Chromium Code Reviews| Index: go/src/infra/tools/cipd/apps/cipd/main.go |
| diff --git a/go/src/infra/tools/cipd/apps/cipd/main.go b/go/src/infra/tools/cipd/apps/cipd/main.go |
| index 132b83d606e49dd2d785ff0e64b551fa8e99672d..6fbca24f8b911198274c55ca4b5a329ab918094e 100644 |
| --- a/go/src/infra/tools/cipd/apps/cipd/main.go |
| +++ b/go/src/infra/tools/cipd/apps/cipd/main.go |
| @@ -314,6 +314,19 @@ func (opts *JSONOutputOptions) writeJSONOutput(result interface{}, err error) er |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| +// ListPackagesOptions mixin. |
| + |
| +// ListPackagesOptions defines --prefix option that matches the prefix of |
| +// packages to list. |
| +type ListPackagesOptions struct { |
| + prefix string |
| +} |
| + |
| +func (opts *ListPackagesOptions) registerFlags(f *flag.FlagSet) { |
| + f.StringVar(&opts.prefix, "prefix", "", "Prefix of packages to list.") |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| // 'create' subcommand. |
| var cmdCreate = &subcommands.Command{ |
| @@ -882,6 +895,58 @@ func inspectInstance(inst local.PackageInstance, listFiles bool) { |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| +// 'pkg-list' subcommand. |
|
Vadim Sh.
2015/06/19 21:12:03
pkg-* prefix is for subcommands that touch package
estaab
2015/06/20 02:25:25
Done, using ls.
|
| + |
| +var cmdListPackages = &subcommands.Command{ |
| + UsageLine: "pkg-list [--prefix=<string>]", |
| + ShortDesc: "List matching packages.", |
| + LongDesc: "List matching packages to which the user has access, with optional filtering.", |
| + CommandRun: func() subcommands.CommandRun { |
| + c := &listPackagesRun{} |
| + c.ListPackagesOptions.registerFlags(&c.Flags) |
| + c.ServiceOptions.registerFlags(&c.Flags) |
| + return c |
| + }, |
| +} |
| + |
| +type listPackagesRun struct { |
| + subcommands.CommandRunBase |
| + ListPackagesOptions |
| + ServiceOptions |
| +} |
| + |
| +func (c *listPackagesRun) Run(a subcommands.Application, args []string) int { |
| + if !checkCommandLine(args, c.GetFlags(), 0) { |
| + return 1 |
| + } |
| + err := listPackages(c.ListPackagesOptions, c.ServiceOptions) |
| + if err != nil { |
| + log.Errorf("Error while listing packages: %s", err) |
| + return 1 |
| + } |
| + return 0 |
| +} |
| + |
| +func listPackages(listOpts ListPackagesOptions, serviceOpts ServiceOptions) error { |
| + client, err := serviceOpts.makeCipdClient("") |
| + if err != nil { |
| + return err |
| + } |
| + packages, err := client.ListPackages(listOpts.prefix) |
| + if err != nil { |
| + return err |
| + } |
| + if len(packages) == 0 { |
| + log.Infof("No matching packages.") |
| + } else { |
| + for _, p := range packages { |
| + log.Infof("%s", p) |
| + } |
| + } |
| + return nil |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| // 'pkg-register' subcommand. |
| var cmdRegister = &subcommands.Command{ |
| @@ -968,6 +1033,7 @@ var application = &subcommands.DefaultApplication{ |
| cmdFetch, |
| cmdInspect, |
| cmdRegister, |
| + cmdListPackages, // REVIEW: Where should this actually go? |
|
Vadim Sh.
2015/06/19 21:12:03
"High level commands" I think.
estaab
2015/06/20 02:25:25
Done.
|
| }, |
| } |