-
Notifications
You must be signed in to change notification settings - Fork 28
Some refactoring on leo subcommands #664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved all subcommands into a single package
Why? 🤔
Is there any reason to keep identical single file packages? |
It probably boils down to a matter of taste1 but, to my mind, it looks cleaner once we introduce subcommands or more complex commands (e.g. #291 or #531) which may be split over several files. See also docker/cli, kubernetes/kubectl or cli/cli for inspiration. Footnotes
|
delete -> destroy read -> status
It looks like there's a bug in cobra where a required persistent flag is enforced even for the help command.
2b012e9
to
35e27b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package cmd | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
|
||
"terraform-provider-iterative/task/common" | ||
) | ||
|
||
// BaseOptions specify base flags for commands that interact with | ||
// cloud deployments. | ||
type BaseOptions struct { | ||
Region string | ||
Provider string | ||
Verbose bool | ||
} | ||
|
||
// defaultCloud specifies default timeouts. | ||
var defaultCloud = common.Cloud{ | ||
Timeouts: common.Timeouts{ | ||
Create: 15 * time.Minute, | ||
Read: 3 * time.Minute, | ||
Update: 3 * time.Minute, | ||
Delete: 15 * time.Minute, | ||
}, | ||
} | ||
|
||
// SetFlags sets base option flags on the provided flagset. | ||
func (o *BaseOptions) SetFlags(f *pflag.FlagSet) { | ||
f.StringVar(&o.Provider, "cloud", "", "cloud provider") | ||
f.StringVar(&o.Region, "region", "us-east", "cloud region") | ||
f.BoolVar(&o.Verbose, "verbose", false, "verbose output") | ||
cobra.CheckErr(cobra.MarkFlagRequired(f, "cloud")) | ||
} | ||
|
||
// GetCloud parses cloud-specific options and returns a cloud structure. | ||
func (o *BaseOptions) GetCloud() *common.Cloud { | ||
cloud := defaultCloud | ||
cloud.Provider = common.Provider(o.Provider) | ||
cloud.Region = common.Region(o.Region) | ||
return &cloud | ||
} | ||
|
||
// ConfigureLogging configures logging and sets the log level. | ||
func (o *BaseOptions) ConfigureLogging() { | ||
logrus.SetLevel(logrus.InfoLevel) | ||
if o.Verbose { | ||
logrus.SetLevel(logrus.DebugLevel) | ||
} | ||
|
||
logrus.SetFormatter(&logrus.TextFormatter{ | ||
ForceColors: true, | ||
DisableTimestamp: true, | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Message in a botte for myself: lots of good stuff here, don't let them disappear forever
Renamed delete to destroy.
Renamed read to status.
Restructured base options and moved all subcommands into a single package.