Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
zekroTJA committed Apr 18, 2024
1 parent 567d02a commit 3a74b53
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
# tracker

< insert description here >
A simple tool to track time.

## Usage

```
$ tracker --help
< insert help here >
Simple tool to do time tracking
Usage: tracker.exe [OPTIONS] <COMMAND>
Commands:
add Add a track entry
view Display tracking list entries
delete Remove entries from a tracking list
help Print this message or the help of the given subcommand(s)
Options:
-c, --config <CONFIG> Path to a config file
-h, --help Print help
-V, --version Print version
```

## Install
Expand Down
4 changes: 4 additions & 0 deletions src/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ use chrono::{Local, NaiveDateTime, NaiveTime};
use clap::Args;
use inquire::Confirm;

/// Add a track entry
#[derive(Args)]
pub struct Add {
/// A short message
message: Vec<String>,

/// Time to set the entry at
#[arg(short, long)]
time: Option<String>,

/// Add a long description
#[arg(short, long)]
long: Option<String>,
}
Expand Down
5 changes: 2 additions & 3 deletions src/commands/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ use chrono::Local;
use clap::Args;
use inquire::MultiSelect;

/// Remove entries from a tracking list
#[derive(Args)]
pub struct Delete {
/// Date of the list
date: Option<String>,

#[arg(short, long)]
long: bool,
}

impl Command for Delete {
Expand Down
3 changes: 3 additions & 0 deletions src/commands/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ use chrono::Local;
use clap::Args;
use yansi::Paint;

/// Display tracking list entries
#[derive(Args)]
pub struct View {
/// Date of the list
date: Option<String>,

/// Display additional description
#[arg(short, long)]
long: bool,
}
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use commands::*;
use config::Config;
use store::Store;

/// Simple tool to do time tracking
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
Expand Down
19 changes: 7 additions & 12 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,19 @@ impl TryFrom<&str> for Entry {
}

impl Entry {
fn to_csv(&self) -> Result<String> {
use std::fmt::Write;

let mut res = String::new();

fn to_csv<W: Write>(&self, mut w: W) -> Result<()> {
let long = match self.long {
Some(ref v) => v.as_ref(),
None => "",
}
.replace('"', "\\\"")
.replace("\r\n", "<NEWLINE>")
.replace('\n', "<NEWLINE>");

let msg = self.message.replace('"', "\\\"").replace('\n', "<NEWLINE>");
// TODO: This is ugly AF and should write directly into a stream
writeln!(res, r#""{}","{msg}","{long}""#, self.timestamp)?;
writeln!(w, r#""{}","{msg}","{long}""#, self.timestamp)?;

Ok(res)
Ok(())
}
}

Expand All @@ -87,9 +83,8 @@ impl Store {
}

pub fn push_entry(&self, entry: Entry) -> Result<()> {
let mut track_file = self.get_track_file(&entry.timestamp)?;
write!(track_file, "{}", entry.to_csv()?)?;

let track_file = self.get_track_file(&entry.timestamp)?;
entry.to_csv(track_file)?;
Ok(())
}

Expand All @@ -114,7 +109,7 @@ impl Store {
let mut track_file = File::create(path)?;

for e in entries {
write!(track_file, "{}", e.to_csv()?)?;
e.to_csv(&mut track_file)?
}

Ok(())
Expand Down

0 comments on commit 3a74b53

Please sign in to comment.