From e23e7de2627a7d6777aebb6b30135681f3983d69 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Fri, 9 Aug 2024 23:59:45 +0100 Subject: [PATCH] checkpoint: add init to schema --- internal/executor/executors.go | 26 ++++++++++++++++++++++++-- internal/executor/init.go | 22 ---------------------- schema/enbas_cli_schema.json | 13 +++++++++++-- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/internal/executor/executors.go b/internal/executor/executors.go index 24469a4..b38ba44 100644 --- a/internal/executor/executors.go +++ b/internal/executor/executors.go @@ -7,6 +7,28 @@ import ( "codeflow.dananglin.me.uk/apollo/enbas/internal/printer" ) +// InitExecutor is the executor for the init command. +type InitExecutor struct { + *flag.FlagSet + printer *printer.Printer + configDir string +} + +func NewInitExecutor( + printer *printer.Printer, + configDir string, +) *InitExecutor { + exe := InitExecutor{ + FlagSet: flag.NewFlagSet("init", flag.ExitOnError), + printer: printer, + configDir: configDir, + } + + exe.Usage = commandUsageFunc("init", "Creates a new configuration file in the specified configuration directory", exe.FlagSet) + + return &exe +} + // LoginExecutor is the executor for the login command. type LoginExecutor struct { *flag.FlagSet @@ -25,7 +47,7 @@ func NewLoginExecutor( config: config, } - exe.Usage = commandUsageFunc("login", "Log into an account on GoToSocial", exe.FlagSet) + exe.Usage = commandUsageFunc("login", "Logs into an account on GoToSocial", exe.FlagSet) exe.StringVar(&exe.instance, "instance", "", "The instance that you want to log into") return &exe @@ -50,7 +72,7 @@ func NewSwitchExecutor( config: config, } - exe.Usage = commandUsageFunc("switch", "Perform a switch operation (e.g. switching between logged in accounts)", exe.FlagSet) + exe.Usage = commandUsageFunc("switch", "Performs a switch operation (e.g. switching between logged in accounts)", exe.FlagSet) exe.StringVar(&exe.accountName, "account-name", "", "The name of the account") exe.StringVar(&exe.to, "to", "", "TBC") diff --git a/internal/executor/init.go b/internal/executor/init.go index 35b64a4..c0f0129 100644 --- a/internal/executor/init.go +++ b/internal/executor/init.go @@ -1,34 +1,12 @@ package executor import ( - "flag" "fmt" "codeflow.dananglin.me.uk/apollo/enbas/internal/config" - "codeflow.dananglin.me.uk/apollo/enbas/internal/printer" "codeflow.dananglin.me.uk/apollo/enbas/internal/utilities" ) -type InitExecutor struct { - *flag.FlagSet - - printer *printer.Printer - configDir string -} - -func NewInitExecutor(printer *printer.Printer, configDir, name, summary string) *InitExecutor { - initExe := InitExecutor{ - FlagSet: flag.NewFlagSet(name, flag.ExitOnError), - - printer: printer, - configDir: configDir, - } - - initExe.Usage = commandUsageFunc(name, summary, initExe.FlagSet) - - return &initExe -} - 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) diff --git a/schema/enbas_cli_schema.json b/schema/enbas_cli_schema.json index 8125631..652d226 100644 --- a/schema/enbas_cli_schema.json +++ b/schema/enbas_cli_schema.json @@ -19,11 +19,20 @@ }, "commands": { + "init": { + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], + "flags": [], + "summary": "Creates a new configuration file in the specified configuration directory", + "useConfig": false, + "usePrinter": true + }, "login": { "flags": [ { "flag": "instance", "default": "" } ], - "summary": "Log into an account on GoToSocial", + "summary": "Logs into an account on GoToSocial", "useConfig": true, "usePrinter": true }, @@ -32,7 +41,7 @@ { "flag": "account-name", "default": "" }, { "flag": "to", "default": "" } ], - "summary": "Perform a switch operation (e.g. switching between logged in accounts)", + "summary": "Performs a switch operation (e.g. switching between logged in accounts)", "useConfig": true, "usePrinter": true },