Skip to content
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

CLI: Remove redundant flags #445

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions cmd/microcloud/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
type cmdAdd struct {
common *CmdControl

flagWipe bool
flagSessionTimeout int64
}

Expand All @@ -29,7 +28,6 @@ func (c *cmdAdd) Command() *cobra.Command {
RunE: c.Run,
}

cmd.Flags().BoolVar(&c.flagWipe, "wipe", false, "Wipe disks to add to MicroCeph")
cmd.Flags().Int64Var(&c.flagSessionTimeout, "session-timeout", 0, "Amount of seconds to wait for the trust establishment session. Defaults: 60m")

return cmd
Expand All @@ -41,13 +39,12 @@ func (c *cmdAdd) Run(cmd *cobra.Command, args []string) error {
}

cfg := initConfig{
bootstrap: false,
setupMany: true,
wipeAllDisks: c.flagWipe,
common: c.common,
asker: &c.common.asker,
systems: map[string]InitSystem{},
state: map[string]service.SystemInformation{},
bootstrap: false,
setupMany: true,
common: c.common,
asker: &c.common.asker,
systems: map[string]InitSystem{},
state: map[string]service.SystemInformation{},
}

cfg.sessionTimeout = DefaultSessionTimeout
Expand Down
18 changes: 7 additions & 11 deletions cmd/microcloud/ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (c *initConfig) askLocalPool(sh *service.Handler) error {
return fmt.Errorf("Failed to add local storage pool: Some peers don't have an available disk")
}

if !c.wipeAllDisks && wipeable {
if wipeable {
fmt.Println("Select which disks to wipe:")
err := table.Render(selectedRows)
if err != nil {
Expand Down Expand Up @@ -377,7 +377,7 @@ func (c *initConfig) askLocalPool(sh *service.Handler) error {
return nil
}

if c.wipeAllDisks && wipeable {
if wipeable {
toWipe = selectedDisks
}

Expand Down Expand Up @@ -638,11 +638,6 @@ func (c *initConfig) askRemotePool(sh *service.Handler) error {

sort.Sort(cli.SortColumnsNaturally(data))
table := NewSelectableTable(header, data)
selected := table.rows
var toWipe []string
if c.wipeAllDisks {
toWipe = selected
}

if len(table.rows) == 0 {
return nil
Expand All @@ -654,12 +649,13 @@ func (c *initConfig) askRemotePool(sh *service.Handler) error {
return err
}

selected, err = table.GetSelections()
selected, err := table.GetSelections()
if err != nil {
return fmt.Errorf("Invalid disk configuration: %w", err)
}

if len(selected) > 0 && !c.wipeAllDisks {
var toWipe []string
if len(selected) > 0 {
fmt.Println("Select which disks to wipe:")
err := table.Render(selected)
if err != nil {
Expand Down Expand Up @@ -728,8 +724,8 @@ func (c *initConfig) askRemotePool(sh *service.Handler) error {
}
}

encryptDisks := c.encryptAllDisks
if !c.encryptAllDisks && len(selectedDisks) > 0 {
encryptDisks := false
if len(selectedDisks) > 0 {
var err error
encryptDisks, err = c.asker.AskBool("Do you want to encrypt the selected disks? (yes/no) [default=no]: ", "no")
if err != nil {
Expand Down
29 changes: 7 additions & 22 deletions cmd/microcloud/main_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ type initConfig struct {
// sessionTimeout is the duration to wait for the trust establishment session to complete.
sessionTimeout time.Duration

// wipeAllDisks indicates whether all disks should be wiped, or if the user should be prompted.
wipeAllDisks bool

// encryptAllDisks indicates whether all disks should be encrypted, or if the user should be prompted.
encryptAllDisks bool

// lookupIface is the interface used for multicast lookup.
lookupIface *net.Interface

Expand All @@ -126,10 +120,7 @@ type initConfig struct {
type cmdInit struct {
common *CmdControl

flagSessionTimeout int64
flagWipeAllDisks bool
flagEncryptAllDisks bool
flagAddress string
flagSessionTimeout int64
}

func (c *cmdInit) Command() *cobra.Command {
Expand All @@ -140,9 +131,6 @@ func (c *cmdInit) Command() *cobra.Command {
RunE: c.Run,
}

cmd.Flags().BoolVar(&c.flagWipeAllDisks, "wipe", false, "Wipe disks to add to MicroCeph")
cmd.Flags().BoolVar(&c.flagEncryptAllDisks, "encrypt", false, "Encrypt disks to add to MicroCeph")
cmd.Flags().StringVar(&c.flagAddress, "address", "", "Address to use for MicroCloud")
cmd.Flags().Int64Var(&c.flagSessionTimeout, "session-timeout", 0, "Amount of seconds to wait for the trust establishment session. Defaults: 60m")

return cmd
Expand All @@ -154,15 +142,12 @@ func (c *cmdInit) Run(cmd *cobra.Command, args []string) error {
}

cfg := initConfig{
bootstrap: true,
setupMany: true,
address: c.flagAddress,
wipeAllDisks: c.flagWipeAllDisks,
encryptAllDisks: c.flagEncryptAllDisks,
Comment on lines -160 to -161
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields are no longer assigned on the struct, so I think we can remove them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed.

common: c.common,
asker: &c.common.asker,
systems: map[string]InitSystem{},
state: map[string]service.SystemInformation{},
bootstrap: true,
setupMany: true,
common: c.common,
asker: &c.common.asker,
systems: map[string]InitSystem{},
state: map[string]service.SystemInformation{},
}

cfg.sessionTimeout = DefaultSessionTimeout
Expand Down
Loading