add verbose flag to oizys dry

This commit is contained in:
Daylin Morgan 2024-05-13 12:04:36 -05:00
parent 5e4629c1e0
commit 887fe2f49d
Signed by: daylin
GPG key ID: 950D13E9719334AD
2 changed files with 22 additions and 9 deletions

View file

@ -11,10 +11,19 @@ var dryCmd = &cobra.Command{
Short: "poor man's nix flake check", Short: "poor man's nix flake check",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
oizys.CheckFlake(flake) oizys.CheckFlake(flake)
oizys.NixDryRun(flake, host) oizys.NixDryRun(flake, host, verbose)
}, },
} }
var verbose bool
func init() { func init() {
rootCmd.AddCommand(dryCmd) rootCmd.AddCommand(dryCmd)
dryCmd.Flags().BoolVarP(
&verbose,
"verbose",
"v",
false,
"show verbose output",
)
} }

View file

@ -29,11 +29,12 @@ func TerminalSize() (int, int) {
return w, h return w, h
} }
func ParseDryRunOutput(nixOutput string) { func ParseDryRunOutput(nixOutput string, verbose bool) {
output := termenv.NewOutput(os.Stdout) output := termenv.NewOutput(os.Stdout)
parts := strings.Split(nixOutput, "\nthese") parts := strings.Split(nixOutput, "\nthese")
if len(parts) != 3 { if len(parts) != 3 {
log.Println("no changes...") log.Println("no changes...")
log.Println(output)
return return
} }
built := strings.Split(strings.TrimSpace(parts[1]), "\n")[1:] built := strings.Split(strings.TrimSpace(parts[1]), "\n")[1:]
@ -58,15 +59,18 @@ func ParseDryRunOutput(nixOutput string) {
rows = append(rows, table.Row{hash, name}) rows = append(rows, table.Row{hash, name})
} }
if verbose {
w, _ := TerminalSize() w, _ := TerminalSize()
columns := []table.Column{ columns := []table.Column{
{Title: "hash", Width: 34}, {Title: "hash", Width: 34},
{Title: "pkg", Width: int(w / 4)}, {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) output := termenv.NewOutput(os.Stdout)
path := Output(flake, host) path := Output(flake, host)
cmd := exec.Command("nix", "build", path, "--dry-run") cmd := exec.Command("nix", "build", path, "--dry-run")
@ -85,7 +89,7 @@ func NixDryRun(flake string, host string) {
fmt.Println(string(result)) fmt.Println(string(result))
log.Fatal(err) log.Fatal(err)
} }
ParseDryRunOutput(string(result)) ParseDryRunOutput(string(result), verbose)
} }
func NixosRebuild(subcmd string, flake string, rest ...string) { func NixosRebuild(subcmd string, flake string, rest ...string) {