65 lines
1.6 KiB
Rust
65 lines
1.6 KiB
Rust
extern crate clap;
|
|
extern crate reqwest;
|
|
extern crate serde;
|
|
extern crate simple_home_dir;
|
|
|
|
mod cli;
|
|
mod config;
|
|
mod debug;
|
|
mod error;
|
|
mod gitlab;
|
|
mod openproject;
|
|
mod planning;
|
|
|
|
use crate::cli::Commands::{Planning, Test};
|
|
use crate::cli::Planning::I2work;
|
|
use crate::error::GeneralError;
|
|
use clap::Parser;
|
|
use cli::Cli;
|
|
use config::Config;
|
|
use std::fs;
|
|
use std::path::PathBuf;
|
|
use std::process::exit;
|
|
|
|
#[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,
|
|
Some(Test) => debug::debug(config).await,
|
|
None => Err(GeneralError {
|
|
description: "No command launched".to_string(),
|
|
}),
|
|
};
|
|
|
|
match result {
|
|
Ok(()) => exit(0),
|
|
Err(e) => {
|
|
println!("Error: {}", e.description);
|
|
exit(1)
|
|
}
|
|
};
|
|
}
|