58 lines
1.4 KiB
Rust
58 lines
1.4 KiB
Rust
extern crate serde;
|
|
extern crate clap;
|
|
extern crate reqwest;
|
|
extern crate simple_home_dir;
|
|
|
|
mod cli;
|
|
mod config;
|
|
mod planning;
|
|
mod openproject;
|
|
mod error;
|
|
mod gitlab;
|
|
|
|
use std::fs;
|
|
use std::path::PathBuf;
|
|
use std::process::exit;
|
|
use clap::Parser;
|
|
use cli::Cli;
|
|
use config::Config;
|
|
use crate::cli::Commands::Planning;
|
|
use crate::cli::Planning::I2work;
|
|
use crate::error::GeneralError;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let cli = Cli::parse();
|
|
let mut default_config_path = PathBuf::new();
|
|
default_config_path.push(simple_home_dir::home_dir().unwrap());
|
|
default_config_path.push(".config/cl-cli/config.toml");
|
|
|
|
let config_path = match cli.config.as_deref() {
|
|
Some(p) => p,
|
|
None => &default_config_path
|
|
};
|
|
|
|
let config_path_content = match fs::read_to_string(config_path) {
|
|
Ok(content) => content,
|
|
Err(e) => {
|
|
println!("Could not read config file at {:?}, error: {}", config_path, e);
|
|
exit(1);
|
|
}
|
|
};
|
|
|
|
let config: Config = toml::from_str(&*config_path_content).expect("Could not parse config");
|
|
|
|
let result = match cli.command {
|
|
Some(Planning(I2work(args))) => planning::issue2work::issue2work(config, &args).await,
|
|
None => Err(GeneralError{description: "No command launched".to_string()})
|
|
};
|
|
|
|
match result {
|
|
Ok(()) => exit(0),
|
|
Err(e) => {
|
|
println!("Error: {}", e.description);
|
|
exit(1)
|
|
}
|
|
};
|
|
}
|