mirror of
https://github.com/gosticks/acari.git
synced 2025-10-16 11:45:37 +00:00
Update libs
This commit is contained in:
parent
eeed27fa90
commit
cd141258cf
1537
Cargo.lock
generated
1537
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -12,7 +12,7 @@ keywords = ["mite", "mite-api", "time-tracking"]
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
clap = "3.0.0-beta.2"
|
||||
clap = { version = "4", features = ["cargo", "derive"] }
|
||||
dirs = "2"
|
||||
toml = "0"
|
||||
text_io = "0"
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
use super::OutputFormat;
|
||||
use super::{entries, find_customer, find_project, find_service};
|
||||
use acari_lib::{AcariError, Client, Day, Minutes};
|
||||
use clap::Clap;
|
||||
use clap::Args;
|
||||
|
||||
#[derive(Clap, PartialEq, Eq)]
|
||||
#[derive(Debug, Args, PartialEq, Eq)]
|
||||
pub struct AddCmd {
|
||||
#[clap(about = "Customer name")]
|
||||
#[clap(help = "Customer name")]
|
||||
customer: String,
|
||||
#[clap(about = "Project name")]
|
||||
#[clap(help = "Project name")]
|
||||
project: String,
|
||||
#[clap(about = "Service name")]
|
||||
#[clap(help = "Service name")]
|
||||
service: String,
|
||||
#[clap(about = "Time (minutes or hh:mm)")]
|
||||
#[clap(help = "Time (minutes or hh:mm)")]
|
||||
time: Minutes,
|
||||
#[clap(about = "Date", default_value = "today")]
|
||||
#[clap(help = "Date", default_value = "today")]
|
||||
day: Day,
|
||||
#[clap(short, long, about = "Optional note")]
|
||||
#[clap(short, long, help = "Optional note")]
|
||||
note: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use super::OutputFormat;
|
||||
use acari_lib::{AcariError, Client, Project};
|
||||
use itertools::Itertools;
|
||||
use prettytable::{cell, format, row, Table};
|
||||
use prettytable::{format, row, Table};
|
||||
|
||||
pub fn all_projects(client: &dyn Client, output_format: OutputFormat) -> Result<(), AcariError> {
|
||||
let mut projects = client.get_projects()?;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use super::OutputFormat;
|
||||
use acari_lib::{AcariError, Account, Client, User};
|
||||
use prettytable::{cell, format, row, table};
|
||||
use prettytable::{format, table};
|
||||
use serde_json::json;
|
||||
|
||||
pub fn check(client: &dyn Client, output_format: OutputFormat) -> Result<(), AcariError> {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use super::OutputFormat;
|
||||
use acari_lib::{AcariError, Client, Customer};
|
||||
use prettytable::{cell, format, row, Table};
|
||||
use prettytable::{format, row, Table};
|
||||
|
||||
pub fn customers(client: &dyn Client, output_format: OutputFormat) -> Result<(), AcariError> {
|
||||
let mut customers = client.get_customers()?;
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
use super::OutputFormat;
|
||||
use acari_lib::{AcariError, Client, DateSpan, Minutes, TimeEntry};
|
||||
use chrono::NaiveDate;
|
||||
use clap::Clap;
|
||||
use clap::Args;
|
||||
use itertools::Itertools;
|
||||
use prettytable::{cell, format, row, Table};
|
||||
use prettytable::{format, row, Table};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
#[derive(Clap, PartialEq, Eq)]
|
||||
#[derive(Debug, Args, PartialEq, Eq)]
|
||||
pub struct EntriesCmd {
|
||||
#[clap(about = "Date span to query\n(today, yesterday, this-week, last-week,\n this-month, last-month, yyyy-mm-dd, yyyy-mm-dd/yyyy-mm-dd)")]
|
||||
#[clap(help = "Date span to query\n(today, yesterday, this-week, last-week,\n this-month, last-month, yyyy-mm-dd, yyyy-mm-dd/yyyy-mm-dd)")]
|
||||
span: DateSpan,
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use clap::Clap;
|
||||
use clap::ValueEnum;
|
||||
|
||||
mod add;
|
||||
mod all_projects;
|
||||
@ -28,7 +28,7 @@ pub use tracker::*;
|
||||
|
||||
use acari_lib::{user_error, AcariError, Client, Customer, CustomerId, Project, ProjectId, Service};
|
||||
|
||||
#[derive(Clap, Debug, PartialEq)]
|
||||
#[derive(ValueEnum, Debug, PartialEq, Clone, Copy)]
|
||||
pub enum OutputFormat {
|
||||
Pretty,
|
||||
Json,
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
use acari_lib::{AcariError, Client};
|
||||
use clap::Clap;
|
||||
use clap::Args;
|
||||
|
||||
use super::{all_projects, projects_of_customer, OutputFormat};
|
||||
|
||||
#[derive(Clap, PartialEq, Eq)]
|
||||
#[derive(Debug, Args, PartialEq, Eq)]
|
||||
pub struct ProjectsCmd {
|
||||
#[clap(about = "Optional: List only projects of a specific customer")]
|
||||
#[clap(help = "Optional: List only projects of a specific customer")]
|
||||
customer: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use super::OutputFormat;
|
||||
use acari_lib::{AcariError, Client, Project};
|
||||
use prettytable::{cell, format, row, Table};
|
||||
use prettytable::{format, row, Table};
|
||||
|
||||
pub fn projects_of_customer(client: &dyn Client, output_format: OutputFormat, customer_name: &str) -> Result<(), AcariError> {
|
||||
let mut projects = client.get_projects()?;
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
use super::OutputFormat;
|
||||
use super::{find_customer, find_project};
|
||||
use acari_lib::{AcariError, Client, Service};
|
||||
use clap::Clap;
|
||||
use clap::Args;
|
||||
use itertools::Itertools;
|
||||
use prettytable::{cell, row, table};
|
||||
use prettytable::table;
|
||||
|
||||
#[derive(Clap, PartialEq, Eq)]
|
||||
#[derive(Debug, Args, PartialEq, Eq)]
|
||||
pub struct ServicesCommand {
|
||||
#[clap(about = "Customer name")]
|
||||
#[clap(help = "Customer name")]
|
||||
customer: String,
|
||||
#[clap(about = "Project name")]
|
||||
#[clap(help = "Project name")]
|
||||
project: String,
|
||||
}
|
||||
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
use super::OutputFormat;
|
||||
use super::{entries, find_customer, find_project, find_service};
|
||||
use acari_lib::{AcariError, Client, Day, Minutes};
|
||||
use clap::Clap;
|
||||
use clap::Args;
|
||||
|
||||
#[derive(Clap, PartialEq, Eq)]
|
||||
#[derive(Debug, Args, PartialEq, Eq)]
|
||||
pub struct SetCmd {
|
||||
#[clap(about = "Customer name")]
|
||||
#[clap(help = "Customer name")]
|
||||
customer: String,
|
||||
#[clap(about = "Project name")]
|
||||
#[clap(help = "Project name")]
|
||||
project: String,
|
||||
#[clap(about = "Service name")]
|
||||
#[clap(help = "Service name")]
|
||||
service: String,
|
||||
#[clap(about = "Time (minutes or hh:mm)")]
|
||||
#[clap(help = "Time (minutes or hh:mm)")]
|
||||
time: Minutes,
|
||||
#[clap(about = "Date", default_value = "today")]
|
||||
#[clap(help = "Date", default_value = "today")]
|
||||
day: Day,
|
||||
#[clap(short, long, about = "Optional note")]
|
||||
#[clap(short, long, help = "Optional note")]
|
||||
note: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
use super::OutputFormat;
|
||||
use super::{find_customer, find_project, find_service};
|
||||
use acari_lib::{AcariError, Client, Day, Minutes, TimeEntry, Tracker};
|
||||
use clap::Clap;
|
||||
use prettytable::{cell, format, row, table};
|
||||
use clap::Args;
|
||||
use prettytable::{format, row, table};
|
||||
use serde_json::json;
|
||||
|
||||
#[derive(Clap, PartialEq, Eq)]
|
||||
#[derive(Debug, Args, PartialEq, Eq)]
|
||||
pub struct StartCmd {
|
||||
#[clap(about = "Customer name")]
|
||||
#[clap(help = "Customer name")]
|
||||
customer: String,
|
||||
#[clap(about = "Project name")]
|
||||
#[clap(help = "Project name")]
|
||||
project: String,
|
||||
#[clap(about = "Service name")]
|
||||
#[clap(help = "Service name")]
|
||||
service: String,
|
||||
#[clap(about = "Optional: Starting offset (minutes or hh:mm)")]
|
||||
#[clap(help = "Optional: Starting offset (minutes or hh:mm)")]
|
||||
offset: Option<Minutes>,
|
||||
#[clap(short, long, about = "Optional note")]
|
||||
#[clap(short, long, help = "Optional note")]
|
||||
note: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
@ -44,9 +44,9 @@ impl Config {
|
||||
let config_file = config_file();
|
||||
match File::open(&config_file) {
|
||||
Ok(mut file) => {
|
||||
let mut content = vec![];
|
||||
file.read_to_end(&mut content)?;
|
||||
Ok(Some(toml::from_slice::<Config>(&content)?))
|
||||
let mut content = String::new();
|
||||
file.read_to_string(&mut content)?;
|
||||
Ok(Some(toml::from_str::<Config>(&content)?))
|
||||
}
|
||||
Err(ref err) if err.kind() == io::ErrorKind::NotFound => Ok(None),
|
||||
Err(err) => Err(err.into()),
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use acari_lib::{clear_cache, AcariError};
|
||||
use clap::Clap;
|
||||
use clap::{Parser, Subcommand};
|
||||
use std::str;
|
||||
|
||||
mod commands;
|
||||
@ -8,24 +8,24 @@ mod config;
|
||||
use commands::OutputFormat;
|
||||
use config::Config;
|
||||
|
||||
#[derive(Clap)]
|
||||
#[clap(version = "0.1.9")]
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(version = "0.1.10")]
|
||||
struct Opts {
|
||||
#[clap(short, long, arg_enum, about = "Output format", default_value = "pretty")]
|
||||
#[clap(short, long, help = "Output format", default_value = "pretty")]
|
||||
output: OutputFormat,
|
||||
|
||||
#[clap(short, long, about = "Select profile")]
|
||||
#[clap(short, long, help = "Select profile")]
|
||||
profile: Option<String>,
|
||||
|
||||
#[clap(long, about = "Disable the use of cache files")]
|
||||
#[clap(long, help = "Disable the use of cache files")]
|
||||
no_cache: bool,
|
||||
|
||||
#[clap(subcommand)]
|
||||
subcommand: SubCommand,
|
||||
subcommand: AcariSubCommand,
|
||||
}
|
||||
|
||||
#[derive(Clap, PartialEq, Eq)]
|
||||
enum SubCommand {
|
||||
#[derive(Debug, Subcommand, PartialEq, Eq)]
|
||||
enum AcariSubCommand {
|
||||
#[clap(about = "Initialize connection to mite")]
|
||||
Init,
|
||||
#[clap(about = "Just add a time entry")]
|
||||
@ -59,25 +59,25 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let opts: Opts = Opts::parse();
|
||||
|
||||
if opts.subcommand == SubCommand::Init {
|
||||
if opts.subcommand == AcariSubCommand::Init {
|
||||
// Init is special
|
||||
commands::init(Config::read()?, &opts.profile)?;
|
||||
} else if let Some(config) = Config::read()? {
|
||||
let client = config.client(&opts.profile, !opts.no_cache)?;
|
||||
match opts.subcommand {
|
||||
SubCommand::Add(add_cmd) => add_cmd.run(client.as_ref(), opts.output)?,
|
||||
SubCommand::Check => commands::check(client.as_ref(), opts.output)?,
|
||||
SubCommand::ClearCache => clear_cache()?,
|
||||
SubCommand::Customers => commands::customers(client.as_ref(), opts.output)?,
|
||||
SubCommand::Entries(entries_cmd) => entries_cmd.run(client.as_ref(), opts.output)?,
|
||||
SubCommand::Profiles => commands::profiles(config),
|
||||
SubCommand::Projects(projects_cmd) => projects_cmd.run(client.as_ref(), opts.output)?,
|
||||
SubCommand::Services(services_cmd) => services_cmd.run(client.as_ref(), opts.output)?,
|
||||
SubCommand::Set(set_cmd) => set_cmd.run(client.as_ref(), opts.output)?,
|
||||
SubCommand::Start(start_cmd) => start_cmd.run(client.as_ref(), opts.output)?,
|
||||
SubCommand::Stop => commands::stop(client.as_ref(), opts.output)?,
|
||||
SubCommand::Tracking => commands::tracking(client.as_ref(), opts.output)?,
|
||||
SubCommand::Init => unreachable!(),
|
||||
AcariSubCommand::Add(add_cmd) => add_cmd.run(client.as_ref(), opts.output)?,
|
||||
AcariSubCommand::Check => commands::check(client.as_ref(), opts.output)?,
|
||||
AcariSubCommand::ClearCache => clear_cache()?,
|
||||
AcariSubCommand::Customers => commands::customers(client.as_ref(), opts.output)?,
|
||||
AcariSubCommand::Entries(entries_cmd) => entries_cmd.run(client.as_ref(), opts.output)?,
|
||||
AcariSubCommand::Profiles => commands::profiles(config),
|
||||
AcariSubCommand::Projects(projects_cmd) => projects_cmd.run(client.as_ref(), opts.output)?,
|
||||
AcariSubCommand::Services(services_cmd) => services_cmd.run(client.as_ref(), opts.output)?,
|
||||
AcariSubCommand::Set(set_cmd) => set_cmd.run(client.as_ref(), opts.output)?,
|
||||
AcariSubCommand::Start(start_cmd) => start_cmd.run(client.as_ref(), opts.output)?,
|
||||
AcariSubCommand::Stop => commands::stop(client.as_ref(), opts.output)?,
|
||||
AcariSubCommand::Tracking => commands::tracking(client.as_ref(), opts.output)?,
|
||||
AcariSubCommand::Init => unreachable!(),
|
||||
}
|
||||
} else {
|
||||
return Err(AcariError::UserError("Missing configuration, run init first".to_string()).into());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user