Skip to content

Commit 45532ea

Browse files
committed
0.1.3 Added ghctl version
1 parent 06c7fe2 commit 45532ea

File tree

5 files changed

+48
-22
lines changed

5 files changed

+48
-22
lines changed

Cargo.lock

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ghctl"
3-
version = "0.1.0"
3+
version = "0.1.3"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -18,3 +18,4 @@ serde = "1.0.160"
1818
serde_json = "1.0.96"
1919
serde_yaml = "0.9.21"
2020
tokio = { version = "1.28.0", features = ["full"] }
21+
version = "3.0.0"

src/commands.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pub mod repo;
33

44
use clap::{Parser, Subcommand};
5-
use clap_verbosity_flag::{Verbosity, InfoLevel};
5+
use clap_verbosity_flag::{InfoLevel, Verbosity};
66
use repo::RepoCommand;
77

88
/// The top level clap parser and CLI arguments
@@ -27,6 +27,7 @@ pub struct Opts {
2727
pub enum Commands {
2828
#[command(about = "Manage repository configuration")]
2929
Repo(RepoCommand),
30+
Version,
3031
}
3132

3233
pub use repo::repo;

src/commands/repo.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub enum RepoConfigSubcommand {
4646
long = "config-file",
4747
help = "The configuration file to apply"
4848
)]
49-
config_files: Vec<String>
49+
config_files: Vec<String>,
5050
},
5151
}
5252

@@ -68,16 +68,25 @@ pub async fn repo(context: &ghctl::Context, repo: &RepoCommand) {
6868

6969
pub async fn config(context: &ghctl::Context, repo_config: &RepoConfigCommand) -> Result<()> {
7070
match &repo_config.command {
71-
RepoConfigSubcommand::Get { repo_full_name } =>
72-
ghctl::repo::get_repo_config(&context, repo_full_name.as_ref().unwrap()).await,
73-
74-
RepoConfigSubcommand::Apply { repo_full_name, config_files } => {
71+
RepoConfigSubcommand::Get { repo_full_name } => {
72+
ghctl::repo::get_repo_config(&context, repo_full_name.as_ref().unwrap()).await
73+
}
74+
75+
RepoConfigSubcommand::Apply {
76+
repo_full_name,
77+
config_files,
78+
} => {
7579
let (owner, repo_name) = split_repo_full_name(repo_full_name).unwrap();
76-
match ghctl::repo::config_apply(&context.access_token, owner, repo_name, config_files).await {
77-
Ok(_) => info!("Applied configuration to {}", repo_full_name.as_ref().unwrap()),
80+
match ghctl::repo::config_apply(&context.access_token, owner, repo_name, config_files)
81+
.await
82+
{
83+
Ok(_) => info!(
84+
"Applied configuration to {}",
85+
repo_full_name.as_ref().unwrap()
86+
),
7887
Err(e) => error!("Error: {}", e),
7988
}
80-
Ok(())
89+
Ok(())
8190
}
8291
}
8392
}

src/ghctl.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,30 @@ fn maybe_get_github_token_env_var() -> Result<String> {
3636
VarError::NotPresent => {
3737
error!("No access token provided and GITHUB_TOKEN environment variable not set, aborting.");
3838
exit(1)
39-
},
40-
_ => Err(anyhow::anyhow!(e))
39+
}
40+
_ => Err(anyhow::anyhow!(e)),
4141
},
4242
}
4343
}
4444

4545
/// Run the ghctl CLI
4646
pub async fn cli(opts: Opts) {
47-
env_logger::builder()
48-
.filter_level(opts.verbose.log_level_filter())
49-
.target(env_logger::Target::Stdout)
50-
.init();
51-
match build_context(opts) {
52-
Ok(context) => match &context.opts.command {
53-
Commands::Repo(repo) => commands::repo::repo(&context, repo).await,
54-
},
55-
Err(e) => error!("Error: {}", e),
47+
match &opts.command {
48+
Commands::Version => println!("ghctl version {}", clap::crate_version!()),
49+
_ => {
50+
env_logger::builder()
51+
.filter_level(opts.verbose.log_level_filter())
52+
.target(env_logger::Target::Stdout)
53+
.init();
54+
match build_context(opts) {
55+
Ok(context) => match &context.opts.command {
56+
Commands::Repo(repo) => commands::repo::repo(&context, repo).await,
57+
_ => {
58+
error!("Not yet implemented: {:?}", &context.opts.command)
59+
}
60+
},
61+
Err(e) => error!("Error: {}", e),
62+
}
63+
}
5664
}
5765
}

0 commit comments

Comments
 (0)