138 lines
2.5 KiB
Mathematica
Executable file
138 lines
2.5 KiB
Mathematica
Executable file
#!/usr/bin/env murex
|
|
|
|
config: set proc force-tty true
|
|
config: set proc strict-types true
|
|
|
|
args meat_args %{
|
|
AllowAdditional: true
|
|
Flags: {
|
|
--all: bool
|
|
-a: --all
|
|
}
|
|
}
|
|
|
|
catch {
|
|
err $meat_args.error
|
|
exit 1
|
|
}
|
|
|
|
function meat {
|
|
if { is-null $ENV.FLAKE } {
|
|
meat_print(NO RECIPE FOUND)
|
|
exit
|
|
}
|
|
$pd = $PWD
|
|
cd $ENV.FLAKE
|
|
meat_print "----- MEAT ----------------------------------------" true
|
|
$a = $args[Additional]
|
|
if { $a -> len } then {
|
|
meat_parse_cmd $a
|
|
} else {
|
|
meat_print_help
|
|
}
|
|
meat_print "---------------------------------------------------" true
|
|
cd $pd
|
|
}
|
|
|
|
function meat_print (t: str, !title: bool [false]) {
|
|
if {$title} {
|
|
out (
|
|
$t
|
|
)
|
|
|
|
} else {
|
|
out (
|
|
$t
|
|
)
|
|
}
|
|
}
|
|
|
|
function meat_parse_cmd (args: json) {
|
|
out args $args
|
|
out arglen $args -> count
|
|
out argscast $args -> cast json
|
|
out argscast $args -> cast json -> count
|
|
$cmd = $args[ 0 ]
|
|
out cmd $cmd
|
|
if { ${$args -> len} > 1 } then {
|
|
$opts = ${$args -> ![ 0 ]}
|
|
}
|
|
out opts $opts
|
|
switch $cmd {
|
|
case "yum" {
|
|
meat_print (CONSUMING DELICIOUS MEATS..)
|
|
nh os switch @opts
|
|
}
|
|
case "poke" {
|
|
meat_print (PREPARING SUSPICIOUS MEATS..)
|
|
nh os test @opts
|
|
}
|
|
case "cook" {
|
|
meat_print (PREPARING MEATS..)
|
|
nh os build @opts
|
|
}
|
|
case "fresh" {
|
|
meat_print (PROCESSING FRESH MEATS..)
|
|
meat_do_fresh $opts
|
|
}
|
|
case "look" {
|
|
meat_print (INSPECTING MEAT..)
|
|
nix flake info @opts
|
|
}
|
|
case "gut" {
|
|
meat_print (CLEANING MEAT STORES..)
|
|
nh clean all @opts
|
|
}
|
|
default { meat_print_help }
|
|
}
|
|
}
|
|
|
|
function meat_print_help {
|
|
out ( FRESH - HUNT LATEST MEATS
|
|
..N - HUNT LATEST SUBMEATS OF N
|
|
..-A - HUNT ALL SUBMEATS
|
|
YUM - CONSUME DELICIOUS MEATS
|
|
COOK - ONLY PREPARE MEATS
|
|
POKE - TASTE SUSPICIOUS MEATS
|
|
GUT - CLEAN MEAT STORES
|
|
LOOK - INSPECT MEAT)
|
|
}
|
|
|
|
function meat_do_fresh (!opts: str) {
|
|
# handle --all flag
|
|
if { $GLOBAL.args.flags.all } then {
|
|
recursive_update $ENV.FLAKE/flakes
|
|
cd $ENV.FLAKE
|
|
nix flake update
|
|
}
|
|
if { $opts } then {
|
|
# handle specified subflakes
|
|
$opts -> foreach subflake {
|
|
meat_print "GET NEW MEAT FOR $(subflake).."
|
|
recursive_update $ENV.FLAKE/flakes/$subflake
|
|
cd $ENV.FLAKE
|
|
nix flake update $subflake
|
|
}
|
|
}
|
|
# simple update
|
|
nix flake update
|
|
}
|
|
|
|
function recursive_update (path: str) {
|
|
if { $path.Exists } {
|
|
cd $path
|
|
# update subflakes
|
|
g */flake.nix -> foreach dir { recursive_update $dir }
|
|
# update this flake
|
|
$isflake = ${g flake.nix -> count} > 0
|
|
if { $isflake } then {
|
|
nix flake update
|
|
}
|
|
} else {
|
|
err "No such subflake at $path"
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
$GLOBAL.args = $meat_args
|
|
meat
|