refactor: Rename sydnix → sydnix-cli

This commit is contained in:
Madeleine Sydney
2025-01-14 20:24:07 -07:00
parent 29fd94f9e2
commit 0e9bad81ee
20 changed files with 55 additions and 57 deletions

View File

@@ -0,0 +1,151 @@
{
"lock-version": 4,
"git-deps": [],
"mvn-deps": [
{
"mvn-path": "org/clojure/clojure/1.10.3/clojure-1.10.3.jar",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-fxJHLa7Y9rUXSYqqKrE6ViR1w+31FHjkWBzHYemJeaM="
},
{
"mvn-path": "org/clojure/clojure/1.10.3/clojure-1.10.3.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-GJwAxDNAdJai+7DsyzeQjJSVXZHq0b5IFWdE7MGBbZQ="
},
{
"mvn-path": "org/clojure/clojure/1.11.0/clojure-1.11.0.jar",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-PiH6daB+yd278bK1A1bPGAcQ0DmN6qT0TpHNYwRVWUc="
},
{
"mvn-path": "org/clojure/clojure/1.11.0/clojure-1.11.0.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-SQjMS0yeYsmoFJb5PLWsb2lBd8xkXc87jOXkkavOHro="
},
{
"mvn-path": "org/clojure/clojure/1.11.1/clojure-1.11.1.jar",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-I4G26UI6tGUVFFWUSQPROlYkPWAGuRlK/Bv0+HEMtN4="
},
{
"mvn-path": "org/clojure/clojure/1.11.1/clojure-1.11.1.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-IMRaGr7b2L4grvk2BQrjGgjBZ0CzL4dAuIOM3pb/y4o="
},
{
"mvn-path": "org/clojure/clojure/1.11.2/clojure-1.11.2.jar",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-iPqZkT1pIs+39kn1xGdQOHfLb8yMwW02948mSAhLqZc="
},
{
"mvn-path": "org/clojure/clojure/1.11.2/clojure-1.11.2.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-FzbP/xCV4dT+/raogrut9ttB7+MV8pbw/aMtt//EExE="
},
{
"mvn-path": "org/clojure/clojure/1.11.3/clojure-1.11.3.jar",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-nDBUCTKOK5boXdK160t1gQxnt2unCuTQ9t3pvPtVsbc="
},
{
"mvn-path": "org/clojure/clojure/1.11.3/clojure-1.11.3.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-DA2+Ge4NKpxXMQzr3dNWRD8NFlFMQmBHsGLjpXwNuK0="
},
{
"mvn-path": "org/clojure/clojure/1.11.4/clojure-1.11.4.jar",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-/H/xtmENDjSUp1zBHvgYEL2kAqwVcBL+TjuJlYbPQTM="
},
{
"mvn-path": "org/clojure/clojure/1.11.4/clojure-1.11.4.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-a6YADmhI+Cw5y5tJqyqmo6Vi9MJNUrMeUZCuZJXwwwk="
},
{
"mvn-path": "org/clojure/clojure/1.12.0/clojure-1.12.0.jar",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-xFMzAGRBoFnqn9sTQfxsH0C5IaENzNgmZTEeSKA4R2M="
},
{
"mvn-path": "org/clojure/clojure/1.12.0/clojure-1.12.0.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-KfRiqonLl2RXWEGKXwjUwagrc1yW569JgX0WqpuQgVA="
},
{
"mvn-path": "org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-/PRCveArBKhj8vzFjuaiowxM8Mlw99q4VjTwq3ERZrY="
},
{
"mvn-path": "org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-AarxdIP/HHSCySoHKV1+e8bjszIt9EsptXONAg/wB0A="
},
{
"mvn-path": "org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.jar",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-Bu6owHC75FwVhWfkQ0OWgbyMRukSNBT4G/oyukLWy8g="
},
{
"mvn-path": "org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-F3i70Ti9GFkLgFS+nZGdG+toCfhbduXGKFtn1Ad9MA4="
},
{
"mvn-path": "org/clojure/core.specs.alpha/0.4.74/core.specs.alpha-0.4.74.jar",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-63OsCM9JuoQMiLpnvu8RM2ylVDM9lAiAjXiUbg/rnds="
},
{
"mvn-path": "org/clojure/core.specs.alpha/0.4.74/core.specs.alpha-0.4.74.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-M0EOuKpz1S2Vez3G4KZfOZisBiPL2BPZDDPm5onEJCk="
},
{
"mvn-path": "org/clojure/pom.contrib/0.3.0/pom.contrib-0.3.0.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-fxgrOypUPgV0YL+T/8XpzvasUn3xoTdqfZki6+ee8Rk="
},
{
"mvn-path": "org/clojure/pom.contrib/1.1.0/pom.contrib-1.1.0.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-EOzku1+YKQENwWVh9C67g7ry9HYFtR+RBbkvPKoIlxU="
},
{
"mvn-path": "org/clojure/pom.contrib/1.2.0/pom.contrib-1.2.0.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-CRbXpBVYuVAKQnyIb6KYJ6zlJZIGvjrTPmTilvwaYRE="
},
{
"mvn-path": "org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-z2iZ+YUpjGSxPqEplGrZAo3uja3w6rmuGORVAn04JJw="
},
{
"mvn-path": "org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-WhHw4eizwFLmUcSYxpRbRNs1Nb8sGHGf3PZd8fiLE+Y="
},
{
"mvn-path": "org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-Z+yJjrVcZqlXpVJ53YXRN2u5lL2HZosrDeHrO5foquA="
},
{
"mvn-path": "org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-bY3hTDrIdXYMX/kJVi/5hzB3AxxquTnxyxOeFp/pB1g="
},
{
"mvn-path": "org/clojure/spec.alpha/0.5.238/spec.alpha-0.5.238.jar",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-lM2ZtupjlkHzevSGCmQ7btOZ7lqL5dcXz/C2Y8jXUHc="
},
{
"mvn-path": "org/clojure/spec.alpha/0.5.238/spec.alpha-0.5.238.pom",
"mvn-repo": "https://repo.maven.apache.org/maven2/",
"hash": "sha256-PLp+DcwIXEzpLd3/6iJhJP+sF4vnm9A3m1suMKlpy+o="
}
]
}

View File

@@ -0,0 +1,43 @@
(ns sydnix-cli.commands.help
(:require
[babashka.process :as p]
[sydnix-cli.mangen :as mangen]))
(defn adorn-with-help-option [wrapped-command-fn]
(fn [{:keys [opts dispatch]}]
(if (:help opts)
(mangen/with-pipe
(fn [man->]
(mangen/write-man-for-command (mangen/find-dispatched dispatch)
:out man->))
(fn [->man]
(p/shell {:in ->man}
"man -l -")))
(wrapped-command-fn opts))))
(defn- view-man-for-command [command-spec]
(mangen/with-pipe
(fn [man->]
(mangen/write-man-for-command command-spec :out man->))
(fn [->man]
(p/shell {:in ->man} "man -l -"))))
(defn- wrap-command-fn [wrapped-fn]
(fn [info]
(if (:help (:opts info))
(do (mangen/render-docs-for-command
(mangen/find-dispatched (:dispatch info)))
#_
(view-man-for-command (mangen/find-dispatched (:dispatch info))))
(when-not (nil? wrapped-fn)
(wrapped-fn info)))))
(defn adorn-with-help-option* [command-spec]
(update command-spec :fn wrap-command-fn))
(defn- command-fn [_opts]
(view-man-for-command (mangen/find-dispatched [])))
(def command
{:cmds ["help"]
:fn command-fn})

View File

@@ -0,0 +1,25 @@
(ns sydnix-cli.commands.rebuild
(:require
[clojure.java.shell :refer [sh]]
[sydnix-cli.commands.help :refer [adorn-with-help-option*]]))
(def command-options-spec
{:flake {:coerce :string
:ref "URI"
:desc "URI is a path to a Flake, which is passed to `nixos-rebuild
--flake URI` as is."
:default "path:///persist/dots"}})
(defn- command-fn [{:keys [args opts]}]
(let [rebuild-cmd
(concat ["sudo" "nixos-rebuild"]
(or args ["switch"])
["--flake" (:flake opts)])]
(apply println "$" rebuild-cmd)
(apply sh rebuild-cmd)))
(def commands
[{:cmds ["rebuild"]
:desc "Rebuild the system NixOS and Home-manager configuration"
:fn command-fn
:spec command-options-spec}])

View File

@@ -0,0 +1,11 @@
(ns sydnix-cli.commands.status
(:require
[sydnix-cli.commands.help :refer [adorn-with-help-option*]]))
(defn- command-fn [opts]
(prn opts))
(def commands
[{:cmds ["status"]
:desc "View system info"
:fn command-fn}])

View File

@@ -0,0 +1,8 @@
(ns sydnix-cli.commands.util
(:require
[sydnix-cli.commands.util.mangen :as cmd-util-mangen]))
(def commands
[{:cmds ["util"]
:desc "Infrequently-used utilities such as docgen and shell completions."}
cmd-util-mangen/command])

View File

@@ -0,0 +1,46 @@
(ns sydnix-cli.commands.util.mangen
(:require
[asciidoc.render]
[babashka.fs :as fs]
[babashka.process :as p]
[clojure.java.io :as io]
[clojure.spec.alpha :as s]
[clojure.string :as str]
[sydnix-cli.mangen :as mangen]
[sydnix-cli.cli-table :refer [*cli-table]]
[sydnix-cli.commands.help :refer [adorn-with-help-option*]]
[sydnix-cli.prelude :as prelude]))
(defn command-fn [{:keys [yes output-directory]}]
(if (or yes
(prelude/y-or-n? (format "Write a bunch of man pages to %s?"
output-directory)))
(doseq [cmd-spec (deref *cli-table)]
(let [man-file-name (fs/file
output-directory
(str (str/join "-" (cons "sydnix" (:cmds cmd-spec)))
".1"))]
(with-open [man-file (io/writer man-file-name)]
(mangen/write-man-for-command cmd-spec :out man-file))
(printf "wrote %s\n" man-file-name)
(flush)))
(System/exit 1)))
(def command-options-spec
{:output-directory {:coerce :string
:ref "DIRECTORY"
:alias :o
:desc "Directory to which the generated man pages will be
written."
:require true
:validate fs/directory?}
:yes {:coerce :bool
:desc "Don't ask for confirmation."
:default false}})
(def command
(adorn-with-help-option*
{:cmds ["util" "mangen"]
:desc "Generate man pages for each subcommand of `sydnix`."
:fn command-fn
:spec command-options-spec}))