Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 12, 2024
1 parent c736444 commit de1f5e5
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 45 deletions.
2 changes: 2 additions & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 15 additions & 1 deletion docs/cli/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@
"full_cmd": [
"start"
],
"usage": "start [-f --force] [ID]...",
"usage": "start [-a --all] [-f --force] [ID]...",
"subcommands": {},
"args": [
{
Expand All @@ -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 <SHELL_PID>",
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- [`pitchfork list [--hide-header]`](/cli/list.md)
- [`pitchfork logs [FLAGS] [ID]...`](/cli/logs.md)
- [`pitchfork run [-f --force] <ID> [RUN]...`](/cli/run.md)
- [`pitchfork start [-f --force] [ID]...`](/cli/start.md)
- [`pitchfork start [-a --all] [-f --force] [ID]...`](/cli/start.md)
- [`pitchfork status <ID>`](/cli/status.md)
- [`pitchfork stop [ID]...`](/cli/stop.md)
- [`pitchfork supervisor <SUBCOMMAND>`](/cli/supervisor.md)
Expand Down
6 changes: 5 additions & 1 deletion docs/cli/start.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
58 changes: 18 additions & 40 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Pitchfork
# Pitchfork

Pitchfork is a CLI for launching daemons with a focus on developer experience.

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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`.
Expand All @@ -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

Expand All @@ -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"]
```
27 changes: 27 additions & 0 deletions docs/mise.md
Original file line number Diff line number Diff line change
@@ -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"]
```
1 change: 1 addition & 0 deletions pitchfork.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<SHELL_PID>"
}
Expand Down
12 changes: 10 additions & 2 deletions src/cli/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use std::collections::HashSet;
pub struct Start {
/// ID of the daemon(s) in pitchfork.toml to start
id: Vec<String>,
/// Start all daemons in all pitchfork.tomls
#[clap(long, short)]
all: bool,
#[clap(long, hide = true)]
shell_pid: Option<u32>,
/// Stop the daemon if it is already running
Expand All @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit de1f5e5

Please sign in to comment.