Skip to content

Commit

Permalink
refactor(cli): Suffix all command options with Options (#923)
Browse files Browse the repository at this point in the history
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
Approved-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
  • Loading branch information
craciunoiuc committed Oct 24, 2023
2 parents 9c09902 + 5fdcfb6 commit e462f98
Show file tree
Hide file tree
Showing 62 changed files with 225 additions and 225 deletions.
8 changes: 4 additions & 4 deletions internal/cli/kraft/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"kraftkit.sh/unikraft/target"
)

type Build struct {
type BuildOptions struct {
All bool `long:"all" usage:"Build all targets"`
Architecture string `long:"arch" short:"m" usage:"Filter the creation of the build by architecture of known targets"`
DotConfig string `long:"config" short:"c" usage:"Override the path to the KConfig .config file"`
Expand All @@ -45,7 +45,7 @@ type Build struct {
}

func New() *cobra.Command {
cmd, err := cmdfactory.New(&Build{}, cobra.Command{
cmd, err := cmdfactory.New(&BuildOptions{}, cobra.Command{
Short: "Configure and build Unikraft unikernels",
Use: "build [FLAGS] [SUBCOMMAND|DIR]",
Args: cmdfactory.MaxDirArgs(1),
Expand All @@ -72,7 +72,7 @@ func New() *cobra.Command {
return cmd
}

func (opts *Build) Pre(cmd *cobra.Command, args []string) error {
func (opts *BuildOptions) Pre(cmd *cobra.Command, args []string) error {
ctx, err := packmanager.WithDefaultUmbrellaManagerInContext(cmd.Context())
if err != nil {
return err
Expand Down Expand Up @@ -112,7 +112,7 @@ func (opts *Build) Pre(cmd *cobra.Command, args []string) error {
return nil
}

func (opts *Build) Run(cmd *cobra.Command, args []string) error {
func (opts *BuildOptions) Run(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

// Filter project targets by any provided CLI options
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/kraft/build/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ type builder interface {

// Buildable determines whether the provided input can be constructed for the
// given implementation.
Buildable(context.Context, *Build, ...string) (bool, error)
Buildable(context.Context, *BuildOptions, ...string) (bool, error)

// Build performs the actual construction of the unikernel given the provided
// inputs for the given implementation.
Build(context.Context, *Build, []target.Target, ...string) error
Build(context.Context, *BuildOptions, []target.Target, ...string) error
}

// builders is the list of built-in builders which are checked sequentially for
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/kraft/build/builder_kraftfile_unikraft.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (build *builderKraftfileUnikraft) String() string {
}

// Buildable implements builder.
func (build *builderKraftfileUnikraft) Buildable(ctx context.Context, opts *Build, args ...string) (bool, error) {
func (build *builderKraftfileUnikraft) Buildable(ctx context.Context, opts *BuildOptions, args ...string) (bool, error) {
if opts.project.Unikraft(ctx) == nil && opts.project.Template() == nil {
return false, fmt.Errorf("cannot build without unikraft core specification")
}
Expand All @@ -45,7 +45,7 @@ func (build *builderKraftfileUnikraft) Buildable(ctx context.Context, opts *Buil
return true, nil
}

func (build *builderKraftfileUnikraft) pull(ctx context.Context, opts *Build, norender bool, nameWidth int) error {
func (build *builderKraftfileUnikraft) pull(ctx context.Context, opts *BuildOptions, norender bool, nameWidth int) error {
var missingPacks []pack.Package
var processes []*paraprogress.Process
var searches []*processtree.ProcessTreeItem
Expand Down Expand Up @@ -283,7 +283,7 @@ func (build *builderKraftfileUnikraft) pull(ctx context.Context, opts *Build, no
return nil
}

func (build *builderKraftfileUnikraft) Build(ctx context.Context, opts *Build, targets []target.Target, args ...string) error {
func (build *builderKraftfileUnikraft) Build(ctx context.Context, opts *BuildOptions, targets []target.Target, args ...string) error {
var processes []*paraprogress.Process

nameWidth := -1
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/kraft/build/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// buildRootfs generates a rootfs based on the provided
func (opts *Build) buildRootfs(ctx context.Context) error {
func (opts *BuildOptions) buildRootfs(ctx context.Context) error {
if opts.Rootfs == "" {
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/cli/kraft/clean/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ import (
"kraftkit.sh/unikraft/target"
)

type Clean struct {
type CleanOptions struct {
Architecture string `long:"arch" short:"m" usage:"Filter prepare based on a target's architecture"`
Kraftfile string `long:"kraftfile" short:"K" usage:"Set an alternative path of the Kraftfile"`
Platform string `long:"plat" short:"p" usage:"Filter prepare based on a target's platform"`
Target string `long:"target" short:"t" usage:"Filter prepare based on a specific target"`
}

func New() *cobra.Command {
cmd, err := cmdfactory.New(&Clean{}, cobra.Command{
cmd, err := cmdfactory.New(&CleanOptions{}, cobra.Command{
Short: "Remove the build object files of a Unikraft project",
Use: "clean [DIR]",
Args: cmdfactory.MaxDirArgs(1),
Expand All @@ -75,7 +75,7 @@ func New() *cobra.Command {
return cmd
}

func (opts *Clean) Pre(cmd *cobra.Command, _ []string) error {
func (opts *CleanOptions) Pre(cmd *cobra.Command, _ []string) error {
ctx, err := packmanager.WithDefaultUmbrellaManagerInContext(cmd.Context())
if err != nil {
return err
Expand All @@ -88,7 +88,7 @@ func (opts *Clean) Pre(cmd *cobra.Command, _ []string) error {
return nil
}

func (opts *Clean) Run(cmd *cobra.Command, args []string) error {
func (opts *CleanOptions) Run(cmd *cobra.Command, args []string) error {
var err error

ctx := cmd.Context()
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/kraft/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
"kraftkit.sh/cmdfactory"
)

type Cloud struct {
type CloudOptions struct {
Metro string `long:"metro" env:"KRAFTCLOUD_METRO" usage:"Set the KraftCloud metro."`
}

func New() *cobra.Command {
cmd, err := cmdfactory.New(&Cloud{}, cobra.Command{
cmd, err := cmdfactory.New(&CloudOptions{}, cobra.Command{
Short: "KraftCloud",
Use: "cloud [FLAGS] [SUBCOMMAND|DIR]",
Hidden: true,
Expand Down Expand Up @@ -78,6 +78,6 @@ func New() *cobra.Command {
return cmd
}

func (opts *Cloud) Run(cmd *cobra.Command, args []string) error {
func (opts *CloudOptions) Run(cmd *cobra.Command, args []string) error {
return nil
}
6 changes: 3 additions & 3 deletions internal/cli/kraft/cloud/img/img.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
"kraftkit.sh/cmdfactory"
)

type Img struct{}
type ImgOptions struct{}

func New() *cobra.Command {
cmd, err := cmdfactory.New(&Img{}, cobra.Command{
cmd, err := cmdfactory.New(&ImgOptions{}, cobra.Command{
Short: "Manage images on KraftCloud",
Use: "img",
Aliases: []string{"images", "image"},
Expand All @@ -34,6 +34,6 @@ func New() *cobra.Command {
return cmd
}

func (opts *Img) Run(cmd *cobra.Command, args []string) error {
func (opts *ImgOptions) Run(cmd *cobra.Command, args []string) error {
return cmd.Help()
}
8 changes: 4 additions & 4 deletions internal/cli/kraft/cloud/img/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import (
"kraftkit.sh/log"
)

type List struct {
type ListOptions struct {
Output string `long:"output" short:"o" usage:"Set output format" default:"table"`

metro string
}

func New() *cobra.Command {
cmd, err := cmdfactory.New(&List{}, cobra.Command{
cmd, err := cmdfactory.New(&ListOptions{}, cobra.Command{
Short: "List all images at a metro for your account",
Use: "ls",
Aliases: []string{"list"},
Expand All @@ -53,7 +53,7 @@ func New() *cobra.Command {
return cmd
}

func (opts *List) Pre(cmd *cobra.Command, _ []string) error {
func (opts *ListOptions) Pre(cmd *cobra.Command, _ []string) error {
opts.metro = cmd.Flag("metro").Value.String()
if opts.metro == "" {
opts.metro = os.Getenv("KRAFTCLOUD_METRO")
Expand All @@ -65,7 +65,7 @@ func (opts *List) Pre(cmd *cobra.Command, _ []string) error {
return nil
}

func (opts *List) Run(cmd *cobra.Command, args []string) error {
func (opts *ListOptions) Run(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
auth, err := config.GetKraftCloudLoginFromContext(ctx)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/cli/kraft/cloud/instance/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"kraftkit.sh/log"
)

type Create struct {
type CreateOptions struct {
Env []string `local:"true" long:"env" short:"e" usage:"Environmental variables"`
Memory int64 `local:"true" long:"memory" short:"M" usage:"Specify the amount of memory to allocate"`
Name string `local:"true" long:"name" short:"n" usage:"Specify the name of the package"`
Expand All @@ -36,7 +36,7 @@ type Create struct {
}

func New() *cobra.Command {
cmd, err := cmdfactory.New(&Create{}, cobra.Command{
cmd, err := cmdfactory.New(&CreateOptions{}, cobra.Command{
Short: "Create an instance",
Use: "create [FLAGS] IMAGE [-- ARGS]",
Args: cobra.MinimumNArgs(1),
Expand All @@ -62,7 +62,7 @@ func New() *cobra.Command {
return cmd
}

func (opts *Create) Pre(cmd *cobra.Command, _ []string) error {
func (opts *CreateOptions) Pre(cmd *cobra.Command, _ []string) error {
opts.metro = cmd.Flag("metro").Value.String()
if opts.metro == "" {
opts.metro = os.Getenv("KRAFTCLOUD_METRO")
Expand All @@ -74,7 +74,7 @@ func (opts *Create) Pre(cmd *cobra.Command, _ []string) error {
return nil
}

func (opts *Create) Run(cmd *cobra.Command, args []string) error {
func (opts *CreateOptions) Run(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
image := args[0]
auth, err := config.GetKraftCloudLoginFromContext(ctx)
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/kraft/cloud/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"kraftkit.sh/internal/cli/kraft/cloud/instance/stop"
)

type Instance struct{}
type InstanceOptions struct{}

func New() *cobra.Command {
cmd, err := cmdfactory.New(&Instance{}, cobra.Command{
cmd, err := cmdfactory.New(&InstanceOptions{}, cobra.Command{
Short: "Manage KraftCloud instances",
Use: "instance SUBCOMMAND",
Aliases: []string{"inst", "instances"},
Expand All @@ -46,6 +46,6 @@ func New() *cobra.Command {
return cmd
}

func (opts *Instance) Run(cmd *cobra.Command, _ []string) error {
func (opts *InstanceOptions) Run(cmd *cobra.Command, _ []string) error {
return cmd.Help()
}
8 changes: 4 additions & 4 deletions internal/cli/kraft/cloud/instance/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"kraftkit.sh/log"
)

type List struct {
type ListOptions struct {
Output string `long:"output" short:"o" usage:"Set output format" default:"table"`

metro string
}

func New() *cobra.Command {
cmd, err := cmdfactory.New(&List{}, cobra.Command{
cmd, err := cmdfactory.New(&ListOptions{}, cobra.Command{
Short: "List instances",
Use: "ls [FLAGS]",
Aliases: []string{"list"},
Expand All @@ -46,7 +46,7 @@ func New() *cobra.Command {
return cmd
}

func (opts *List) Pre(cmd *cobra.Command, _ []string) error {
func (opts *ListOptions) Pre(cmd *cobra.Command, _ []string) error {
opts.metro = cmd.Flag("metro").Value.String()
if opts.metro == "" {
opts.metro = os.Getenv("KRAFTCLOUD_METRO")
Expand All @@ -58,7 +58,7 @@ func (opts *List) Pre(cmd *cobra.Command, _ []string) error {
return nil
}

func (opts *List) Run(cmd *cobra.Command, args []string) error {
func (opts *ListOptions) Run(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
auth, err := config.GetKraftCloudLoginFromContext(ctx)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/cli/kraft/cloud/instance/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"kraftkit.sh/log"
)

type Logs struct {
type LogOptions struct {
Tail int `local:"true" long:"tail" short:"n" usage:"Lines of recent logs to display" default:"-1"`

metro string
}

func New() *cobra.Command {
cmd, err := cmdfactory.New(&Logs{}, cobra.Command{
cmd, err := cmdfactory.New(&LogOptions{}, cobra.Command{
Short: "Get console output of an instance",
Use: "logs [UUID]",
Args: cobra.ExactArgs(1),
Expand All @@ -46,7 +46,7 @@ func New() *cobra.Command {
return cmd
}

func (opts *Logs) Pre(cmd *cobra.Command, _ []string) error {
func (opts *LogOptions) Pre(cmd *cobra.Command, _ []string) error {
opts.metro = cmd.Flag("metro").Value.String()
if opts.metro == "" {
opts.metro = os.Getenv("KRAFTCLOUD_METRO")
Expand All @@ -58,7 +58,7 @@ func (opts *Logs) Pre(cmd *cobra.Command, _ []string) error {
return nil
}

func (opts *Logs) Run(cmd *cobra.Command, args []string) error {
func (opts *LogOptions) Run(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
auth, err := config.GetKraftCloudLoginFromContext(ctx)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/cli/kraft/cloud/instance/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import (
"kraftkit.sh/log"
)

type Remove struct {
type RemoveOptions struct {
Output string `long:"output" short:"o" usage:"Set output format" default:"table"`
All bool `long:"all" usage:"Stop all instances"`

metro string
}

func New() *cobra.Command {
cmd, err := cmdfactory.New(&Remove{}, cobra.Command{
cmd, err := cmdfactory.New(&RemoveOptions{}, cobra.Command{
Short: "Delete an instance",
Use: "delete UUID",
Aliases: []string{"del", "delete", "rm"},
Expand All @@ -51,7 +51,7 @@ func New() *cobra.Command {
return cmd
}

func (opts *Remove) Pre(cmd *cobra.Command, args []string) error {
func (opts *RemoveOptions) Pre(cmd *cobra.Command, args []string) error {
if !opts.All && len(args) == 0 {
return fmt.Errorf("either specify an instance UUID or --all flag")
}
Expand All @@ -67,7 +67,7 @@ func (opts *Remove) Pre(cmd *cobra.Command, args []string) error {
return nil
}

func (opts *Remove) Run(cmd *cobra.Command, args []string) error {
func (opts *RemoveOptions) Run(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
auth, err := config.GetKraftCloudLoginFromContext(ctx)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/cli/kraft/cloud/instance/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import (
"kraftkit.sh/log"
)

type Start struct {
type StartOptions struct {
WaitTimeoutMS int `local:"true" long:"wait_timeout_ms" short:"w" usage:"Timeout to wait for the instance to start in milliseconds"`
Output string `long:"output" short:"o" usage:"Set output format" default:"table"`

metro string
}

func New() *cobra.Command {
cmd, err := cmdfactory.New(&Start{}, cobra.Command{
cmd, err := cmdfactory.New(&StartOptions{}, cobra.Command{
Short: "Start an instance",
Use: "start [FLAGS] [PACKAGE]",
Args: cobra.ExactArgs(1),
Expand All @@ -46,7 +46,7 @@ func New() *cobra.Command {
return cmd
}

func (opts *Start) Pre(cmd *cobra.Command, _ []string) error {
func (opts *StartOptions) Pre(cmd *cobra.Command, _ []string) error {
opts.metro = cmd.Flag("metro").Value.String()
if opts.metro == "" {
opts.metro = os.Getenv("KRAFTCLOUD_METRO")
Expand All @@ -58,7 +58,7 @@ func (opts *Start) Pre(cmd *cobra.Command, _ []string) error {
return nil
}

func (opts *Start) Run(cmd *cobra.Command, args []string) error {
func (opts *StartOptions) Run(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
auth, err := config.GetKraftCloudLoginFromContext(ctx)
if err != nil {
Expand Down

0 comments on commit e462f98

Please sign in to comment.