Files
gt/src/main.rs

82 lines
2.1 KiB
Rust
Raw Permalink Normal View History

// gt - a gitea cli client
// Written by Wyatt J. Miller
2021-07-28 21:30:24 -04:00
// All right reserved, 2020 - 2021
// Licensed by the MPL v2
mod arg;
mod config;
mod generate;
mod issue;
mod pr;
mod repo;
2021-07-27 01:48:05 -04:00
mod request;
2021-12-18 20:11:18 -05:00
mod user;
mod util;
2021-07-27 01:48:05 -04:00
use clap::ArgMatches;
fn main() {
2021-07-28 21:30:24 -04:00
let matches: ArgMatches = arg::get_args();
let mut config = crate::config::Configuration::new();
config.load_envs();
if config.base_url.is_empty()
|| config.api_token.is_none()
|| (config.username.is_none() && config.password.is_none())
{
config.load_config_file();
}
2021-07-27 01:48:05 -04:00
let auth = request::Authentication::new(&config);
let request = auth.request_chooser(config.clone(), matches);
2021-07-27 01:48:05 -04:00
match request.arg_value.subcommand() {
("", None) => println!("No subcommand was given!"),
("repo", Some(repo_matches)) => {
let repo = repo::Repository::new();
// TODO: match expression should be here
if repo_matches.is_present("create") {
2021-07-27 01:48:05 -04:00
repo.create_repo(&request);
}
if repo_matches.is_present("delete") {
repo.delete_repo(&request);
}
if repo_matches.is_present("fork") {
repo.fork_repo(&request)
}
if repo_matches.is_present("search") {
repo.search_repo(&request)
}
if repo_matches.is_present("list") {
repo.list_repo(&request)
}
2021-12-19 20:01:05 -05:00
if repo_matches.is_present("push") {
repo.push_to_remote(&request, &config)
2021-12-19 20:01:05 -05:00
}
if repo_matches.is_present("pull") {
repo.pull_from_remote(&request, &config)
2021-12-19 20:01:05 -05:00
}
if repo_matches.is_present("clone") {
repo.clone_from_remote(&request, &config)
}
}
("issue", Some(issue_matches)) => {
let issue = issue::Issue::new();
// TODO: match expression should be here
if issue_matches.is_present("create") {
2021-12-18 20:11:18 -05:00
issue.create_issue(&request);
}
}
_ => println!("Huh?"),
}
2021-07-27 01:48:05 -04:00
}