cli cleanup

This commit is contained in:
Daylin Morgan 2024-08-02 12:22:39 -05:00
parent 805f1c19b3
commit 884bc993ec
Signed by: daylin
GPG key ID: 950D13E9719334AD
4 changed files with 10 additions and 12 deletions

View file

@ -10,10 +10,12 @@ import (
)
var validArgs = []string{
"switch", "boot", "test", "build", "dry-build", "dry-activate", "edit", "repl",
"switch", "boot", "test", "build", "dry-build",
"dry-activate", "edit", "repl",
"build-vm", "build-vm-with-bootloader",
"list-generations",
}
var osCmd = &cobra.Command{
Use: "os [subcmd]",
Short: "nixos-rebuild wrapper",
@ -21,11 +23,14 @@ var osCmd = &cobra.Command{
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil {
return err
}
// Run the custom validation logic
if slices.Contains(validArgs, args[0]) {
return nil
}
return fmt.Errorf("unexpected arg: %s\nexpected one of:\n %s", args[0], strings.Join(validArgs, ", "))
return fmt.Errorf(
"unexpected arg: %s\nexpected one of:\n %s",
args[0],
strings.Join(validArgs, ", "),
)
},
Run: func(cmd *cobra.Command, args []string) {
subcmd := args[0]

View file

@ -32,7 +32,6 @@ var (
flake string
host string
debug bool
verbose bool
systemPath bool
resetCache bool
minimal bool
@ -48,7 +47,6 @@ var rootCmd = &cobra.Command{
}
oizys.SetFlake(flake)
oizys.SetHost(host)
oizys.SetVerbose(verbose)
oizys.SetResetCache(resetCache)
oizys.SetDebug(debug)
},
@ -76,7 +74,6 @@ func init() {
rootCmd.CompletionOptions.HiddenDefaultCmd = true
rootCmd.PersistentFlags().StringVar(&flake, "flake", "", "path to flake ($OIZYS_DIR or $HOME/oizys)")
rootCmd.PersistentFlags().StringVar(&host, "host", "", "host(s) to build (current host)")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "show verbose output")
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "show debug output")
rootCmd.PersistentFlags().BoolVar(&resetCache, "reset-cache", false, "set narinfo-cache-negative-ttl to 0")
}

View file

@ -9,7 +9,6 @@ require (
github.com/google/go-github/v63 v63.0.0
github.com/ivanpirog/coloredcobra v1.0.1
github.com/spf13/cobra v1.8.0
golang.org/x/term v0.21.0
)
require (
@ -28,4 +27,5 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
)

View file

@ -35,7 +35,6 @@ type Oizys struct {
githubToken string
local bool
inCI bool
verbose bool
systemPath bool
resetCache bool
debug bool
@ -101,9 +100,6 @@ func SetHost(name string) {
}
func GetHost() string { return o.host }
func SetVerbose(v bool) {
o.verbose = v
}
func SetResetCache(reset bool) {
o.resetCache = reset
@ -241,7 +237,7 @@ func NixosRebuild(subcmd string, rest ...string) {
if !o.inCI {
cmd.Args = append(cmd.Args, "--log-format", "multiline")
}
if o.verbose {
if o.debug {
cmd.Args = append(cmd.Args, "--print-build-logs")
}
cmd.Args = append(cmd.Args, rest...)