add debug flag

This commit is contained in:
Daylin Morgan 2024-07-02 10:21:40 -05:00
parent 6930508add
commit a5d5d7d325
Signed by: daylin
GPG key ID: 950D13E9719334AD
2 changed files with 11 additions and 4 deletions

View file

@ -31,6 +31,7 @@ func Execute() {
var ( var (
flake string flake string
host string host string
debug bool
verbose bool verbose bool
nom bool nom bool
systemPath bool systemPath bool
@ -42,7 +43,7 @@ var rootCmd = &cobra.Command{
Use: "oizys", Use: "oizys",
Short: "nix begat oizys", Short: "nix begat oizys",
PersistentPreRun: func(cmd *cobra.Command, args []string) { PersistentPreRun: func(cmd *cobra.Command, args []string) {
if verbose { if debug {
log.Info("running with verbose mode") log.Info("running with verbose mode")
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
} }
@ -50,6 +51,7 @@ var rootCmd = &cobra.Command{
oizys.SetHost(host) oizys.SetHost(host)
oizys.SetVerbose(verbose) oizys.SetVerbose(verbose)
oizys.SetResetCache(resetCache) oizys.SetResetCache(resetCache)
oizys.SetDebug(debug)
}, },
} }
@ -76,5 +78,6 @@ func init() {
rootCmd.PersistentFlags().StringVar(&flake, "flake", "", "path to flake ($OIZYS_DIR or $HOME/oizys)") rootCmd.PersistentFlags().StringVar(&flake, "flake", "", "path to flake ($OIZYS_DIR or $HOME/oizys)")
rootCmd.PersistentFlags().StringVar(&host, "host", "", "host to build (current host)") rootCmd.PersistentFlags().StringVar(&host, "host", "", "host to build (current host)")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "show verbose output") 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") rootCmd.PersistentFlags().BoolVar(&resetCache, "reset-cache", false, "set narinfo-cache-negative-ttl to 0")
} }

View file

@ -30,6 +30,7 @@ type Oizys struct {
verbose bool verbose bool
systemPath bool systemPath bool
resetCache bool resetCache bool
debug bool
} }
func New() *Oizys { func New() *Oizys {
@ -69,6 +70,8 @@ func SetFlake(path string) {
} }
} }
func SetDebug(debug bool) { o.debug = debug }
func SetCache(name string) { func SetCache(name string) {
if name != "" { if name != "" {
o.cache = name o.cache = name
@ -215,10 +218,11 @@ func parseDryRun2(buf string) ([]string, []string) {
return parts[0], parts[1] return parts[0], parts[1]
} }
// TODO: refactor to account for --debug and not --verbose?
func showDryRunResult(nixOutput string, verbose bool) { func showDryRunResult(nixOutput string, verbose bool) {
toBuild, toFetch := parseDryRun(nixOutput) toBuild, toFetch := parseDryRun(nixOutput)
toBuild.show(verbose) toFetch.show(o.debug)
toFetch.show(verbose) toBuild.show(true)
} }
func Dry(verbose bool, minimal bool, rest ...string) { func Dry(verbose bool, minimal bool, rest ...string) {
@ -288,7 +292,7 @@ func NixBuild(nom bool, minimal bool, rest ...string) {
} }
cmd.Args = append(cmd.Args, append(drvs, "--no-link")...) cmd.Args = append(cmd.Args, append(drvs, "--no-link")...)
} }
if !o.inCI { if !o.inCI {
cmd.Args = append(cmd.Args, "--log-format", "multiline") cmd.Args = append(cmd.Args, "--log-format", "multiline")
} }
cmd.Args = append(cmd.Args, rest...) cmd.Args = append(cmd.Args, rest...)