mirror of
https://github.com/gosticks/acari.git
synced 2025-10-16 11:45:37 +00:00
README + basic shell completions for fish
This commit is contained in:
parent
809b22765b
commit
f116826594
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 leanovate
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
76
README.md
Normal file
76
README.md
Normal file
@ -0,0 +1,76 @@
|
||||
# Command-line client for mite time-tracking
|
||||
|
||||
## Requirements
|
||||
|
||||
Rust >=1.40.0
|
||||
|
||||
## Installation
|
||||
|
||||
Right now this in a too early stage to be published on crates.io, so the best installation method is to check out this project and run
|
||||
```
|
||||
cargo install --path cli --force --locked
|
||||
```
|
||||
|
||||
## Shell completions
|
||||
|
||||
### Fish
|
||||
|
||||
Copy or symlink `cli/shell_completions/acari.fish` to `~/.config/fish/completions`.
|
||||
|
||||
### Bash/Zsh
|
||||
|
||||
Right now there are two options:
|
||||
* Migrate to the more colorful side of `fish`
|
||||
* Contribute your own completions. I will gladly accept pull requests.
|
||||
|
||||
## Basic usage
|
||||
|
||||
### Initialization
|
||||
|
||||
You need to get an API token from mite. This can be found on your account page. Then you just have to do
|
||||
```
|
||||
acari init
|
||||
```
|
||||
which will ask for your mite domain and token.
|
||||
|
||||
Alternatively you simply create a `~/.config/acari/config.toml`
|
||||
```
|
||||
domain = '<your-company>.mite.yo.lk'
|
||||
token = '<your-token>'
|
||||
cache_ttl_minutes = 1440
|
||||
```
|
||||
|
||||
After this you may check your connection with
|
||||
```
|
||||
acari check
|
||||
```
|
||||
with will print your account and user information.
|
||||
|
||||
### Query customers/projects/services
|
||||
|
||||
List customers
|
||||
```
|
||||
acari customers
|
||||
```
|
||||
|
||||
List projects
|
||||
```
|
||||
acari projects
|
||||
```
|
||||
or if you are interested in the projects of a specific customer
|
||||
```
|
||||
acari projects "<customer-name>"
|
||||
```
|
||||
|
||||
List services
|
||||
```
|
||||
acari services
|
||||
```
|
||||
|
||||
All of these information will be cached. You can modify the cache duration in your `~/.config/acari/config.toml` (default: 1 day).
|
||||
|
||||
If you think that something is missing you can try running the above commands with the `--no-cache` option, or run
|
||||
```
|
||||
acari clear-cache
|
||||
```
|
||||
or simple erase the `~/.cache/acari` directory.
|
||||
@ -17,3 +17,8 @@ prettytable-rs = "0"
|
||||
itertools = "0"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
acari-lib = { path = "../lib" }
|
||||
|
||||
|
||||
[[bin]]
|
||||
name = "acari"
|
||||
path = "src/main.rs"
|
||||
32
cli/shell_completions/acari.fish
Normal file
32
cli/shell_completions/acari.fish
Normal file
@ -0,0 +1,32 @@
|
||||
function __fish_is_arg_n --argument-names n
|
||||
test $n -eq (count (string match -v -- '-*' (commandline -poc)))
|
||||
end
|
||||
|
||||
# options
|
||||
complete -c acari -s o -l output -a "flat json pretty" -d "set output format"
|
||||
complete -c acari -s h -l help -d "show help"
|
||||
complete -c acari -l no-cache -d "disable caching"
|
||||
|
||||
# subcommands
|
||||
complete -f -c acari -n "__fish_use_subcommand" -a init -d "initialize connection"
|
||||
complete -f -c acari -n "__fish_use_subcommand" -a check -d "check connection"
|
||||
complete -f -c acari -n "__fish_use_subcommand" -a clear-cache -d "Clear local cache"
|
||||
complete -f -c acari -n "__fish_use_subcommand" -a customers -d "list customers"
|
||||
complete -f -c acari -n "__fish_use_subcommand" -a projects -d "list projects"
|
||||
complete -f -c acari -n "__fish_use_subcommand" -a services -d "list services"
|
||||
|
||||
# check
|
||||
complete -f -c acari -n "__fish_seen_subcommand_from check"
|
||||
|
||||
# check
|
||||
complete -f -c acari -n "__fish_seen_subcommand_from clear-cache"
|
||||
|
||||
# customers
|
||||
complete -f -c acari -n "__fish_seen_subcommand_from customers"
|
||||
|
||||
# projects
|
||||
complete -f -c acari -n "__fish_seen_subcommand_from projects"
|
||||
complete -f -c acari -n "__fish_seen_subcommand_from projects; and __fish_is_arg_n 2" -a "(acari -oflat customers)"
|
||||
|
||||
# services
|
||||
complete -f -c acari -n "__fish_seen_subcommand_from services"
|
||||
5
cli/src/commands/clear_cache.rs
Normal file
5
cli/src/commands/clear_cache.rs
Normal file
@ -0,0 +1,5 @@
|
||||
use acari_lib::{AcariError, CachedClient};
|
||||
|
||||
pub fn clear_cache() -> Result<(), AcariError> {
|
||||
CachedClient::clear_cache()
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
mod all_projects;
|
||||
mod check;
|
||||
mod clear_cache;
|
||||
mod customers;
|
||||
mod entries;
|
||||
mod init;
|
||||
@ -8,6 +9,7 @@ mod services;
|
||||
|
||||
pub use all_projects::*;
|
||||
pub use check::*;
|
||||
pub use clear_cache::*;
|
||||
pub use customers::*;
|
||||
pub use entries::*;
|
||||
pub use init::*;
|
||||
|
||||
@ -21,6 +21,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.arg(Arg::with_name("no-cache").long("no-cache").help("Disable the use of cache files"))
|
||||
.subcommand(SubCommand::with_name("init").about("Initialize connection to mite"))
|
||||
.subcommand(SubCommand::with_name("check").about("Check connection to mite"))
|
||||
.subcommand(SubCommand::with_name("clear-cache").about("Clear the local cache"))
|
||||
.subcommand(SubCommand::with_name("customers").about("List all customers"))
|
||||
.subcommand(
|
||||
SubCommand::with_name("projects")
|
||||
@ -47,6 +48,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
match matches.subcommand() {
|
||||
("init", _) => commands::init()?,
|
||||
("check", _) => commands::check(client.as_ref(), output_format)?,
|
||||
("clear-cache", _) => commands::clear_cache()?,
|
||||
("customers", _) => commands::customers(client.as_ref(), output_format)?,
|
||||
("projects", Some(sub_matches)) => match sub_matches.value_of("customer") {
|
||||
Some(customer) => commands::projects_of_customer(client.as_ref(), customer, output_format)?,
|
||||
|
||||
@ -30,6 +30,14 @@ impl CachedClient {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn clear_cache() -> Result<(), AcariError> {
|
||||
let cache_dir = cache_dir();
|
||||
|
||||
fs::remove_dir_all(cache_dir)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn cache_data<T, F>(&self, cache_name: &str, fetch_data: F) -> Result<T, AcariError>
|
||||
where
|
||||
T: DeserializeOwned + Serialize,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user