Skip to content

Commit 5ae509e

Browse files
authored
Merge pull request #38 from justaugustus/cleanup
commands: Default to remote checks and introduce `--local-only` flag
2 parents bc550ba + db0fa72 commit 5ae509e

File tree

3 files changed

+54
-19
lines changed

3 files changed

+54
-19
lines changed

commands/commands.go

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,16 @@ func New() *cobra.Command {
4545
}
4646

4747
// Submit types
48-
cmd.PersistentFlags().BoolVar(
49-
&rootOpts.local,
50-
"local",
51-
false,
52-
"if specified, subcommands will only perform local checks",
53-
)
5448

5549
cmd.PersistentFlags().BoolVar(
56-
&rootOpts.remote,
57-
"remote",
50+
&rootOpts.localOnly,
51+
"local-only",
5852
false,
59-
"if specified, subcommands will query against remotes defined in the config",
53+
"if specified, subcommands will only perform local checks",
6054
)
6155

6256
cmd.PersistentFlags().StringVar(
63-
&rootOpts.config,
57+
&rootOpts.configFile,
6458
"config",
6559
defaultConfigFile,
6660
"configuration file location",
@@ -80,6 +74,38 @@ func New() *cobra.Command {
8074
fmt.Sprintf("the logging verbosity, either %s", log.LevelNames()),
8175
)
8276

77+
// START - Deprecated flags
78+
79+
// TODO: Remove in the next (post-v0.3.0) minor release
80+
cmd.PersistentFlags().BoolVar(
81+
&rootOpts.localOnly,
82+
"local",
83+
false,
84+
"if specified, subcommands will only perform local checks",
85+
)
86+
87+
// TODO: Remove in the next (post-v0.3.0) minor release
88+
cmd.PersistentFlags().BoolVar(
89+
&rootOpts.remote,
90+
"remote",
91+
false,
92+
"if specified, subcommands will query against remotes defined in the config",
93+
)
94+
95+
// nolint: errcheck
96+
cmd.PersistentFlags().MarkDeprecated(
97+
"local",
98+
"and will be removed in a future release. Use --local-only instead.",
99+
)
100+
101+
// nolint: errcheck
102+
cmd.PersistentFlags().MarkDeprecated(
103+
"remote",
104+
"as remote checks now happen by default.",
105+
)
106+
107+
// END - Deprecated flags
108+
83109
AddCommands(cmd)
84110
return cmd
85111
}

commands/options.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,21 @@ import (
2424
)
2525

2626
type options struct {
27+
// configuration options
28+
localOnly bool
29+
remote bool
30+
31+
// path options
32+
basePath string
33+
configFile string
34+
35+
// command options
2736
logLevel string
28-
local bool
29-
remote bool
30-
config string
31-
basePath string
3237
}
3338

3439
// setAndValidate sets some default options and verifies if options are valid
3540
func (o *options) setAndValidate() error {
36-
logrus.Info("Validating zeitgeist options...")
41+
logrus.Debug("Validating zeitgeist options...")
3742

3843
if o.basePath != "" {
3944
if _, err := os.Stat(o.basePath); os.IsNotExist(err) {

commands/validate.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,20 @@ func addValidate(topLevel *cobra.Command) {
4949
func runValidate(opts *options) error {
5050
client := dependencies.NewClient()
5151

52-
if opts.remote {
53-
updates, err := client.RemoteCheck(opts.config)
52+
if opts.localOnly {
53+
if err := client.LocalCheck(opts.configFile, opts.basePath); err != nil {
54+
return errors.Wrap(err, "checking local dependencies")
55+
}
56+
} else {
57+
updates, err := client.RemoteCheck(opts.configFile)
5458
if err != nil {
55-
return errors.Wrap(err, "check remote dependencies")
59+
return errors.Wrap(err, "checking remote dependencies")
5660
}
5761

5862
for _, update := range updates {
5963
fmt.Println(update)
6064
}
6165
}
6266

63-
return client.LocalCheck(opts.config, opts.basePath)
67+
return nil
6468
}

0 commit comments

Comments
 (0)