Dan Anglin
84091f398d
Summary: - Created a custom CLI schema for Enbas which will act as the Source of Truth for code and document generation. - Created a code generator which uses the schema to generate the executor definitions and code in the internal usage package. Changes: - Created the Enbas CLI schema as the Source of Truth for Enbas. - Created the code generator that generates the executor definitions and code in the usage package. - Regenerated the executor definitions using the code generator. - Moved the custom flag value types to the new internal flag package. - Created a new flag value type for the bool pointer to replace the flag.BoolFunc() used for the sensitive and no-color flags. - Moved the version and build variables to the new internal version package to simplify the version executor. - Created a new usage package and moved the usage functions there. - Changed the type of the account-name flag from string to the internal StringSliceValue type.
35 lines
970 B
Go
35 lines
970 B
Go
package executor
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/utilities"
|
|
)
|
|
|
|
func (i *InitExecutor) Execute() error {
|
|
if err := utilities.EnsureDirectory(i.configDir); err != nil {
|
|
return fmt.Errorf("unable to ensure that the configuration directory is present: %w", err)
|
|
}
|
|
|
|
i.printer.PrintSuccess("The configuration directory is present.")
|
|
|
|
fileExists, err := config.FileExists(i.configDir)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to check if the config file exists: %w", err)
|
|
}
|
|
|
|
if fileExists {
|
|
i.printer.PrintInfo("The configuration file is already present in " + i.configDir + "\n")
|
|
|
|
return nil
|
|
}
|
|
|
|
if err := config.SaveDefaultConfigToFile(i.configDir); err != nil {
|
|
return fmt.Errorf("unable to create a new configuration file in %s: %w", i.configDir, err)
|
|
}
|
|
|
|
i.printer.PrintSuccess("Successfully created a new configuration file in " + i.configDir)
|
|
|
|
return nil
|
|
}
|