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

Added multiple headings in the the files of doc/LXC directory #11955

Merged
merged 3 commits into from
Jul 7, 2023
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
16 changes: 16 additions & 0 deletions lxc/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type cmdStart struct {
action *cmdAction
}

// 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 {
cmdAction := cmdAction{global: c.global}
c.action = &cmdAction
Expand All @@ -39,6 +41,8 @@ type cmdPause struct {
action *cmdAction
}

// 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 {
cmdAction := cmdAction{global: c.global}
c.action = &cmdAction
Expand All @@ -60,6 +64,8 @@ type cmdRestart struct {
action *cmdAction
}

// 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 {
cmdAction := cmdAction{global: c.global}
c.action = &cmdAction
Expand All @@ -81,6 +87,8 @@ type cmdStop struct {
action *cmdAction
}

// 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 {
cmdAction := cmdAction{global: c.global}
c.action = &cmdAction
Expand All @@ -105,6 +113,8 @@ type cmdAction struct {
flagTimeout int
}

// Command is a method of the cmdAction structure which constructs and configures a cobra Command object.
// 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
Expand All @@ -130,6 +140,8 @@ func (c *cmdAction) Command(action string) *cobra.Command {
return cmd
}

// doActionAll is a method of the cmdAction structure. It performs a specified action on all instances of a remote resource.
// It ensures that flags and parameters are appropriately set, and handles any errors that may occur during the process.
func (c *cmdAction) doActionAll(action string, resource remoteResource) error {
if resource.name != "" {
// both --all and instance name given.
Expand Down Expand Up @@ -189,6 +201,8 @@ func (c *cmdAction) doActionAll(action string, resource remoteResource) error {
return nil
}

// doAction is a method of the cmdAction structure. It carries out a specified action on an instance,
// using a given config and instance name. It manages state changes, flag checks, error handling and console attachment.
func (c *cmdAction) doAction(action string, conf *config.Config, nameArg string) error {
state := false

Expand Down Expand Up @@ -287,6 +301,8 @@ func (c *cmdAction) doAction(action string, conf *config.Config, nameArg string)
return nil
}

// 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 {
conf := c.global.conf

Expand Down
18 changes: 18 additions & 0 deletions lxc/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type cmdAlias struct {
global *cmdGlobal
}

// 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 {
cmd := &cobra.Command{}
cmd.Use = usage("alias")
Expand Down Expand Up @@ -49,6 +51,8 @@ type cmdAliasAdd struct {
alias *cmdAlias
}

// 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 {
cmd := &cobra.Command{}
cmd.Use = usage("add", i18n.G("<alias> <target>"))
Expand All @@ -64,6 +68,8 @@ func (c *cmdAliasAdd) Command() *cobra.Command {
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 {
conf := c.global.conf

Expand Down Expand Up @@ -94,6 +100,8 @@ type cmdAliasList struct {
flagFormat string
}

// 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 {
cmd := &cobra.Command{}
cmd.Use = usage("list")
Expand All @@ -108,6 +116,8 @@ func (c *cmdAliasList) Command() *cobra.Command {
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 {
conf := c.global.conf

Expand Down Expand Up @@ -139,6 +149,8 @@ type cmdAliasRename struct {
alias *cmdAlias
}

// 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 {
cmd := &cobra.Command{}
cmd.Use = usage("rename", i18n.G("<old alias> <new alias>"))
Expand All @@ -155,6 +167,8 @@ func (c *cmdAliasRename) Command() *cobra.Command {
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 {
conf := c.global.conf

Expand Down Expand Up @@ -190,6 +204,8 @@ type cmdAliasRemove struct {
alias *cmdAlias
}

// 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 {
cmd := &cobra.Command{}
cmd.Use = usage("remove", i18n.G("<alias>"))
Expand All @@ -206,6 +222,8 @@ func (c *cmdAliasRemove) Command() *cobra.Command {
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 {
conf := c.global.conf

Expand Down
4 changes: 4 additions & 0 deletions lxc/config/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ func (c *Config) GetImageServer(name string) (lxd.ImageServer, error) {
return d, nil
}

// getConnectionArgs retrieves the connection arguments for the specified remote.
// It constructs the necessary connection arguments based on the remote's configuration, including authentication type,
// authentication interactors, cookie jar, OIDC tokens, TLS certificates, and client key.
// The function returns the connection arguments or an error if any configuration is missing or encounters a problem.
func (c *Config) getConnectionArgs(name string) (*lxd.ConnectionArgs, error) {
remote := c.Remotes[name]
args := lxd.ConnectionArgs{
Expand Down