mirror of
https://github.com/daylinmorgan/oizys.git
synced 2024-12-26 01:00:44 -06:00
Compare commits
No commits in common. "8fe9b61e64f17b4a8709c2992e02193656eb31bf" and "f7e25099e6774ccadda239ce8eee9a6a08de9f88" have entirely different histories.
8fe9b61e64
...
f7e25099e6
5 changed files with 48 additions and 12 deletions
1
.github/workflows/update.yml
vendored
1
.github/workflows/update.yml
vendored
|
@ -16,7 +16,6 @@ jobs:
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: daylin-bot/actions/setup@main
|
- uses: daylin-bot/actions/setup@main
|
||||||
- uses: ./.github/actions/clean-disk
|
|
||||||
|
|
||||||
- run: git checkout -B flake-lock
|
- run: git checkout -B flake-lock
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
quarto
|
quarto
|
||||||
cachix
|
cachix
|
||||||
graphviz
|
graphviz
|
||||||
# nix-du # failing to build suddenly?
|
nix-du
|
||||||
# https://github.com/symphorien/nix-du/issues/23
|
|
||||||
# maybe llvm related?
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ var dryCmd = &cobra.Command{
|
||||||
Use: "dry",
|
Use: "dry",
|
||||||
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.Dry( minimal, args...)
|
oizys.Dry(verbose, minimal, args...)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,13 +191,13 @@ func parseDryRun2(buf string) ([]string, []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: refactor to account for --debug and not --verbose?
|
// TODO: refactor to account for --debug and not --verbose?
|
||||||
func showDryRunResult(nixOutput string) {
|
func showDryRunResult(nixOutput string, verbose bool) {
|
||||||
toBuild, toFetch := parseDryRun(nixOutput)
|
toBuild, toFetch := parseDryRun(nixOutput)
|
||||||
toFetch.Show(o.debug)
|
toFetch.Show(o.debug)
|
||||||
toBuild.Show(true)
|
toBuild.Show(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Dry(minimal bool, rest ...string) {
|
func Dry(verbose bool, minimal bool, rest ...string) {
|
||||||
cmd := exec.Command("nix", "build", "--dry-run")
|
cmd := exec.Command("nix", "build", "--dry-run")
|
||||||
cmd.Args = append(cmd.Args, rest...)
|
cmd.Args = append(cmd.Args, rest...)
|
||||||
if o.resetCache {
|
if o.resetCache {
|
||||||
|
@ -226,7 +226,7 @@ func Dry(minimal bool, rest ...string) {
|
||||||
if minimal {
|
if minimal {
|
||||||
fmt.Println(string(result))
|
fmt.Println(string(result))
|
||||||
} else {
|
} else {
|
||||||
showDryRunResult(string(result))
|
showDryRunResult(string(result), verbose)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/charmbracelet/log"
|
"github.com/charmbracelet/log"
|
||||||
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ShowFailedOutput(buf []byte) {
|
func ShowFailedOutput(buf []byte) {
|
||||||
|
@ -22,23 +23,55 @@ func ShowFailedOutput(buf []byte) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: seperate parsing and displaying of packages
|
||||||
|
func terminalSize() (int, int) {
|
||||||
|
fd := os.Stdout.Fd()
|
||||||
|
if !term.IsTerminal(int(fd)) {
|
||||||
|
log.Error("failed to get terminal size")
|
||||||
|
return 80, 0
|
||||||
|
}
|
||||||
|
w, h, err := term.GetSize(int(fd))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return w, h
|
||||||
|
}
|
||||||
|
|
||||||
type Packages struct {
|
type Packages struct {
|
||||||
desc string
|
desc string
|
||||||
names []string
|
names []string
|
||||||
|
pad int
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParsePackages(lines []string, desc string) *Packages {
|
func ParsePackages(lines []string, desc string) *Packages {
|
||||||
|
w, _ := terminalSize()
|
||||||
|
maxAcceptable := (w / 4) - 1
|
||||||
|
maxLen := 0
|
||||||
names := make([]string, len(lines))
|
names := make([]string, len(lines))
|
||||||
for i, pkg := range lines {
|
for i, pkg := range lines {
|
||||||
s := strings.SplitN(pkg, "-", 2)
|
s := strings.SplitN(pkg, "-", 2)
|
||||||
if len(s) != 2 {
|
if len(s) != 2 {
|
||||||
log.Fatalf("failed to trim hash path from this line: %s\n ", pkg)
|
log.Fatalf("failed to trim hash path from this line: %s\n ", pkg)
|
||||||
}
|
}
|
||||||
name := strings.Replace(s[1], ".drv", "", 1)
|
name := ellipsis(strings.Replace(s[1], ".drv", "", 1), maxAcceptable)
|
||||||
|
if nameLen := len(name); nameLen > maxLen {
|
||||||
|
maxLen = nameLen
|
||||||
|
}
|
||||||
names[i] = name
|
names[i] = name
|
||||||
}
|
}
|
||||||
sort.Strings(names)
|
sort.Strings(names)
|
||||||
return &Packages{names: names, desc: desc}
|
return &Packages{names: names, pad: maxLen + 1, desc: desc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ellipsis(s string, maxLen int) string {
|
||||||
|
runes := []rune(s)
|
||||||
|
if len(runes) <= maxLen {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
if maxLen < 3 {
|
||||||
|
maxLen = 3
|
||||||
|
}
|
||||||
|
return string(runes[0:maxLen-3]) + "..."
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Packages) Show(verbose bool) {
|
func (p *Packages) Show(verbose bool) {
|
||||||
|
@ -48,8 +81,14 @@ func (p *Packages) Show(verbose bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pkgs := p.names
|
pkgs := p.names
|
||||||
for _, pkg := range pkgs {
|
w, _ := terminalSize()
|
||||||
fmt.Printf(" %s\n", pkg)
|
nCols := w / p.pad
|
||||||
|
fmt.Printf("%s\n", strings.Repeat("-", w))
|
||||||
|
for i, pkg := range pkgs {
|
||||||
|
fmt.Printf("%-*s", p.pad, pkg)
|
||||||
|
if (i+1)%nCols == 0 {
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue