Skip to content

Commit

Permalink
lxc: Unexport all Run and Command methods (exported).
Browse files Browse the repository at this point in the history
The "checkPrivateReceivers" argument to the "exported" rule of the
"revive" linter flags all of these methods. This rule was added to
enforce comments e.g. exported methods for interface implementations
where the implementing struct is kept private. The `Run` and `Command`
methods are not called outside of the `lxc` package, so the rule is
correctly indicating that these methods should not be exported.

Signed-off-by: Mark Laing <[email protected]>
  • Loading branch information
markylaing committed Jun 4, 2024
1 parent 1bde882 commit 5505b96
Show file tree
Hide file tree
Showing 49 changed files with 1,103 additions and 1,118 deletions.
20 changes: 10 additions & 10 deletions lxc/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ type cmdStart struct {
action *cmdAction
}

// The function Command() returns a cobra.Command object representing the "start" command.
// The function command() returns a cobra.Command object representing the "start" command.
// It is used to start one or more instances specified by the user.
func (c *cmdStart) Command() *cobra.Command {
func (c *cmdStart) command() *cobra.Command {
cmdAction := cmdAction{global: c.global}
c.action = &cmdAction

Expand All @@ -41,9 +41,9 @@ type cmdPause struct {
action *cmdAction
}

// The function Command() returns a cobra.Command object representing the "pause" command.
// The function command() returns a cobra.Command object representing the "pause" command.
// It is used to pause (or freeze) one or more instances specified by the user. This command is hidden and has an alias "freeze".
func (c *cmdPause) Command() *cobra.Command {
func (c *cmdPause) command() *cobra.Command {
cmdAction := cmdAction{global: c.global}
c.action = &cmdAction

Expand All @@ -63,9 +63,9 @@ type cmdRestart struct {
action *cmdAction
}

// The function Command() returns a cobra.Command object representing the "restart" command.
// The function command() returns a cobra.Command object representing the "restart" command.
// It is used to restart one or more instances specified by the user. This command restarts the instances, which is the opposite of the "pause" command.
func (c *cmdRestart) Command() *cobra.Command {
func (c *cmdRestart) command() *cobra.Command {
cmdAction := cmdAction{global: c.global}
c.action = &cmdAction

Expand All @@ -86,9 +86,9 @@ type cmdStop struct {
action *cmdAction
}

// The function Command() returns a cobra.Command object representing the "stop" command.
// The function command() returns a cobra.Command object representing the "stop" command.
// It is used to stop one or more instances specified by the user. This command stops the instances, effectively shutting them down.
func (c *cmdStop) Command() *cobra.Command {
func (c *cmdStop) command() *cobra.Command {
cmdAction := cmdAction{global: c.global}
c.action = &cmdAction

Expand Down Expand Up @@ -116,7 +116,7 @@ type cmdAction struct {
// It creates a command with a specific action, defines flags based on that action, and assigns appropriate help text.
func (c *cmdAction) Command(action string) *cobra.Command {
cmd := &cobra.Command{}
cmd.RunE = c.Run
cmd.RunE = c.run

cmd.Flags().BoolVar(&c.flagAll, "all", false, i18n.G("Run against all instances"))

Expand Down Expand Up @@ -302,7 +302,7 @@ func (c *cmdAction) doAction(action string, conf *config.Config, nameArg string)

// Run is a method of the cmdAction structure that implements the execution logic for the given Cobra command.
// It handles actions on instances (single or all) and manages error handling, console flag restrictions, and batch operations.
func (c *cmdAction) Run(cmd *cobra.Command, args []string) error {
func (c *cmdAction) run(cmd *cobra.Command, args []string) error {
conf := c.global.conf

var names []string
Expand Down
34 changes: 17 additions & 17 deletions lxc/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type cmdAlias struct {

// Command is a method of the cmdAlias structure that returns a new cobra Command for managing command aliases.
// This includes commands for adding, listing, renaming, and removing aliases, along with their usage and descriptions.
func (c *cmdAlias) Command() *cobra.Command {
func (c *cmdAlias) command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = usage("alias")
cmd.Short = i18n.G("Manage command aliases")
Expand All @@ -25,19 +25,19 @@ func (c *cmdAlias) Command() *cobra.Command {

// Add
aliasAddCmd := cmdAliasAdd{global: c.global, alias: c}
cmd.AddCommand(aliasAddCmd.Command())
cmd.AddCommand(aliasAddCmd.command())

// List
aliasListCmd := cmdAliasList{global: c.global, alias: c}
cmd.AddCommand(aliasListCmd.Command())
cmd.AddCommand(aliasListCmd.command())

// Rename
aliasRenameCmd := cmdAliasRename{global: c.global, alias: c}
cmd.AddCommand(aliasRenameCmd.Command())
cmd.AddCommand(aliasRenameCmd.command())

// Remove
aliasRemoveCmd := cmdAliasRemove{global: c.global, alias: c}
cmd.AddCommand(aliasRemoveCmd.Command())
cmd.AddCommand(aliasRemoveCmd.command())

// Workaround for subcommand usage errors. See: https://github.com/spf13/cobra/issues/706
cmd.Args = cobra.NoArgs
Expand All @@ -53,7 +53,7 @@ type cmdAliasAdd struct {

// Command is a method of the cmdAliasAdd structure that returns a new cobra Command for adding new command aliases.
// It specifies the command usage, description, and examples, and links it to the RunE method for execution logic.
func (c *cmdAliasAdd) Command() *cobra.Command {
func (c *cmdAliasAdd) command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = usage("add", i18n.G("<alias> <target>"))
cmd.Short = i18n.G("Add new aliases")
Expand All @@ -63,14 +63,14 @@ func (c *cmdAliasAdd) Command() *cobra.Command {
`lxc alias add list "list -c ns46S"
Overwrite the "list" command to pass -c ns46S.`))

cmd.RunE = c.Run
cmd.RunE = c.run

return cmd
}

// Run is a method of the cmdAliasAdd structure. It implements the logic to add a new alias command.
// The function checks for valid arguments, verifies if the alias already exists, and if not, adds the new alias to the configuration.
func (c *cmdAliasAdd) Run(cmd *cobra.Command, args []string) error {
func (c *cmdAliasAdd) run(cmd *cobra.Command, args []string) error {
conf := c.global.conf

// Quick checks.
Expand Down Expand Up @@ -102,7 +102,7 @@ type cmdAliasList struct {

// Command is a method of the cmdAliasList structure that returns a new cobra Command for listing command aliases.
// It specifies the command usage, description, aliases, and output formatting options, and links it to the RunE method for execution logic.
func (c *cmdAliasList) Command() *cobra.Command {
func (c *cmdAliasList) command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = usage("list")
cmd.Aliases = []string{"ls"}
Expand All @@ -111,14 +111,14 @@ func (c *cmdAliasList) Command() *cobra.Command {
`List aliases`))
cmd.Flags().StringVarP(&c.flagFormat, "format", "f", "table", i18n.G("Format (csv|json|table|yaml|compact)")+"``")

cmd.RunE = c.Run
cmd.RunE = c.run

return cmd
}

// Run is a method of the cmdAliasList structure. It implements the logic to list existing command aliases.
// The function checks for valid arguments, collects all the aliases, sorts them, and renders them in the specified format.
func (c *cmdAliasList) Run(cmd *cobra.Command, args []string) error {
func (c *cmdAliasList) run(cmd *cobra.Command, args []string) error {
conf := c.global.conf

// Quick checks.
Expand Down Expand Up @@ -151,7 +151,7 @@ type cmdAliasRename struct {

// Command is a method of the cmdAliasRename structure. It returns a new cobra.Command object.
// This command allows a user to rename existing aliases in the CLI application.
func (c *cmdAliasRename) Command() *cobra.Command {
func (c *cmdAliasRename) command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = usage("rename", i18n.G("<old alias> <new alias>"))
cmd.Aliases = []string{"mv"}
Expand All @@ -162,14 +162,14 @@ func (c *cmdAliasRename) Command() *cobra.Command {
`lxc alias rename list my-list
Rename existing alias "list" to "my-list".`))

cmd.RunE = c.Run
cmd.RunE = c.run

return cmd
}

// Run is a method of the cmdAliasRename structure. It takes a cobra command and a slice of strings as arguments.
// This method checks the validity of arguments, ensures the existence of the old alias, verifies the non-existence of the new alias, and then proceeds to rename the alias in the configuration.
func (c *cmdAliasRename) Run(cmd *cobra.Command, args []string) error {
func (c *cmdAliasRename) run(cmd *cobra.Command, args []string) error {
conf := c.global.conf

// Quick checks.
Expand Down Expand Up @@ -206,7 +206,7 @@ type cmdAliasRemove struct {

// Command is a method of the cmdAliasRemove structure. It configures and returns a cobra.Command object.
// This command enables the removal of a given alias from the command line interface.
func (c *cmdAliasRemove) Command() *cobra.Command {
func (c *cmdAliasRemove) command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = usage("remove", i18n.G("<alias>"))
cmd.Aliases = []string{"rm"}
Expand All @@ -217,14 +217,14 @@ func (c *cmdAliasRemove) Command() *cobra.Command {
`lxc alias remove my-list
Remove the "my-list" alias.`))

cmd.RunE = c.Run
cmd.RunE = c.run

return cmd
}

// Run is a method of the cmdAliasRemove structure that executes the actual operation of the alias removal command.
// It takes as input the name of the alias to be removed and updates the global configuration file to reflect this change.
func (c *cmdAliasRemove) Run(cmd *cobra.Command, args []string) error {
func (c *cmdAliasRemove) run(cmd *cobra.Command, args []string) error {
conf := c.global.conf

// Quick checks.
Expand Down
Loading

0 comments on commit 5505b96

Please sign in to comment.