write workpackage on openproject

This commit is contained in:
2024-01-08 13:26:09 +01:00
parent 5b34a51d90
commit a17901a6d6
15 changed files with 739 additions and 82 deletions

View File

@@ -1,35 +1,57 @@
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;
fn main() {
#[tokio::main]
async fn main() {
let cli = Cli::parse();
let default_config_path = PathBuf::from("/etc/config.toml");
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 = fs::read_to_string(config_path)
.expect("Could not read config file");
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");
match cli.command {
Some(Planning(I2work(args))) => {
planning::issue2work::issue2work(config, &args);
},
None => {}
}
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)
}
};
}