diff --git a/gritty-clap/src/auth.rs b/gritty-clap/src/auth.rs new file mode 100644 index 0000000..311f372 --- /dev/null +++ b/gritty-clap/src/auth.rs @@ -0,0 +1,8 @@ +use clap::Parser; + +#[derive(Debug, Clone, Parser)] +#[command(about = "Authenticate with a remote")] +pub struct Auth { + #[arg(help = "Name of the remote as defined in the config (ex: 'github')")] + pub remote: String, +} diff --git a/gritty-clap/src/clone.rs b/gritty-clap/src/clone.rs new file mode 100644 index 0000000..a77282c --- /dev/null +++ b/gritty-clap/src/clone.rs @@ -0,0 +1,13 @@ +use clap::Parser; + +#[derive(Debug, Clone, Parser)] +#[command(about = "Clone a repository from a remote")] +pub struct Clone { + #[arg(help = "Name of the repository")] + pub name: String, + #[arg(help = "Name of the remote as defined in the config (ex: 'github')")] + pub remote: String, + #[arg(short, long, help = "Initialize and clone all submodules")] + pub recursive: bool, +} + diff --git a/gritty-clap/src/create.rs b/gritty-clap/src/create.rs new file mode 100644 index 0000000..a06ef6e --- /dev/null +++ b/gritty-clap/src/create.rs @@ -0,0 +1,54 @@ +use clap::Parser; + +use super::OutputFormat; + +#[derive(Debug, Clone, Parser)] +#[command(about = "Create a repository on a remote")] +pub struct Create { + #[arg(short, long, help = "Create a private repository")] + pub private: bool, + #[arg(short, long, help = "Clone the repository after creation")] + pub clone: bool, + #[arg( + short, + long, + help = "Initialize and clone all submodules. Only valid with --clone" + )] + pub recursive: bool, + #[arg( + short, + long, + help = "Add the remote to the local git repository as 'origin'. Ignored if --clone is specified", + long_help = "Add the remote to the local git repository as 'origin'. +If the current directory is not a git repository, it will be initialized as one. +Ignored if --clone is specified. +" + )] + pub add_remote: bool, + #[arg(short, long, help = "Description of the repository")] + pub description: Option, + #[arg(short, long, help = "Initialize the repository with a README.md")] + pub init: bool, + #[arg( + short, + long, + help = concat!("License to use for the repository (ex: 'MIT'). ", + "If not provided, or --init is not specified, no license will be addeed.") + )] + pub license: Option, + #[arg(help = "Name of the repository")] + pub name: String, + #[arg(help = "Name of the remote as defined in the config (ex: 'github')")] + pub remote: String, + #[arg( + long, + help = "Change the output format to the specified value (can be 'json')", + long_help = "\ +Change the output format to the specified value. +This option is useful for parsing the output of gritty, such as in a script or another +tool integrating with gritty. +Note that the 'create-config' and 'auth' subcommands do not respect this option. +Currently, the only supported format is 'json'." + )] + pub format: Option, +} diff --git a/gritty-clap/src/delete.rs b/gritty-clap/src/delete.rs new file mode 100644 index 0000000..7eb2d4a --- /dev/null +++ b/gritty-clap/src/delete.rs @@ -0,0 +1,16 @@ +use clap::Parser; + +#[derive(Debug, Clone, Parser)] +#[command(about = "Delete a repository on a remote")] +pub struct Delete { + #[arg(help = "Name of the repository")] + pub name: String, + #[arg(help = "Name of the remote as defined in the config (ex: 'github')")] + pub remote: String, + #[arg( + short, + long, + help = "Force deletion without confirmation. Use with caution!" + )] + pub force: bool, +} diff --git a/gritty-clap/src/lib.rs b/gritty-clap/src/lib.rs index f32f938..59bb629 100644 --- a/gritty-clap/src/lib.rs +++ b/gritty-clap/src/lib.rs @@ -1,5 +1,17 @@ use std::env; +mod auth; +mod clone; +mod create; +mod delete; +mod list; + +pub use auth::Auth; +pub use clone::Clone; +pub use create::Create; +pub use delete::Delete; +pub use list::List; + use clap::{ builder::styling::{AnsiColor, Effects, Styles}, Parser, Subcommand, ValueEnum, @@ -68,107 +80,3 @@ pub enum Commands { #[command(about = "List all configured remotes")] ListRemotes, } - -#[derive(Debug, Clone, Parser)] -#[command(about = "Clone a repository from a remote")] -pub struct Clone { - #[arg(help = "Name of the repository")] - pub name: String, - #[arg(help = "Name of the remote as defined in the config (ex: 'github')")] - pub remote: String, - #[arg(short, long, help = "Initialize and clone all submodules")] - pub recursive: bool, -} - -#[derive(Debug, Clone, Parser)] -#[command(about = "List repositories on a remote")] -pub struct List { - #[arg(help = "Name of the remote as defined in the config (ex: 'github')")] - pub remote: String, - #[arg(short, long, help = "Show private repositories")] - pub private: bool, - #[arg(short, long, help = "Show forks")] - pub forks: bool, - #[arg( - long, - help = "Change the output format to the specified value (can be 'json')", - long_help = "\ -Change the output format to the specified value. -This option is useful for parsing the output of gritty, such as in a script or another -tool integrating with gritty. -Note that the 'create-config' and 'auth' subcommands do not respect this option. -Currently, the only supported format is 'json'." - )] - pub format: Option, -} - -#[derive(Debug, Clone, Parser)] -#[command(about = "Create a repository on a remote")] -pub struct Create { - #[arg(short, long, help = "Create a private repository")] - pub private: bool, - #[arg(short, long, help = "Clone the repository after creation")] - pub clone: bool, - #[arg( - short, - long, - help = "Initialize and clone all submodules. Only valid with --clone" - )] - pub recursive: bool, - #[arg( - short, - long, - help = "Add the remote to the local git repository as 'origin'. Ignored if --clone is specified", - long_help = "Add the remote to the local git repository as 'origin'. -If the current directory is not a git repository, it will be initialized as one. -Ignored if --clone is specified. -" - )] - pub add_remote: bool, - #[arg(short, long, help = "Description of the repository")] - pub description: Option, - #[arg(short, long, help = "Initialize the repository with a README.md")] - pub init: bool, - #[arg( - short, - long, - help = concat!("License to use for the repository (ex: 'MIT'). ", - "If not provided, or --init is not specified, no license will be addeed.") - )] - pub license: Option, - #[arg(help = "Name of the repository")] - pub name: String, - #[arg(help = "Name of the remote as defined in the config (ex: 'github')")] - pub remote: String, - #[arg( - long, - help = "Change the output format to the specified value (can be 'json')", - long_help = "\ -Change the output format to the specified value. -This option is useful for parsing the output of gritty, such as in a script or another -tool integrating with gritty. -Note that the 'create-config' and 'auth' subcommands do not respect this option. -Currently, the only supported format is 'json'." - )] - pub format: Option, -} -#[derive(Debug, Clone, Parser)] -#[command(about = "Delete a repository on a remote")] -pub struct Delete { - #[arg(help = "Name of the repository")] - pub name: String, - #[arg(help = "Name of the remote as defined in the config (ex: 'github')")] - pub remote: String, - #[arg( - short, - long, - help = "Force deletion without confirmation. Use with caution!" - )] - pub force: bool, -} -#[derive(Debug, Clone, Parser)] -#[command(about = "Authenticate with a remote")] -pub struct Auth { - #[arg(help = "Name of the remote as defined in the config (ex: 'github')")] - pub remote: String, -} diff --git a/gritty-clap/src/list.rs b/gritty-clap/src/list.rs new file mode 100644 index 0000000..0db632b --- /dev/null +++ b/gritty-clap/src/list.rs @@ -0,0 +1,26 @@ +use clap::Parser; + +use super::OutputFormat; + +#[derive(Debug, Clone, Parser)] +#[command(about = "List repositories on a remote")] +pub struct List { + #[arg(help = "Name of the remote as defined in the config (ex: 'github')")] + pub remote: String, + #[arg(short, long, help = "Show private repositories")] + pub private: bool, + #[arg(short, long, help = "Show forks")] + pub forks: bool, + #[arg( + long, + help = "Change the output format to the specified value (can be 'json')", + long_help = "\ +Change the output format to the specified value. +This option is useful for parsing the output of gritty, such as in a script or another +tool integrating with gritty. +Note that the 'create-config' and 'auth' subcommands do not respect this option. +Currently, the only supported format is 'json'." + )] + pub format: Option, +} +