From 887fe2f49d2e09ec90ea48d970961fa5495105cb Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Mon, 13 May 2024 12:04:36 -0500 Subject: [PATCH] add verbose flag to oizys dry --- pkgs/oizys/oizys-go/cmd/dry.go | 11 ++++++++++- pkgs/oizys/oizys-go/pkg/oizys/oizys.go | 20 ++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pkgs/oizys/oizys-go/cmd/dry.go b/pkgs/oizys/oizys-go/cmd/dry.go index 308a3b2..cf802e9 100644 --- a/pkgs/oizys/oizys-go/cmd/dry.go +++ b/pkgs/oizys/oizys-go/cmd/dry.go @@ -11,10 +11,19 @@ var dryCmd = &cobra.Command{ Short: "poor man's nix flake check", Run: func(cmd *cobra.Command, args []string) { oizys.CheckFlake(flake) - oizys.NixDryRun(flake, host) + oizys.NixDryRun(flake, host, verbose) }, } +var verbose bool + func init() { rootCmd.AddCommand(dryCmd) + dryCmd.Flags().BoolVarP( + &verbose, + "verbose", + "v", + false, + "show verbose output", + ) } diff --git a/pkgs/oizys/oizys-go/pkg/oizys/oizys.go b/pkgs/oizys/oizys-go/pkg/oizys/oizys.go index 684717f..f210303 100644 --- a/pkgs/oizys/oizys-go/pkg/oizys/oizys.go +++ b/pkgs/oizys/oizys-go/pkg/oizys/oizys.go @@ -29,11 +29,12 @@ func TerminalSize() (int, int) { return w, h } -func ParseDryRunOutput(nixOutput string) { +func ParseDryRunOutput(nixOutput string, verbose bool) { output := termenv.NewOutput(os.Stdout) parts := strings.Split(nixOutput, "\nthese") if len(parts) != 3 { log.Println("no changes...") + log.Println(output) return } built := strings.Split(strings.TrimSpace(parts[1]), "\n")[1:] @@ -58,15 +59,18 @@ func ParseDryRunOutput(nixOutput string) { rows = append(rows, table.Row{hash, name}) } - w, _ := TerminalSize() - columns := []table.Column{ - {Title: "hash", Width: 34}, - {Title: "pkg", Width: int(w / 4)}, + if verbose { + + w, _ := TerminalSize() + columns := []table.Column{ + {Title: "hash", Width: 34}, + {Title: "pkg", Width: int(w / 4)}, + } + ShowTable(columns, rows) } - ShowTable(columns, rows) } -func NixDryRun(flake string, host string) { +func NixDryRun(flake string, host string, verbose bool) { output := termenv.NewOutput(os.Stdout) path := Output(flake, host) cmd := exec.Command("nix", "build", path, "--dry-run") @@ -85,7 +89,7 @@ func NixDryRun(flake string, host string) { fmt.Println(string(result)) log.Fatal(err) } - ParseDryRunOutput(string(result)) + ParseDryRunOutput(string(result), verbose) } func NixosRebuild(subcmd string, flake string, rest ...string) {