Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: logdog/client/cli/main.go

Issue 2626433004: Move "common/config" common types into cfgtypes. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « logdog/client/butlerlib/bootstrap/bootstrap.go ('k') | logdog/client/cli/path.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package cli 5 package cli
6 6
7 import ( 7 import (
8 "flag" 8 "flag"
9 "fmt" 9 "fmt"
10 "os" 10 "os"
11 "os/signal" 11 "os/signal"
12 "strings" 12 "strings"
13 "time" 13 "time"
14 14
15 "github.com/maruel/subcommands" 15 "github.com/maruel/subcommands"
16 "golang.org/x/net/context" 16 "golang.org/x/net/context"
17 17
18 "github.com/luci/luci-go/client/authcli" 18 "github.com/luci/luci-go/client/authcli"
19 "github.com/luci/luci-go/common/auth" 19 "github.com/luci/luci-go/common/auth"
20 "github.com/luci/luci-go/common/cli" 20 "github.com/luci/luci-go/common/cli"
21 "github.com/luci/luci-go/common/clock/clockflag" 21 "github.com/luci/luci-go/common/clock/clockflag"
22 "github.com/luci/luci-go/common/config"
23 log "github.com/luci/luci-go/common/logging" 22 log "github.com/luci/luci-go/common/logging"
24 "github.com/luci/luci-go/common/logging/gologger" 23 "github.com/luci/luci-go/common/logging/gologger"
25 "github.com/luci/luci-go/grpc/prpc" 24 "github.com/luci/luci-go/grpc/prpc"
26 "github.com/luci/luci-go/logdog/client/coordinator" 25 "github.com/luci/luci-go/logdog/client/coordinator"
27 "github.com/luci/luci-go/logdog/common/types" 26 "github.com/luci/luci-go/logdog/common/types"
27 "github.com/luci/luci-go/luci_config/common/cfgtypes"
28 ) 28 )
29 29
30 func init() { 30 func init() {
31 prpc.DefaultUserAgent = "logdog CLI" 31 prpc.DefaultUserAgent = "logdog CLI"
32 } 32 }
33 33
34 // Parameters is the set of application parametesr that can be supplied. 34 // Parameters is the set of application parametesr that can be supplied.
35 type Parameters struct { 35 type Parameters struct {
36 // Args is the command-line arguments. This should not include the comma nd name, 36 // Args is the command-line arguments. This should not include the comma nd name,
37 // args[0]. 37 // args[0].
38 Args []string 38 Args []string
39 39
40 // Host is the default host name. 40 // Host is the default host name.
41 Host string 41 Host string
42 } 42 }
43 43
44 type application struct { 44 type application struct {
45 cli.Application 45 cli.Application
46 context.Context 46 context.Context
47 47
48 // p is the set of runtime parameters to use. 48 // p is the set of runtime parameters to use.
49 p Parameters 49 p Parameters
50 50
51 // project is the project name. This may either be a valid project name or 51 // project is the project name. This may either be a valid project name or
52 // empty. Subcommands that support "unified" project-in-path paths shoul d use 52 // empty. Subcommands that support "unified" project-in-path paths shoul d use
53 // splitPath to get the project form the path. Those that don't should a ssert 53 // splitPath to get the project form the path. Those that don't should a ssert
54 // that this is non-empty. 54 // that this is non-empty.
55 » project config.ProjectName 55 » project cfgtypes.ProjectName
56 authFlags authcli.Flags 56 authFlags authcli.Flags
57 insecure bool 57 insecure bool
58 timeout clockflag.Duration 58 timeout clockflag.Duration
59 59
60 coord *coordinator.Client 60 coord *coordinator.Client
61 } 61 }
62 62
63 func (a *application) addToFlagSet(ctx context.Context, fs *flag.FlagSet) { 63 func (a *application) addToFlagSet(ctx context.Context, fs *flag.FlagSet) {
64 fs.StringVar(&a.p.Host, "host", a.p.Host, 64 fs.StringVar(&a.p.Host, "host", a.p.Host,
65 "The LogDog Coordinator [host][:port].") 65 "The LogDog Coordinator [host][:port].")
66 fs.BoolVar(&a.insecure, "insecure", false, 66 fs.BoolVar(&a.insecure, "insecure", false,
67 "Use insecure transport for RPC.") 67 "Use insecure transport for RPC.")
68 fs.Var(&a.project, "project", 68 fs.Var(&a.project, "project",
69 "The log stream's project.") 69 "The log stream's project.")
70 70
71 fs.Var(&a.timeout, "timeout", 71 fs.Var(&a.timeout, "timeout",
72 "If >0, a duration string for the maximum amount of time to wait for a log entry "+ 72 "If >0, a duration string for the maximum amount of time to wait for a log entry "+
73 "before exiting with a 2. "+clockflag.DurationHelp) 73 "before exiting with a 2. "+clockflag.DurationHelp)
74 } 74 }
75 75
76 // splitPath converts between a possible user-facing "unified" stream path 76 // splitPath converts between a possible user-facing "unified" stream path
77 // (e.g., "project/path...") to separate project/path values. 77 // (e.g., "project/path...") to separate project/path values.
78 // 78 //
79 // If a project is supplied via command-line, the path is returned directly 79 // If a project is supplied via command-line, the path is returned directly
80 // along with the project. If no project is supplied, the first slash-delimited 80 // along with the project. If no project is supplied, the first slash-delimited
81 // component of "p" is used as the project name. 81 // component of "p" is used as the project name.
82 func (a *application) splitPath(p string) (config.ProjectName, string, bool, err or) { 82 func (a *application) splitPath(p string) (cfgtypes.ProjectName, string, bool, e rror) {
83 if a.project != "" { 83 if a.project != "" {
84 return a.project, p, false, nil 84 return a.project, p, false, nil
85 } 85 }
86 86
87 parts := strings.SplitN(p, types.StreamNameSepStr, 2) 87 parts := strings.SplitN(p, types.StreamNameSepStr, 2)
88 88
89 » project := config.ProjectName(parts[0]) 89 » project := cfgtypes.ProjectName(parts[0])
90 if err := project.Validate(); err != nil { 90 if err := project.Validate(); err != nil {
91 return "", "", false, fmt.Errorf("invalid project name %q: %v", project, err) 91 return "", "", false, fmt.Errorf("invalid project name %q: %v", project, err)
92 } 92 }
93 93
94 if len(parts) == 2 { 94 if len(parts) == 2 {
95 p = parts[1] 95 p = parts[1]
96 } else { 96 } else {
97 p = "" 97 p = ""
98 } 98 }
99 return project, p, true, nil 99 return project, p, true, nil
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 C: httpClient, 196 C: httpClient,
197 Host: a.p.Host, 197 Host: a.p.Host,
198 Options: prpc.DefaultOptions(), 198 Options: prpc.DefaultOptions(),
199 } 199 }
200 prpcClient.Options.Insecure = a.insecure 200 prpcClient.Options.Insecure = a.insecure
201 201
202 a.coord = coordinator.NewClient(prpcClient) 202 a.coord = coordinator.NewClient(prpcClient)
203 a.Context = ctx 203 a.Context = ctx
204 return subcommands.Run(&a, flags.Args()) 204 return subcommands.Run(&a, flags.Args())
205 } 205 }
OLDNEW
« no previous file with comments | « logdog/client/butlerlib/bootstrap/bootstrap.go ('k') | logdog/client/cli/path.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698