Chromium Code Reviews| Index: logdog/client/cli/main.go |
| diff --git a/logdog/client/cmd/logdog/main.go b/logdog/client/cli/main.go |
| similarity index 87% |
| copy from logdog/client/cmd/logdog/main.go |
| copy to logdog/client/cli/main.go |
| index 4ab743d21e14561cf168a6fcd3b1ab31a79f6302..d1d2d6083bd2c702db29818bbb36a84d77727b91 100644 |
| --- a/logdog/client/cmd/logdog/main.go |
| +++ b/logdog/client/cli/main.go |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed under the Apache License, Version 2.0 |
| // that can be found in the LICENSE file. |
| -package main |
| +package cli |
| import ( |
| "flag" |
| @@ -31,25 +31,37 @@ func init() { |
| prpc.DefaultUserAgent = "logdog CLI" |
| } |
| +// Parameters is the set of application parametesr that can be supplied. |
| +type Parameters struct { |
| + // Args is the command-line arguments. This should not include the command name, |
| + // args[0]. |
| + Args []string |
| + |
| + // Host is the default host name. |
| + Host string |
| +} |
| + |
| type application struct { |
| cli.Application |
| context.Context |
| + // host is the host name of the Coordinator service to interface with. |
|
Vadim Sh.
2016/09/27 17:58:35
this comment is stale
dnj
2016/09/27 18:13:42
Done.
|
| + p Parameters |
| + |
| // project is the project name. This may either be a valid project name or |
| // empty. Subcommands that support "unified" project-in-path paths should use |
| // splitPath to get the project form the path. Those that don't should assert |
| // that this is non-empty. |
| - project config.ProjectName |
| - authFlags authcli.Flags |
| - coordinator string |
| - insecure bool |
| - timeout clockflag.Duration |
| + project config.ProjectName |
| + authFlags authcli.Flags |
| + insecure bool |
| + timeout clockflag.Duration |
| coord *coordinator.Client |
| } |
| func (a *application) addToFlagSet(ctx context.Context, fs *flag.FlagSet) { |
| - fs.StringVar(&a.coordinator, "host", "", |
| + fs.StringVar(&a.p.Host, "host", a.p.Host, |
| "The LogDog Coordinator [host][:port].") |
| fs.BoolVar(&a.insecure, "insecure", false, |
| "Use insecure transport for RPC.") |
| @@ -94,8 +106,8 @@ func (a *application) timeoutCtx(c context.Context) (context.Context, context.Ca |
| return context.WithTimeout(c, time.Duration(a.timeout)) |
| } |
| -func mainImpl() int { |
| - ctx := context.Background() |
| +// Main is the entry point for the CLI application. |
| +func Main(ctx context.Context, params Parameters) int { |
| ctx = gologger.StdConfig.Use(ctx) |
| authOptions := auth.Options{ |
| @@ -119,6 +131,7 @@ func mainImpl() int { |
| authcli.SubcommandInfo(authOptions, "auth-info"), |
| }, |
| }, |
| + p: params, |
| } |
| loggingConfig := log.Config{ |
| Level: log.Level(log.Info), |
| @@ -130,7 +143,7 @@ func mainImpl() int { |
| a.authFlags.Register(flags, authOptions) |
| // Parse flags. |
| - if err := flags.Parse(os.Args[1:]); err != nil { |
| + if err := flags.Parse(params.Args); err != nil { |
| log.Errorf(log.SetError(ctx, err), "Failed to parse command-line.") |
| return 1 |
| } |
| @@ -138,7 +151,7 @@ func mainImpl() int { |
| // Install our log formatter. |
| ctx = loggingConfig.Set(ctx) |
| - if a.coordinator == "" { |
| + if a.p.Host == "" { |
| log.Errorf(ctx, "Missing coordinator host (-host).") |
| return 1 |
| } |
| @@ -181,7 +194,7 @@ func mainImpl() int { |
| // Get our Coordinator client instance. |
| prpcClient := &prpc.Client{ |
| C: httpClient, |
| - Host: a.coordinator, |
| + Host: a.p.Host, |
| Options: prpc.DefaultOptions(), |
| } |
| prpcClient.Options.Insecure = a.insecure |
| @@ -190,7 +203,3 @@ func mainImpl() int { |
| a.Context = ctx |
| return subcommands.Run(&a, flags.Args()) |
| } |
| - |
| -func main() { |
| - os.Exit(mainImpl()) |
| -} |