Skip to content

Commit

Permalink
feat!: nested "remote" subcommand
Browse files Browse the repository at this point in the history
Move `gritty list-remotes` into `gritty remote list` to allow grouping
common remote operations - like adding, deleting and configuring remotes
in the future.

BREAKING CHANGE: `gritty list-remotes` is now `gritty remote list`
  • Loading branch information
benpueschel committed Aug 14, 2024
1 parent b1ac66a commit 2e4b717
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
5 changes: 3 additions & 2 deletions gritty-clap/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::env;

pub mod remote;
pub mod repo;
pub mod auth;

use repo::Repo;
use auth::Auth;
use remote::Remote;

use clap::{
builder::styling::{AnsiColor, Effects, Styles},
Expand Down Expand Up @@ -68,9 +70,8 @@ pub enum OutputFormat {
pub enum Commands {
Auth(Auth),
Repo(Repo),
Remote(Remote),

#[command(about = "Interactively configure gritty")]
CreateConfig,
#[command(about = "List all configured remotes")]
ListRemotes,
}
13 changes: 13 additions & 0 deletions gritty-clap/src/remote/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use clap::{Parser, Subcommand};

#[derive(Debug, Clone, Parser)]
#[command(about = "Remote operations")]
pub struct Remote {
#[command(subcommand)]
pub subcommand: RemoteCommands,
}
#[derive(Debug, Clone, Subcommand)]
pub enum RemoteCommands {
#[command(about = "List all configured remotes")]
List,
}
10 changes: 5 additions & 5 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ use std::io::{stdin, stdout, Write};

use crate::config::Config;
use crate::error::Result;
use crate::remote::{self, Remote};
use crate::remote::{create_remote, Remote};

mod repo;
pub use repo::repo;

mod remote;
pub use remote::remote;

mod auth;
pub use auth::auth;

mod create_config;
pub use create_config::create_config;

mod list_remotes;
pub use list_remotes::list_remotes;

async fn load_remote(remote_name: &str, config: &Config) -> Result<Box<dyn Remote>> {
let provider = config.get_remote_provider(remote_name)?;
let remote_config = config.get_remote_config(remote_name)?;
Ok(remote::create_remote(&remote_config, provider).await)
Ok(create_remote(&remote_config, provider).await)
}

fn get_input() -> Result<String> {
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions src/commands/remote/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use gritty_clap::remote::{Remote, RemoteCommands};

use crate::config::Config;
use crate::error::Result;

pub mod list;

pub use list::list_remotes;

pub async fn remote(remote: Remote, config: &Config) -> Result<()> {
match remote.subcommand {
RemoteCommands::List => list_remotes(config).await,
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn execute_command(args: Args) -> Result<()> {

// Execute the sub-command
match args.subcommand {
Commands::ListRemotes => commands::list_remotes(&config).await,
Commands::Remote(remote) => commands::remote(remote, &config).await,
Commands::Repo(repo) => commands::repo(repo, &config).await,
Commands::Auth(args) => commands::auth(args, &mut config).await,
Commands::CreateConfig => unreachable!(),
Expand Down

0 comments on commit 2e4b717

Please sign in to comment.