diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 0527e66..b8d7a0e 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -22,11 +22,13 @@ export default defineConfig({ // https://vitepress.dev/reference/default-theme-config nav: [ { text: "Home", link: "/" }, + { text: "Getting Started", link: "/getting-started" }, { text: "CLI Reference", link: "/cli" }, ], sidebar: [ { text: "Getting Started", link: "/getting-started" }, + { text: "Integration with mise", link: "/mise" }, { text: "CLI Reference", link: "/cli", diff --git a/docs/cli/commands.json b/docs/cli/commands.json index 0def701..0fedd2f 100644 --- a/docs/cli/commands.json +++ b/docs/cli/commands.json @@ -429,7 +429,7 @@ "full_cmd": [ "start" ], - "usage": "start [-f --force] [ID]...", + "usage": "start [-a --all] [-f --force] [ID]...", "subcommands": {}, "args": [ { @@ -443,6 +443,20 @@ } ], "flags": [ + { + "name": "all", + "usage": "-a --all", + "help": "Start all daemons in all pitchfork.tomls", + "help_first_line": "Start all daemons in all pitchfork.tomls", + "short": [ + "a" + ], + "long": [ + "all" + ], + "hide": false, + "global": false + }, { "name": "shell-pid", "usage": "--shell-pid ", diff --git a/docs/cli/index.md b/docs/cli/index.md index 123edd5..b043698 100644 --- a/docs/cli/index.md +++ b/docs/cli/index.md @@ -17,7 +17,7 @@ - [`pitchfork list [--hide-header]`](/cli/list.md) - [`pitchfork logs [FLAGS] [ID]...`](/cli/logs.md) - [`pitchfork run [-f --force] [RUN]...`](/cli/run.md) -- [`pitchfork start [-f --force] [ID]...`](/cli/start.md) +- [`pitchfork start [-a --all] [-f --force] [ID]...`](/cli/start.md) - [`pitchfork status `](/cli/status.md) - [`pitchfork stop [ID]...`](/cli/stop.md) - [`pitchfork supervisor `](/cli/supervisor.md) diff --git a/docs/cli/start.md b/docs/cli/start.md index 1270040..073cf04 100644 --- a/docs/cli/start.md +++ b/docs/cli/start.md @@ -1,6 +1,6 @@ # `pitchfork start` -- **Usage**: `pitchfork start [-f --force] [ID]...` +- **Usage**: `pitchfork start [-a --all] [-f --force] [ID]...` - **Aliases**: `s` Starts a daemon from a pitchfork.toml file @@ -13,6 +13,10 @@ ID of the daemon(s) in pitchfork.toml to start ## Flags +### `-a --all` + +Start all daemons in all pitchfork.tomls + ### `-f --force` Stop the daemon if it is already running diff --git a/docs/getting-started.md b/docs/getting-started.md index a42492d..c1c59e3 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -1,4 +1,4 @@ -## Pitchfork +# Pitchfork Pitchfork is a CLI for launching daemons with a focus on developer experience. @@ -13,10 +13,10 @@ Pitchfork is a CLI for launching daemons with a focus on developer experience. ## Features -- [coming soon] automatically start daemons on boot - only starting daemons if they have not already been started -- [coming soon] restarting daemons on failure - starting daemons only when working in a project directory—then automatically stopping when you leave +- [coming soon] automatically start daemons on boot +- [coming soon] restarting daemons on failure ## Workflows @@ -28,7 +28,7 @@ This workflow is an alternative to something like shell jobs—`mytask &`. This the background: ```bash -pitchfork run docs "npm start docs-dev-server" +pitchfork run docs -- npm start docs-dev-server ``` You need to label the daemon with a name, in this case "docs". Once it's started, "docs" will be how @@ -37,17 +37,19 @@ is still running—this way you can start one-off daemons without thinking if yo On `pitchfork run`, pitchfork will emit the output of `npm start docs-dev-server` for a few seconds. If it fails during that time, it will exit non-zero to help you see if the daemon was configured/setup -correctly. +correctly. -- TODO this needs to be implemented ### Adding a daemon to a project A project may have several daemons defined, this is configured in `pitchfork.toml` in the root of the project: ```toml -[daemons] -redis = "redis-server" -api = "npm run server:api" -docs = "npm run server:docs" +[daemons.redis] +run = "redis-server" +[daemons.api] +run = "npm run server:api" +[daemons.docs] +run = "npm run server:docs" ``` You can start all the daemons with `pitchfork start --all` or individual ones with their name, e.g.: `pitchfork start redis`. @@ -56,7 +58,7 @@ You can also have pitchfork automatically start the daemons when entering the pr ### Adding a global daemon that runs on boot -TODO +TODO - implement this ## Shell hook @@ -73,39 +75,15 @@ echo 'pitchfork activate fish | source' >> ~/.config/fish/config.fish Then when you restart your shell pitchfork will automatically start "autostart" daemons when entering the directory. daemons with "autostop" will stop daemons when leaving the directory after a bit of a delay if no terminal sessions are still inside the directory. +:::tip +You can also have daemons only autostop. You can manually start them with `pitchfork start` then they +will be stopped when you leave the directory. +::: + Here's a `pitchfork.toml` with this configured: ```toml [daemons.api] run = "npm run server:api" -autostart = true -autostop = true -``` - -## Integration with mise - -[mise](https://mise.jdx.dev) is a project for installing/managing dev tools, managing environment variables, -and running tasks. Unlike pitchfork, [mise tasks](https://mise.jdx.dev/tasks/) do not run in the background however -they offer a lot of functionality you won't find in pitchfork. It's encouraged to define relatively simple daemons -that just call `mise run` to launch the daemon as a mise task. - -To do so, put the following into `pitchfork.toml`: - -```toml -[daemons.docs] -run = "mise run docs:dev" -``` - -And in `mise.toml` you can define how `mise run docs:dev` gets setup and behaves: - -```toml -[env] -NODE_ENV = "development" -[tools] -node = "20" -[tasks."docs:setup"] -run = "npm install" -[tasks."docs:dev"] -run = "node docs/index.js" -depends = ["docs:setup"] +auto = ["start", "stop"] ``` diff --git a/docs/mise.md b/docs/mise.md new file mode 100644 index 0000000..2f61ed0 --- /dev/null +++ b/docs/mise.md @@ -0,0 +1,27 @@ +# Integrating pitchfork with mise + +[mise](https://mise.jdx.dev) is a project for installing/managing dev tools, managing environment variables, +and running tasks. Unlike pitchfork, [mise tasks](https://mise.jdx.dev/tasks/) do not run in the background however +they offer a lot of functionality you won't find in pitchfork. It's encouraged to define relatively simple daemons +that just call `mise run` to launch the daemon as a mise task. + +To do so, put the following into `pitchfork.toml`: + +```toml +[daemons.docs] +run = "mise run docs:dev" +``` + +And in `mise.toml` you can define how `mise run docs:dev` gets setup and behaves: + +```toml +[env] +NODE_ENV = "development" +[tools] +node = "20" +[tasks."docs:setup"] +run = "npm install" +[tasks."docs:dev"] +run = "node docs/index.js" +depends = ["docs:setup"] +``` diff --git a/pitchfork.usage.kdl b/pitchfork.usage.kdl index a27235a..4847e9b 100644 --- a/pitchfork.usage.kdl +++ b/pitchfork.usage.kdl @@ -65,6 +65,7 @@ cmd "run" help="Runs a one-off daemon" { } cmd "start" help="Starts a daemon from a pitchfork.toml file" { alias "s" + flag "-a --all" help="Start all daemons in all pitchfork.tomls" flag "--shell-pid" hide=true { arg "" } diff --git a/src/cli/start.rs b/src/cli/start.rs index 8259895..50e73c8 100644 --- a/src/cli/start.rs +++ b/src/cli/start.rs @@ -11,6 +11,9 @@ use std::collections::HashSet; pub struct Start { /// ID of the daemon(s) in pitchfork.toml to start id: Vec, + /// Start all daemons in all pitchfork.tomls + #[clap(long, short)] + all: bool, #[clap(long, hide = true)] shell_pid: Option, /// Stop the daemon if it is already running @@ -21,7 +24,7 @@ pub struct Start { impl Start { pub async fn run(&self) -> Result<()> { ensure!( - !self.id.is_empty(), + self.all || !self.id.is_empty(), "At least one daemon ID must be provided" ); let pt = PitchforkToml::all_merged(); @@ -33,7 +36,12 @@ impl Start { .into_iter() .map(|d| d.id) .collect(); - for id in &self.id { + let ids = if self.all { + pt.daemons.keys().cloned().collect() + } else { + self.id.clone() + }; + for id in &ids { if disabled_daemons.contains(id) { warn!("Daemon {} is disabled", id); continue;