-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
364 additions
and
121 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,26 @@ | ||
# `pitchfork config add` | ||
|
||
- **Usage**: `pitchfork config add` | ||
- **Usage**: `pitchfork config add [--autostart] [--autostop] <ID> [ARGS]...` | ||
- **Aliases**: `a` | ||
|
||
Add a new daemon to pitchfork.toml | ||
Add a new daemon to ./pitchfork.toml | ||
|
||
## Arguments | ||
|
||
### `<ID>` | ||
|
||
ID of the daemon to add | ||
|
||
### `[ARGS]...` | ||
|
||
Arguments to pass to the daemon | ||
|
||
## Flags | ||
|
||
### `--autostart` | ||
|
||
Autostart the daemon when entering the directory | ||
|
||
### `--autostop` | ||
|
||
Autostop the daemon when leaving the directory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
# `pitchfork config remove` | ||
|
||
- **Usage**: `pitchfork config remove` | ||
- **Usage**: `pitchfork config remove <ID>` | ||
- **Aliases**: `rm` | ||
|
||
Remove a daemon from pitchfork.toml | ||
|
||
## Arguments | ||
|
||
### `<ID>` | ||
|
||
The ID of the daemon to remove |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,43 @@ | ||
use crate::pitchfork_toml::{PitchforkToml, PitchforkTomlAuto, PitchforkTomlDaemon}; | ||
use crate::Result; | ||
|
||
/// Add a new daemon to pitchfork.toml | ||
/// Add a new daemon to ./pitchfork.toml | ||
#[derive(Debug, clap::Args)] | ||
#[clap(visible_alias = "a", verbatim_doc_comment)] | ||
pub struct Add {} | ||
pub struct Add { | ||
/// ID of the daemon to add | ||
pub id: String, | ||
/// Arguments to pass to the daemon | ||
#[clap(allow_hyphen_values = true, trailing_var_arg = true)] | ||
pub args: Vec<String>, | ||
/// Autostart the daemon when entering the directory | ||
#[clap(long)] | ||
pub autostart: bool, | ||
/// Autostop the daemon when leaving the directory | ||
#[clap(long)] | ||
pub autostop: bool, | ||
} | ||
|
||
impl Add { | ||
pub async fn run(&self) -> Result<()> { | ||
let mut pt = PitchforkToml::read("pitchfork.toml").unwrap_or_default(); | ||
pt.path = pt.path.or(Some("pitchfork.toml".into())); | ||
let mut auto = vec![]; | ||
if self.autostart { | ||
auto.push(PitchforkTomlAuto::Start); | ||
} | ||
if self.autostop { | ||
auto.push(PitchforkTomlAuto::Stop); | ||
} | ||
pt.daemons.insert( | ||
self.id.clone(), | ||
PitchforkTomlDaemon { | ||
run: shell_words::join(&self.args), | ||
auto, | ||
}, | ||
); | ||
pt.write()?; | ||
println!("added {} to {}", self.id, pt.path.unwrap().display()); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
use crate::pitchfork_toml::PitchforkToml; | ||
use crate::Result; | ||
|
||
/// Remove a daemon from pitchfork.toml | ||
#[derive(Debug, clap::Args)] | ||
#[clap(visible_alias = "rm", verbatim_doc_comment)] | ||
pub struct Remove {} | ||
pub struct Remove { | ||
/// The ID of the daemon to remove | ||
id: String, | ||
} | ||
|
||
impl Remove { | ||
pub async fn run(&self) -> Result<()> { | ||
if let Some(path) = PitchforkToml::list_paths().first() { | ||
let mut pt = PitchforkToml::read(path)?; | ||
if pt.daemons.shift_remove(&self.id).is_some() { | ||
pt.write()?; | ||
println!("removed {} from {}", self.id, path.display()); | ||
} else { | ||
warn!("{} not found in {}", self.id, path.display()); | ||
} | ||
} else { | ||
warn!("No pitchfork.toml files found"); | ||
} | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.