enbas/cmd/enbas/main.go
Dan Anglin 84091f398d
feat: add Enbas CLI schema and code generator
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.
2024-08-13 14:53:26 +01:00

49 lines
917 B
Go

package main
import (
"flag"
"os"
"codeflow.dananglin.me.uk/apollo/enbas/internal/executor"
internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag"
"codeflow.dananglin.me.uk/apollo/enbas/internal/usage"
)
func main() {
if err := run(); err != nil {
os.Exit(1)
}
}
func run() error {
var (
configDir string
noColorFlag internalFlag.BoolPtrValue
)
flag.StringVar(&configDir, "config-dir", "", "Specify your config directory")
flag.Var(&noColorFlag, "no-color", "Disable ANSI colour output when displaying text on screen")
flag.Usage = usage.AppUsageFunc()
flag.Parse()
if flag.NArg() < 1 {
flag.Usage()
return nil
}
var noColor bool
if noColorFlag.Value != nil {
noColor = *noColorFlag.Value
} else if os.Getenv("NO_COLOR") != "" {
noColor = true
}
command := flag.Arg(0)
args := flag.Args()[1:]
return executor.Execute(command, args, noColor, configDir)
}