checkpoint: add init to schema
This commit is contained in:
parent
622ee40306
commit
e23e7de262
3 changed files with 35 additions and 26 deletions
|
@ -7,6 +7,28 @@ import (
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/printer"
|
"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.
|
// LoginExecutor is the executor for the login command.
|
||||||
type LoginExecutor struct {
|
type LoginExecutor struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
|
@ -25,7 +47,7 @@ func NewLoginExecutor(
|
||||||
config: config,
|
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")
|
exe.StringVar(&exe.instance, "instance", "", "The instance that you want to log into")
|
||||||
return &exe
|
return &exe
|
||||||
|
@ -50,7 +72,7 @@ func NewSwitchExecutor(
|
||||||
config: config,
|
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.accountName, "account-name", "", "The name of the account")
|
||||||
exe.StringVar(&exe.to, "to", "", "TBC")
|
exe.StringVar(&exe.to, "to", "", "TBC")
|
||||||
|
|
|
@ -1,34 +1,12 @@
|
||||||
package executor
|
package executor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/printer"
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/utilities"
|
"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 {
|
func (i *InitExecutor) Execute() error {
|
||||||
if err := utilities.EnsureDirectory(i.configDir); err != nil {
|
if err := utilities.EnsureDirectory(i.configDir); err != nil {
|
||||||
return fmt.Errorf("unable to ensure that the configuration directory is present: %w", err)
|
return fmt.Errorf("unable to ensure that the configuration directory is present: %w", err)
|
||||||
|
|
|
@ -19,11 +19,20 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"commands": {
|
"commands": {
|
||||||
|
"init": {
|
||||||
|
"additionalFields": [
|
||||||
|
{ "name": "configDir", "type": "string"}
|
||||||
|
],
|
||||||
|
"flags": [],
|
||||||
|
"summary": "Creates a new configuration file in the specified configuration directory",
|
||||||
|
"useConfig": false,
|
||||||
|
"usePrinter": true
|
||||||
|
},
|
||||||
"login": {
|
"login": {
|
||||||
"flags": [
|
"flags": [
|
||||||
{ "flag": "instance", "default": "" }
|
{ "flag": "instance", "default": "" }
|
||||||
],
|
],
|
||||||
"summary": "Log into an account on GoToSocial",
|
"summary": "Logs into an account on GoToSocial",
|
||||||
"useConfig": true,
|
"useConfig": true,
|
||||||
"usePrinter": true
|
"usePrinter": true
|
||||||
},
|
},
|
||||||
|
@ -32,7 +41,7 @@
|
||||||
{ "flag": "account-name", "default": "" },
|
{ "flag": "account-name", "default": "" },
|
||||||
{ "flag": "to", "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,
|
"useConfig": true,
|
||||||
"usePrinter": true
|
"usePrinter": true
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue