refactor: Move each command spec into its own file
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
(:require
|
||||
[clojure.pprint :refer [pprint]]
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as str]
|
||||
[clojure.zip :as zip]
|
||||
[spec-dict :refer [dict dict*]]))
|
||||
[spec-dict :refer [dict]]
|
||||
[sydnix.cli-table :refer [*cli-table*]]))
|
||||
|
||||
(s/def ::block-context
|
||||
#{:document :section :paragraph})
|
||||
@@ -118,12 +120,18 @@
|
||||
|
||||
|
||||
|
||||
(defn docs-for-command [command])
|
||||
(defn- docs-for-command [command])
|
||||
|
||||
(defn command [opts]
|
||||
(defn- command-fn [opts]
|
||||
(prn "help" opts))
|
||||
|
||||
(defn adorn-with-help-option [command-fn]
|
||||
(fn [opts]
|
||||
(prn "adorned help" opts)
|
||||
(command-fn opts)))
|
||||
(fn [{:keys [opts dispatch]}]
|
||||
(if (:help opts)
|
||||
(do (printf "<help for %s>\n" (str/join " " dispatch))
|
||||
(pprint *cli-table*))
|
||||
(command-fn opts))))
|
||||
|
||||
(def command
|
||||
{:cmds ["help"]
|
||||
:fn command-fn})
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
(ns sydnix.commands.rebuild
|
||||
(:require
|
||||
[clojure.java.shell :refer [sh]]))
|
||||
[clojure.java.shell :refer [sh]]
|
||||
[sydnix.commands.help :refer [adorn-with-help-option]]))
|
||||
|
||||
(defn command [{:keys [args opts]}]
|
||||
(let [command
|
||||
(defn- command-fn [{:keys [args opts]}]
|
||||
(let [rebuild-cmd
|
||||
(concat ["sudo" "nixos-rebuild"]
|
||||
(or args ["switch"])
|
||||
["--flake" (:flake opts)])]
|
||||
(apply println "$" command)
|
||||
(apply sh command)))
|
||||
(apply println "$" rebuild-cmd)
|
||||
(apply sh rebuild-cmd)))
|
||||
|
||||
(def command
|
||||
{:cmds ["rebuild"]
|
||||
:desc "Rebuild the system NixOS and Home-manager configuration"
|
||||
:fn (adorn-with-help-option command-fn)
|
||||
:spec {:flake {:coerce :string
|
||||
:default "path:///persist/dots"}}})
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
(ns sydnix.commands.status)
|
||||
(ns sydnix.commands.status
|
||||
(:require
|
||||
[sydnix.commands.help :refer [adorn-with-help-option]]))
|
||||
|
||||
(defn command [opts]
|
||||
(defn- command-fn [opts]
|
||||
(prn opts))
|
||||
|
||||
(def command
|
||||
{:cmds ["status"]
|
||||
:desc "View system info"
|
||||
:fn (adorn-with-help-option command-fn)})
|
||||
|
||||
@@ -7,27 +7,12 @@
|
||||
[sydnix.commands.rebuild :as cmd-rebuild])
|
||||
(:gen-class))
|
||||
|
||||
(def cmd-status-spec
|
||||
{})
|
||||
|
||||
(def with-help cmd-help/adorn-with-help-option)
|
||||
|
||||
(def cmd-rebuild-spec
|
||||
{:flake {:coerce :string
|
||||
:default "path:///persist/dots"}})
|
||||
|
||||
(def cli-table
|
||||
[{:cmds ["status"]
|
||||
:desc "View system info"
|
||||
:fn (with-help cmd-status/command)}
|
||||
{:cmds ["rebuild"]
|
||||
:desc "Rebuild the system NixOS and Home-manager configuration"
|
||||
:fn (with-help cmd-rebuild/command)
|
||||
:spec cmd-rebuild-spec}
|
||||
{:cmds ["help"]
|
||||
:fn cmd-help/command}
|
||||
{:cmds []
|
||||
:fn cmd-help/command}])
|
||||
[cmd-status/command
|
||||
cmd-rebuild/command
|
||||
cmd-help/command
|
||||
;; Show help when no other command matches.
|
||||
(assoc cmd-help/command :cmds [])])
|
||||
|
||||
(defn -main [& args]
|
||||
(binding [*cli-table* cli-table]
|
||||
|
||||
Reference in New Issue
Block a user