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 307c747 commit 80fe91a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
paths = ['../xx']
6 changes: 4 additions & 2 deletions docs/cli/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,12 @@
"flags": [],
"mounts": [],
"hide": false,
"subcommand_required": true,
"help": "manage/edit pitchfork.toml files",
"help_long": "manage/edit pitchfork.toml files\n\nwithout a subcommand, lists all pitchfork.toml files from the current directory",
"name": "config",
"aliases": [],
"aliases": [
"cfg"
],
"hidden_aliases": [],
"examples": []
},
Expand Down
3 changes: 3 additions & 0 deletions docs/cli/config.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# `pitchfork config`

- **Usage**: `pitchfork config <SUBCOMMAND>`
- **Aliases**: `cfg`

manage/edit pitchfork.toml files

without a subcommand, lists all pitchfork.toml files from the current directory

## Subcommands

- [`pitchfork config add`](/cli/config/add.md)
Expand Down
6 changes: 5 additions & 1 deletion pitchfork.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ cmd "cd" hide=true {
cmd "clean" help="Removes stopped/failed daemons from `pitchfork list`" {
alias "c"
}
cmd "config" subcommand_required=true help="manage/edit pitchfork.toml files" {
cmd "config" help="manage/edit pitchfork.toml files" {
alias "cfg"
long_help r"manage/edit pitchfork.toml files

without a subcommand, lists all pitchfork.toml files from the current directory"
cmd "add" help="Add a new daemon to pitchfork.toml" {
alias "a"
}
Expand Down
19 changes: 15 additions & 4 deletions src/cli/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use crate::pitchfork_toml::PitchforkToml;
use crate::Result;

mod add;
mod remove;

/// manage/edit pitchfork.toml files
///
/// without a subcommand, lists all pitchfork.toml files from the current directory
#[derive(Debug, clap::Args)]
#[clap(visible_alias = "cfg", verbatim_doc_comment)]
pub struct Config {
#[clap(subcommand)]
command: Commands,
command: Option<Commands>,
}

#[derive(Debug, clap::Subcommand)]
Expand All @@ -18,9 +22,16 @@ enum Commands {

impl Config {
pub async fn run(self) -> Result<()> {
match self.command {
Commands::Add(add) => add.run().await,
Commands::Remove(remove) => remove.run().await,
if let Some(cmd) = self.command {
match cmd {
Commands::Add(add) => add.run().await,
Commands::Remove(remove) => remove.run().await,
}
} else {
for p in PitchforkToml::list_paths() {
println!("{}", p.display());
}
Ok(())
}
}
}
1 change: 1 addition & 0 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub use std::env::*;
use std::path::PathBuf;

pub static BIN_PATH: Lazy<PathBuf> = Lazy::new(|| current_exe().unwrap().canonicalize().unwrap());
pub static CWD: Lazy<PathBuf> = Lazy::new(|| current_dir().unwrap_or_default());

pub static HOME_DIR: Lazy<PathBuf> = Lazy::new(|| dirs::home_dir().unwrap_or_default());
pub static PITCHFORK_STATE_DIR: Lazy<PathBuf> = Lazy::new(|| {
Expand Down
8 changes: 7 additions & 1 deletion src/pitchfork_toml.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::daemon::Daemon;
use crate::Result;
use crate::{env, Result};
use indexmap::IndexMap;
use miette::IntoDiagnostic;
use std::path::{Path, PathBuf};
Expand All @@ -11,6 +11,12 @@ pub struct PitchforkToml {
pub path: PathBuf,
}

impl PitchforkToml {
pub fn list_paths() -> Vec<PathBuf> {
xx::file::find_up_all(&env::CWD, &["pitchfork.toml"])
}
}

impl PitchforkToml {
pub fn new(path: PathBuf) -> Self {
Self {
Expand Down

0 comments on commit 80fe91a

Please sign in to comment.