本文整理汇总了Golang中github.com/coreos/rkt/Godeps/_workspace/src/github.com/spf13/cobra.Command类的典型用法代码示例。如果您正苦于以下问题:Golang Command类的具体用法?Golang Command怎么用?Golang Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Command类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: runCatManifest
func runCatManifest(cmd *cobra.Command, args []string) (exit int) {
if len(args) != 1 {
cmd.Usage()
return 1
}
pod, err := getPodFromUUIDString(args[0])
if err != nil {
stderr("cat-manifest: problem retrieving pod: %v", err)
return 1
}
defer pod.Close()
manifest, err := pod.getManifest()
if err != nil {
return 1
}
var b []byte
if flagPMPrettyPrint {
b, err = json.MarshalIndent(manifest, "", "\t")
} else {
b, err = json.Marshal(manifest)
}
if err != nil {
stderr("cat-manifest: cannot read the pod manifest: %v", err)
return 1
}
stdout(string(b))
return 0
}
开发者ID:matomesc,项目名称:rkt,代码行数:32,代码来源:cat_manifest.go
示例2: runStatus
func runStatus(cmd *cobra.Command, args []string) (exit int) {
if len(args) != 1 {
cmd.Usage()
return 1
}
p, err := getPodFromUUIDString(args[0])
if err != nil {
stderr("Problem retrieving pod: %v", err)
return 1
}
defer p.Close()
if flagWait {
if err := p.waitExited(); err != nil {
stderr("Unable to wait for pod: %v", err)
return 1
}
}
if err = printStatus(p); err != nil {
stderr("Unable to print status: %v", err)
return 1
}
return 0
}
开发者ID:matomesc,项目名称:rkt,代码行数:27,代码来源:status.go
示例3: runTrust
func runTrust(cmd *cobra.Command, args []string) (exit int) {
if flagPrefix == "" && !flagRoot {
if len(args) != 0 {
stderr("--root required for non-prefixed (root) keys")
} else {
cmd.Usage()
}
return 1
}
if flagPrefix != "" && flagRoot {
stderr("--root and --prefix usage mutually exclusive")
return 1
}
// if the user included a scheme with the prefix, error on it
u, err := url.Parse(flagPrefix)
if err == nil && u.Scheme != "" {
stderr("--prefix must not contain a URL scheme, omit %s://", u.Scheme)
return 1
}
pkls, err := getPubKeyLocations(flagPrefix, args)
if err != nil {
stderr("Error determining key location: %v", err)
return 1
}
if err := addKeys(pkls, flagPrefix); err != nil {
stderr("Error adding keys: %v", err)
return 1
}
return 0
}
开发者ID:fdserr,项目名称:rkt,代码行数:35,代码来源:trust.go
示例4: runRm
func runRm(cmd *cobra.Command, args []string) (exit int) {
var podUUID *types.UUID
var err error
switch {
case len(args) == 0 && flagUUIDFile != "":
podUUID, err = readUUIDFromFile(flagUUIDFile)
if err != nil {
stderr("Unable to read UUID from file: %v", err)
return 1
}
case len(args) == 1 && flagUUIDFile == "":
podUUID, err = resolveUUID(args[0])
if err != nil {
stderr("Unable to resolve UUID: %v", err)
return 1
}
default:
cmd.Usage()
return 1
}
p, err := getPod(podUUID)
if err != nil {
stderr("Cannot get pod: %v", err)
return 1
}
return removePod(p)
}
开发者ID:krieg,项目名称:rkt,代码行数:31,代码来源:rm.go
示例5: runStatus
func runStatus(cmd *cobra.Command, args []string) (exit int) {
if len(args) != 1 {
cmd.Usage()
return 1
}
podUUID, err := resolveUUID(args[0])
if err != nil {
stderr("Unable to resolve UUID: %v", err)
return 1
}
p, err := getPod(podUUID)
if err != nil {
stderr("Unable to get pod: %v", err)
return 1
}
defer p.Close()
if flagWait {
if err := p.waitExited(); err != nil {
stderr("Unable to wait for pod: %v", err)
return 1
}
}
if err = printStatus(p); err != nil {
stderr("Unable to print status: %v", err)
return 1
}
return 0
}
开发者ID:NeilW,项目名称:rkt,代码行数:33,代码来源:status.go
示例6: runTrust
func runTrust(cmd *cobra.Command, args []string) (exit int) {
if globalFlags.InsecureSkipVerify {
// --insecure-skip-verify disable the keystore but we need it for rkt trust
stderr("--insecure-skip-verify cannot be used with rkt trust")
return 1
}
if flagPrefix == "" && !flagRoot {
if len(args) != 0 {
stderr("--root required for non-prefixed (root) keys")
} else {
cmd.Usage()
}
return 1
}
if flagPrefix != "" && flagRoot {
stderr("--root and --prefix usage mutually exclusive")
return 1
}
ks := getKeystore()
if ks == nil {
stderr("could not get the keystore")
return 1
}
// if the user included a scheme with the prefix, error on it
u, err := url.Parse(flagPrefix)
if err == nil && u.Scheme != "" {
stderr("--prefix must not contain a URL scheme, omit %s://", u.Scheme)
return 1
}
pkls := args
m := &pubkey.Manager{
InsecureAllowHttp: flagAllowHTTP,
TrustKeysFromHttps: globalFlags.TrustKeysFromHttps,
Ks: ks,
Debug: globalFlags.Debug,
}
if len(pkls) == 0 {
pkls, err = m.GetPubKeyLocations(flagPrefix)
if err != nil {
stderr("Error determining key location: %v", err)
return 1
}
}
acceptOpt := pubkey.AcceptAsk
if globalFlags.InsecureSkipVerify {
acceptOpt = pubkey.AcceptForce
}
if err := m.AddKeys(pkls, flagPrefix, acceptOpt, pubkey.OverrideDeny); err != nil {
stderr("Error adding keys: %v", err)
return 1
}
return 0
}
开发者ID:ngorskig,项目名称:rkt,代码行数:60,代码来源:trust.go
示例7: runImageImport
func runImageImport(cmd *cobra.Command, args []string) (exit int) {
if len(args) != 2 {
cmd.Usage()
return 1
}
outFile := args[1]
ext := filepath.Ext(outFile)
if ext != schema.ACIExtension {
stderr("rkt: Extension must be %s (given %s)", schema.ACIExtension, ext)
return 1
}
aciImgPath, err := oci2aciImage(args[0])
if err != nil {
stderr("rkt: oci2aci failed: %s", err)
return 1
}
if err = run(exec.Command("mv", aciImgPath, args[1])); err != nil {
return 1
}
return 0
}
开发者ID:ChengTiesheng,项目名称:rkt-image-import,代码行数:25,代码来源:image_import.go
示例8: runImageImport
func runImageImport(cmd *cobra.Command, args []string) (exit int) {
if len(args) != 1 {
cmd.Usage()
return 1
}
//convert oci bundle to aci image
aciImage, err := oci2aci.Oci2aciImage(args[0])
if err != nil {
fmt.Printf("oci2aci failed: %v", err)
return 1
}
//save aci to rkt store
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
fmt.Printf("cannot open store: %v", err)
return 1
}
aciFile, err := os.Open(aciImage)
if err != nil {
fmt.Printf("opening ACI file %s failed: %v", aciImage, err)
return 1
}
key, err := s.WriteACI(aciFile, true)
if err != nil {
fmt.Printf("write ACI file failed: %v", err)
return 1
}
fmt.Println(key)
return 0
}
开发者ID:liugenping,项目名称:rkt,代码行数:32,代码来源:image_importoci.go
示例9: runFetch
func runFetch(cmd *cobra.Command, args []string) (exit int) {
if err := parseApps(&rktApps, args, cmd.Flags(), false); err != nil {
stderr("fetch: unable to parse arguments: %v", err)
return 1
}
if rktApps.Count() < 1 {
stderr("fetch: must provide at least one image")
return 1
}
if flagStoreOnly && flagNoStore {
stderr("both --store-only and --no-store specified")
return 1
}
s, err := store.NewStore(getDataDir())
if err != nil {
stderr("fetch: cannot open store: %v", err)
return 1
}
ks := getKeystore()
config, err := getConfig()
if err != nil {
stderr("fetch: cannot get configuration: %v", err)
return 1
}
ft := &image.Fetcher{
S: s,
Ks: ks,
Headers: config.AuthPerHost,
DockerAuth: config.DockerCredentialsPerRegistry,
InsecureFlags: globalFlags.InsecureFlags,
Debug: globalFlags.Debug,
TrustKeysFromHTTPS: globalFlags.TrustKeysFromHTTPS,
StoreOnly: flagStoreOnly,
NoStore: flagNoStore,
WithDeps: true,
}
err = rktApps.Walk(func(app *apps.App) error {
hash, err := ft.FetchImage(app.Image, app.Asc, app.ImType)
if err != nil {
return err
}
if !flagFullHash {
hash = types.ShortHash(hash)
}
stdout(hash)
return nil
})
if err != nil {
stderr("%v", err)
return 1
}
return
}
开发者ID:mischief,项目名称:rkt,代码行数:59,代码来源:fetch.go
示例10: getSubCommands
func getSubCommands(cmd *cobra.Command) []*cobra.Command {
subCommands := []*cobra.Command{}
for _, subCmd := range cmd.Commands() {
subCommands = append(subCommands, subCmd)
subCommands = append(subCommands, getSubCommands(subCmd)...)
}
return subCommands
}
开发者ID:NeilW,项目名称:rkt,代码行数:8,代码来源:help.go
示例11: runImageCatManifest
func runImageCatManifest(cmd *cobra.Command, args []string) (exit int) {
if len(args) != 1 {
cmd.Usage()
return 1
}
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
stderr("image cat-manifest: cannot open store: %v", err)
return 1
}
var key string
if _, err := types.NewHash(args[0]); err == nil {
key, err = s.ResolveKey(args[0])
if err != nil {
stderr("image cat-manifest: cannot resolve key: %v", err)
return 1
}
} else {
app, err := discovery.NewAppFromString(args[0])
if err != nil {
stderr("image cat-manifest: cannot parse the image name: %v", err)
return 1
}
labels, err := types.LabelsFromMap(app.Labels)
if err != nil {
stderr("image cat-manifest: invalid labels in the name: %v", err)
return 1
}
key, err = s.GetACI(app.Name, labels)
if err != nil {
stderr("image cat-manifest: cannot find image: %v", err)
return 1
}
}
manifest, err := s.GetImageManifest(key)
if err != nil {
stderr("image cat-manifest: cannot get image manifest: %v", err)
return 1
}
var b []byte
if flagPrettyPrint {
b, err = json.MarshalIndent(manifest, "", "\t")
} else {
b, err = json.Marshal(manifest)
}
if err != nil {
stderr("image cat-manifest: cannot read the image manifest: %v", err)
return 1
}
stdout(string(b))
return 0
}
开发者ID:danieltaborda,项目名称:rkt,代码行数:57,代码来源:image_cat_manifest.go
示例12: runFetch
func runFetch(cmd *cobra.Command, args []string) (exit int) {
if err := parseApps(&rktApps, args, cmd.Flags(), false); err != nil {
stderr("fetch: unable to parse arguments: %v", err)
return 1
}
if rktApps.Count() < 1 {
stderr("fetch: must provide at least one image")
return 1
}
if flagStoreOnly && flagNoStore {
stderr("both --store-only and --no-store specified")
return 1
}
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
stderr("fetch: cannot open store: %v", err)
return 1
}
ks := getKeystore()
config, err := getConfig()
if err != nil {
stderr("fetch: cannot get configuration: %v", err)
return 1
}
ft := &fetcher{
imageActionData: imageActionData{
s: s,
ks: ks,
headers: config.AuthPerHost,
dockerAuth: config.DockerCredentialsPerRegistry,
insecureSkipVerify: globalFlags.InsecureSkipVerify,
debug: globalFlags.Debug,
},
storeOnly: flagStoreOnly,
noStore: flagNoStore,
withDeps: true,
}
err = rktApps.Walk(func(app *apps.App) error {
hash, err := ft.fetchImage(app.Image, app.Asc)
if err != nil {
return err
}
shortHash := types.ShortHash(hash)
stdout(shortHash)
return nil
})
if err != nil {
stderr("%v", err)
return 1
}
return
}
开发者ID:NeilW,项目名称:rkt,代码行数:57,代码来源:fetch.go
示例13: runEnter
func runEnter(cmd *cobra.Command, args []string) (exit int) {
if len(args) < 1 {
cmd.Usage()
return 1
}
p, err := getPodFromUUIDString(args[0])
if err != nil {
stderr("Problem problem retrieving pod: %v", err)
return 1
}
defer p.Close()
if !p.isRunning() {
stderr("Pod %q isn't currently running", p.uuid)
return 1
}
podPID, err := p.getContainerPID1()
if err != nil {
stderr("Unable to determine the pid for pod %q: %v", p.uuid, err)
return 1
}
appName, err := getAppName(p)
if err != nil {
stderr("Unable to determine app name: %v", err)
return 1
}
argv, err := getEnterArgv(p, args)
if err != nil {
stderr("Enter failed: %v", err)
return 1
}
s, err := store.NewStore(getDataDir())
if err != nil {
stderr("Cannot open store: %v", err)
return 1
}
stage1TreeStoreID, err := p.getStage1TreeStoreID()
if err != nil {
stderr("Error getting stage1 treeStoreID: %v", err)
return 1
}
stage1RootFS := s.GetTreeStoreRootFS(stage1TreeStoreID)
if err = stage0.Enter(p.path(), podPID, *appName, stage1RootFS, argv); err != nil {
stderr("Enter failed: %v", err)
return 1
}
// not reached when stage0.Enter execs /enter
return 0
}
开发者ID:matomesc,项目名称:rkt,代码行数:57,代码来源:enter.go
示例14: runImageExport
func runImageExport(cmd *cobra.Command, args []string) (exit int) {
if len(args) != 2 {
cmd.Usage()
return 1
}
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
stderr("image export: cannot open store: %v", err)
return 1
}
key, err := getKeyFromAppOrHash(s, args[0])
if err != nil {
stderr("image export: %v", err)
return 1
}
aci, err := s.ReadStream(key)
if err != nil {
stderr("image export: error reading image: %v", err)
return 1
}
defer aci.Close()
mode := os.O_CREATE | os.O_WRONLY
if flagOverwriteACI {
mode |= os.O_TRUNC
} else {
mode |= os.O_EXCL
}
f, err := os.OpenFile(args[1], mode, 0644)
if err != nil {
if os.IsExist(err) {
stderr("image export: output ACI file exists (try --overwrite)")
} else {
stderr("image export: unable to open output ACI file %s: %v", args[1], err)
}
return 1
}
defer func() {
err := f.Close()
if err != nil {
stderr("image export: error closing output ACI file: %v", err)
exit = 1
}
}()
_, err = io.Copy(f, aci)
if err != nil {
stderr("image export: error writing to output ACI file: %v", err)
return 1
}
return 0
}
开发者ID:jsarenik,项目名称:rkt,代码行数:56,代码来源:image_export.go
示例15: runRm
func runRm(cmd *cobra.Command, args []string) (exit int) {
var podUUID *types.UUID
var podUUIDs []*types.UUID
var err error
switch {
case len(args) == 0 && flagUUIDFile != "":
podUUID, err = readUUIDFromFile(flagUUIDFile)
if err != nil {
stderr("Unable to read UUID from file: %v", err)
return 1
}
podUUIDs = append(podUUIDs, podUUID)
case len(args) > 0 && flagUUIDFile == "":
for _, uuid := range args {
podUUID, err := resolveUUID(uuid)
if err != nil {
stderr("Unable to resolve UUID: %v", err)
} else {
podUUIDs = append(podUUIDs, podUUID)
}
}
default:
cmd.Usage()
return 1
}
ret := 0
for _, podUUID = range podUUIDs {
p, err := getPod(podUUID)
if err != nil {
ret = 1
stderr("Cannot get pod: %v", err)
}
if removePod(p) {
stdout("%q", p.uuid)
} else {
ret = 1
}
}
if ret == 1 {
stderr("Failed to remove one or more pods")
}
return ret
}
开发者ID:matomesc,项目名称:rkt,代码行数:50,代码来源:rm.go
示例16: runTrust
func runTrust(cmd *cobra.Command, args []string) (exit int) {
if globalFlags.InsecureSkipVerify {
// --insecure-skip-verify disable the keystore but we need it for rkt trust
stderr("--insecure-skip-verify cannot be used with rkt trust")
return 1
}
if flagPrefix == "" && !flagRoot {
if len(args) != 0 {
stderr("--root required for non-prefixed (root) keys")
} else {
cmd.Usage()
}
return 1
}
if flagPrefix != "" && flagRoot {
stderr("--root and --prefix usage mutually exclusive")
return 1
}
// if the user included a scheme with the prefix, error on it
u, err := url.Parse(flagPrefix)
if err == nil && u.Scheme != "" {
stderr("--prefix must not contain a URL scheme, omit %s://", u.Scheme)
return 1
}
pkls := args
if len(pkls) == 0 {
pkls, err = getPubKeyLocations(flagPrefix, flagAllowHTTP, globalFlags.Debug)
if err != nil {
stderr("Error determining key location: %v", err)
return 1
}
}
// allow override
if err := addKeys(pkls, flagPrefix, flagAllowHTTP, globalFlags.InsecureSkipVerify, true); err != nil {
stderr("Error adding keys: %v", err)
return 1
}
return 0
}
开发者ID:NeilW,项目名称:rkt,代码行数:45,代码来源:trust.go
示例17: usageFunc
func usageFunc(cmd *cobra.Command) error {
subCommands := getSubCommands(cmd)
commandUsageTemplate.Execute(tabOut, struct {
Executable string
Cmd *cobra.Command
CmdFlags *pflag.FlagSet
SubCommands []*cobra.Command
Version string
}{
cliName,
cmd,
cmd.Flags(),
subCommands,
version.Version,
})
tabOut.Flush()
return nil
}
开发者ID:danieltaborda,项目名称:rkt,代码行数:18,代码来源:help.go
示例18: usageFunc
func usageFunc(cmd *cobra.Command) error {
subCommands := getSubCommands(cmd)
tabOut := getTabOutWithWriter(os.Stdout)
commandUsageTemplate.Execute(tabOut, struct {
Cmd *cobra.Command
LocalFlags string
GlobalFlags string
SubCommands []*cobra.Command
Version string
}{
cmd,
rktFlagUsages(cmd.LocalFlags()),
rktFlagUsages(cmd.InheritedFlags()),
subCommands,
version.Version,
})
tabOut.Flush()
return nil
}
开发者ID:matomesc,项目名称:rkt,代码行数:19,代码来源:help.go
示例19: getStage1Hash
// getStage1Hash will try to fetch stage1 from store if it is a
// default one. If that fails it will try to get via usual fetching
// from disk or network.
//
// As a special case, if stage1 image path is a default and not
// overriden by --stage1-image flag and it is has no scheme, it will
// try to fetch it from two places on disk - from the path directly if
// it is absolute and then from the same directory where rkt binary
// resides.
//
// The passed command must have "stage1-image" string flag registered.
func getStage1Hash(s *store.Store, cmd *cobra.Command) (*types.Hash, error) {
fn := &finder{
imageActionData: imageActionData{
s: s,
},
storeOnly: false,
noStore: false,
withDeps: false,
}
imageFlag := cmd.Flags().Lookup(stage1ImageFlagName)
if imageFlag == nil {
panic(fmt.Sprintf("Expected flag --%s to be registered in command %s", stage1ImageFlagName, cmd.Name()))
}
path := imageFlag.Value.String()
if path == defaultStage1Image {
return getDefaultStage1Hash(fn, imageFlag.Changed)
}
return getCustomStage1Hash(fn, path)
}
开发者ID:ngorskig,项目名称:rkt,代码行数:31,代码来源:stage1hash.go
示例20: getStage1Hash
// getStage1Hash will try to fetch stage1 from store if it is a
// default one. If that fails it will try to get via usual fetching
// from disk or network.
//
// As a special case, if stage1 image path is a default and not
// overriden by --stage1-image flag and it is has no scheme, it will
// try to fetch it from two places on disk - from the path directly if
// it is absolute and then from the same directory where rkt binary
// resides.
//
// The passed command must have "stage1-image" string flag registered.
func getStage1Hash(s *store.Store, cmd *cobra.Command) (*types.Hash, error) {
fn := &image.Finder{
S: s,
InsecureFlags: globalFlags.InsecureFlags,
TrustKeysFromHttps: globalFlags.TrustKeysFromHttps,
StoreOnly: false,
NoStore: false,
WithDeps: false,
}
imageFlag := cmd.Flags().Lookup(stage1ImageFlagName)
if imageFlag == nil {
panic(fmt.Sprintf("Expected flag --%s to be registered in command %s", stage1ImageFlagName, cmd.Name()))
}
path := imageFlag.Value.String()
if path == defaultStage1Image {
return getDefaultStage1Hash(fn, imageFlag.Changed)
}
return getCustomStage1Hash(fn, path)
}
开发者ID:matomesc,项目名称:rkt,代码行数:32,代码来源:stage1hash.go
注:本文中的github.com/coreos/rkt/Godeps/_workspace/src/github.com/spf13/cobra.Command类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论