Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 10, 2024
1 parent 969494f commit 95a197b
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 11 deletions.
26 changes: 22 additions & 4 deletions docs/cli/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,18 @@
"full_cmd": [
"disable"
],
"usage": "disable",
"usage": "disable <ID>",
"subcommands": {},
"args": [],
"args": [
{
"name": "ID",
"usage": "<ID>",
"help": "Name of the daemon to disable",
"help_first_line": "Name of the daemon to disable",
"required": true,
"hide": false
}
],
"flags": [],
"mounts": [],
"hide": false,
Expand All @@ -187,9 +196,18 @@
"full_cmd": [
"enable"
],
"usage": "enable",
"usage": "enable <ID>",
"subcommands": {},
"args": [],
"args": [
{
"name": "ID",
"usage": "<ID>",
"help": "Name of the daemon to enable",
"help_first_line": "Name of the daemon to enable",
"required": true,
"hide": false
}
],
"flags": [],
"mounts": [],
"hide": false,
Expand Down
8 changes: 7 additions & 1 deletion docs/cli/disable.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# `pitchfork disable`

- **Usage**: `pitchfork disable`
- **Usage**: `pitchfork disable <ID>`
- **Aliases**: `d`

Prevent a daemon from restarting

## Arguments

### `<ID>`

Name of the daemon to disable
8 changes: 7 additions & 1 deletion docs/cli/enable.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# `pitchfork enable`

- **Usage**: `pitchfork enable`
- **Usage**: `pitchfork enable <ID>`
- **Aliases**: `e`

Allow a daemon to start

## Arguments

### `<ID>`

Name of the daemon to enable
4 changes: 2 additions & 2 deletions docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
- [`pitchfork config add`](/cli/config/add.md)
- [`pitchfork config remove`](/cli/config/remove.md)
- [`pitchfork completion <SHELL>`](/cli/completion.md)
- [`pitchfork disable`](/cli/disable.md)
- [`pitchfork enable`](/cli/enable.md)
- [`pitchfork disable <ID>`](/cli/disable.md)
- [`pitchfork enable <ID>`](/cli/enable.md)
- [`pitchfork list [--hide-header]`](/cli/list.md)
- [`pitchfork logs [-n <N>] [-t --tail] [NAME]...`](/cli/logs.md)
- [`pitchfork run [-f --force] <NAME> [CMD]...`](/cli/run.md)
Expand Down
2 changes: 2 additions & 0 deletions pitchfork.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ cmd "completion" help="Generates shell completion scripts" {
}
cmd "disable" help="Prevent a daemon from restarting" {
alias "d"
arg "<ID>" help="Name of the daemon to disable"
}
cmd "enable" help="Allow a daemon to start" {
alias "e"
arg "<ID>" help="Name of the daemon to enable"
}
cmd "list" help="List all daemons" {
alias "ls"
Expand Down
16 changes: 15 additions & 1 deletion src/cli/disable.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
use crate::state_file::StateFile;
use crate::Result;
use miette::bail;

/// Prevent a daemon from restarting
#[derive(Debug, clap::Args)]
#[clap(visible_alias = "d", verbatim_doc_comment)]
pub struct Disable {}
pub struct Disable {
/// Name of the daemon to disable
id: String,
}

impl Disable {
pub async fn run(&self) -> Result<()> {
let mut sf = StateFile::get().clone();
if self.id == "pitchfork" {
bail!("Cannot disable pitchfork daemon");
}
let disabled = sf.disabled.insert(self.id.clone());
if disabled {
sf.write()?;
println!("disabled {}", self.id);
}
Ok(())
}
}
16 changes: 15 additions & 1 deletion src/cli/enable.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
use crate::state_file::StateFile;
use crate::Result;
use miette::bail;

/// Allow a daemon to start
#[derive(Debug, clap::Args)]
#[clap(visible_alias = "e", verbatim_doc_comment)]
pub struct Enable {}
pub struct Enable {
/// Name of the daemon to enable
id: String,
}

impl Enable {
pub async fn run(&self) -> Result<()> {
let mut sf = StateFile::get().clone();
if self.id == "pitchfork" {
bail!("Cannot disable pitchfork daemon");
}
let enabled = sf.disabled.remove(&self.id);
if enabled {
sf.write()?;
println!("enabled {}", self.id);
}
Ok(())
}
}
4 changes: 3 additions & 1 deletion src/state_file.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::{env, Result};
use miette::IntoDiagnostic;
use once_cell::sync::Lazy;
use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};
use std::fmt::Debug;
use std::path::{Path, PathBuf};

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct StateFile {
pub daemons: BTreeMap<String, StateFileDaemon>,
pub disabled: BTreeSet<String>,
#[serde(skip)]
pub(crate) path: PathBuf,
}
Expand Down Expand Up @@ -43,6 +44,7 @@ impl StateFile {
pub fn new(path: PathBuf) -> Self {
Self {
daemons: Default::default(),
disabled: Default::default(),
path,
}
}
Expand Down

0 comments on commit 95a197b

Please sign in to comment.