From 415c39bc812de33b912ef422fcede597f1b9983e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=81scar=20M=2E=20Lage?= Date: Fri, 12 Nov 2021 23:41:31 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + Cargo.lock | 200 +++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 13 ++++ src/NOTES.md | 17 +++++ src/cli.rs | 34 +++++++++ src/cmd.rs | 17 +++++ src/config.rs | 31 ++++++++ src/console.rs | 31 ++++++++ src/main.rs | 39 ++++++++++ 9 files changed, 383 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/NOTES.md create mode 100644 src/cli.rs create mode 100644 src/cmd.rs create mode 100644 src/config.rs create mode 100644 src/console.rs create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..44ae53c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,200 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "clap" +version = "2.33.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "gst" +version = "0.1.0" +dependencies = [ + "clap", + "serde", + "termcolor", + "toml", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "libc" +version = "0.2.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219" + +[[package]] +name = "proc-macro2" +version = "1.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "syn" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "toml" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" +dependencies = [ + "serde", +] + +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..7764f10 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "gst" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = "2" +termcolor = "1.0.4" +# configparser = "3.0.0" +toml = "0.4.2" +serde = { version = "1.0", features = ["derive"] } diff --git a/src/NOTES.md b/src/NOTES.md new file mode 100644 index 0000000..5d1504d --- /dev/null +++ b/src/NOTES.md @@ -0,0 +1,17 @@ +# Notes + +```sh +$ comando projects [pr] + - listado de proyectos +$ comando tasks [t] [--project|-pr] + - listado de tareas, agrupadas por proyectos +$ comando start -t 212 + - agrega nuevo stamp de la tarea 212 +$ comando stop +$ comando description "Task description" + - agrega descripción al último stamp +$ comando addtask [project] "Task title" + - agrega una nueva tarea al proyecto +$ comando status [--last] + - lista los stamps running y/o los últimos stamps +``` diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..07a0832 --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,34 @@ +extern crate clap; +use clap::{Arg, App, SubCommand}; + +pub fn build_cli() -> App<'static, 'static> { + App::new("gst") + .version("v0.1") + .author("Óscar M. Lage ") + .about("Cli tool to deal with gestion actions") + .arg( + Arg::with_name("config") + .short("c") + .long("config") + .value_name("FILE") + .help("Sets a custom config file") + .takes_value(true) + .default_value("/Users/oscar/.config/gst/gstrc"), + ) + .subcommand( + SubCommand::with_name("projects") + .about("List of active projects"), + ) + .subcommand( + SubCommand::with_name("tasks") + .about("List of active tasks grouped by project") + .arg( + Arg::with_name("project") + .short("p") + .long("project") + .value_name("PROJECT") + .help("Provides a project to list tasks from") + .takes_value(true), + ), + ) +} diff --git a/src/cmd.rs b/src/cmd.rs new file mode 100644 index 0000000..5331bd8 --- /dev/null +++ b/src/cmd.rs @@ -0,0 +1,17 @@ +use std::path::PathBuf; + +#[path = "./config.rs"] +mod config; + +pub fn get_projects(config_file: &PathBuf) { + // Config + let mut default_config = config::Config::default(); + let config = default_config.parse(&config_file); + + // Call api + println!("Call API, Config: {:?}", config); + + // Return json result + let projects = String::from("we"); + println!("{}", projects); +} diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..c569431 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,31 @@ +use std::path::PathBuf; +use std::fs::File; +use std::io::Read; // read_to_string + +use serde::{Serialize, Deserialize}; +use toml; + +#[derive(Debug, Serialize, Deserialize)] +pub struct Config { + url: String, + api: String, + key: String, +} + +impl Config { + pub fn default() -> Config { + Config { + url: "https://uri".to_string(), + api: "/v1/api".to_string(), + key: "s3cr3tk3y".to_string(), + } + } + pub fn parse(&mut self, config_file: &PathBuf) -> Config { + let mut file = File::open(config_file).unwrap(); + let mut s = String::new(); + file.read_to_string(&mut s).unwrap(); + let myconfig: Self = toml::from_str(&s).unwrap(); + myconfig + } +} + diff --git a/src/console.rs b/src/console.rs new file mode 100644 index 0000000..260cde4 --- /dev/null +++ b/src/console.rs @@ -0,0 +1,31 @@ +use std::io::Write; + +use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; + +#[allow(dead_code)] +pub fn info(message: &str) { + colorize(message, ColorSpec::new().set_bold(true)); +} + +#[allow(dead_code)] +pub fn warn(message: &str) { + colorize(message, ColorSpec::new().set_bold(true).set_fg(Some(Color::Yellow))); +} + +#[allow(dead_code)] +pub fn success(message: &str) { + colorize(message, ColorSpec::new().set_bold(true).set_fg(Some(Color::Green))); +} + +#[allow(dead_code)] +pub fn error(message: &str) { + colorize(message, ColorSpec::new().set_bold(true).set_fg(Some(Color::Red))); +} + +fn colorize(message: &str, color: &ColorSpec) { + let mut stdout = StandardStream::stdout(ColorChoice::Always); + stdout.set_color(color).unwrap(); + write!(&mut stdout, "{}", message).unwrap(); + stdout.set_color(&ColorSpec::new()).unwrap(); + writeln!(&mut stdout).unwrap(); +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..ff9c148 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,39 @@ +use std::{process}; +use std::path::PathBuf; + +mod cli; +mod cmd; +pub mod console; + +fn main() { + // Get cli matches + let matches = cli::build_cli().get_matches(); + + // Read the config file + let config_file = match matches.value_of("config") { + Some(path) => PathBuf::from(path), + None => { + console::error("Error, not able to load config"); + process::exit(1); + } + }; + + // Start program flow + match matches.subcommand() { + ("projects", Some(_matches)) => { + console::info("List of projects"); + cmd::get_projects(&config_file); + } + + ("tasks", Some(matches)) => { + let project = matches.value_of("project").unwrap_or(""); + println!("Tasks"); + if !project.is_empty() { + println!("Project: {}", project); + } + } + + _ => console::error("Whut!!!"), + } +} +