diff --git a/.env b/.env deleted file mode 100644 index fbee64a..0000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -GITEA_USERNAME=kjuulh -GITEA_API_TOKEN=c0bd801cc9a7f2ed559ea45d603afc92f5443f19 diff --git a/.gitignore b/.gitignore index a269da4..33117ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target .cuddle/ target/ +.env diff --git a/Cargo.lock b/Cargo.lock index 8780bed..730d0ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "async-trait" version = "0.1.58" @@ -69,6 +78,21 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim 0.8.0", + "textwrap", + "unicode-width", + "vec_map", +] + [[package]] name = "clap" version = "4.0.18" @@ -78,7 +102,7 @@ dependencies = [ "atty", "bitflags", "clap_lex", - "strsim", + "strsim 0.10.0", "termcolor", ] @@ -107,6 +131,15 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" +dependencies = [ + "clap 2.34.0", +] + [[package]] name = "encoding_rs" version = "0.8.31" @@ -583,6 +616,7 @@ dependencies = [ name = "octopush" version = "0.1.0" dependencies = [ + "dotenv", "eyre", "octopush_cli", "tokio", @@ -594,7 +628,7 @@ dependencies = [ name = "octopush_cli" version = "0.1.0" dependencies = [ - "clap", + "clap 4.0.18", "eyre", "octopush_core", "octopush_infra", @@ -1015,6 +1049,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + [[package]] name = "strsim" version = "0.10.0" @@ -1055,6 +1095,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + [[package]] name = "thread_local" version = "1.1.4" @@ -1252,6 +1301,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + [[package]] name = "unsafe-libyaml" version = "0.2.4" @@ -1290,6 +1345,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 0fe200a..e8d46f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,3 +28,4 @@ tokio = { workspace = true } tracing = { workspace = true } tracing-subscriber = { version = "0.3.16", features = ["json", "env-filter"] } +dotenv = { version = "0.15.0", features = ["clap", "cli"] } diff --git a/crates/octopush_cli/src/commands/execute.rs b/crates/octopush_cli/src/commands/execute.rs index 2b82e34..82ad4da 100644 --- a/crates/octopush_cli/src/commands/execute.rs +++ b/crates/octopush_cli/src/commands/execute.rs @@ -21,10 +21,24 @@ pub fn execute_cmd() -> Command { .required(true), ) .arg( - Arg::new("gitea-http-token") - .long("gitea-http-token") + Arg::new("gitea-api-token") + .long("gitea-api-token") .action(ArgAction::Set) - .env("GITEA_HTTP_TOKEN") + .env("GITEA_API_TOKEN") + .required(false), + ) + .arg( + Arg::new("gitea-username") + .long("gitea-username") + .action(ArgAction::Set) + .env("GITEA_USERNAME") + .required(false), + ) + .arg( + Arg::new("gitea-url") + .long("gitea-url") + .action(ArgAction::Set) + .env("GITEA_URL") .required(false), ) } @@ -34,13 +48,18 @@ pub async fn execute_subcommand(args: &ArgMatches) -> eyre::Result<()> { .get_one::("action") .ok_or(eyre::anyhow!("--action is required"))?; - let gitea_http_token = args.get_one::("gitea-http-token"); + let gitea_http_token = args.get_one::("gitea-api-token"); + let gitea_username = args.get_one::("gitea-username"); + let gitea_url = args.get_one::("gitea-url"); let service_register = ServiceRegister::new( LocalGitProviderOptions { http_auth: None }, DefaultGiteaClientOptions { - url: "https://git.front.kjuulh.io/api/v1".into(), - basicauth: gitea_http_token.map(|t| t.clone()), + url: gitea_url.map(|g| g.clone()).unwrap_or("".into()), + basicauth: gitea_username + .zip(gitea_http_token) + .map(|(u, ht)| format!("{}:{}", u, ht)) + .map(|t| t.clone()), }, ); diff --git a/src/main.rs b/src/main.rs index 0e86ad0..4dfd6b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,10 @@ +use dotenv::dotenv; use tracing_subscriber::prelude::*; #[tokio::main] async fn main() -> eyre::Result<()> { + dotenv()?; + tracing_subscriber::registry() .with(tracing_subscriber::EnvFilter::new( std::env::var("RUST_LOG")