mirror of
https://github.com/nikolassv/bartib
synced 2025-02-26 11:57:12 +00:00
subcommand for editing the journal file
This commit is contained in:
parent
1d8560cba3
commit
f7885eb345
3 changed files with 52 additions and 5 deletions
20
README.md
20
README.md
|
@ -10,7 +10,7 @@ Build it with cargo:
|
|||
cargo build --release
|
||||
```
|
||||
|
||||
## The `.bartib` file
|
||||
## The journal file
|
||||
|
||||
Bartib safes a journal of all tracked activities in a plaintext file. The file can either be specified via the `-f / --file` cli option or as a `BARTIB_FILE` environment variable.
|
||||
|
||||
|
@ -42,13 +42,13 @@ Stops the currently running activity:
|
|||
bartib stop
|
||||
```
|
||||
|
||||
### Continues the last activity
|
||||
### Continue the last activity
|
||||
|
||||
```
|
||||
bartib continue [-p "Another project"] [-d "Another description"]
|
||||
```
|
||||
|
||||
This continues the last activity. If an activity is currently tracked, bartib stops and restarts this activity. The associated project and description may be overwritten by setting a `-p / --project` or `-d / --description` parameter.
|
||||
This continues the last activity. If an activity is currently tracked, bartib stops and restarts this activity. The associated project and description may be overwritten by setting a `-p / --project` or `-d / --description` option.
|
||||
|
||||
### List all currently running activities
|
||||
|
||||
|
@ -89,6 +89,20 @@ bartib list --today
|
|||
bartib list --yesterday
|
||||
```
|
||||
|
||||
### Edit activities
|
||||
|
||||
To change tracked activities, just open the file with your activities log in any text editor. To facilitate this, bartib offers the `edit` subcommand:
|
||||
|
||||
```
|
||||
bartib edit
|
||||
```
|
||||
|
||||
This will open your log in the editor you have defined in your `EDITOR` environment variable. Alternatively you can specify the editor command via the `-e/--editor` option:
|
||||
|
||||
```
|
||||
bartib edit -e vim
|
||||
```
|
||||
|
||||
### Show last activity
|
||||
|
||||
```
|
||||
|
|
18
src/lib.rs
18
src/lib.rs
|
@ -1,8 +1,9 @@
|
|||
use anyhow::{bail, Context, Result, Error};
|
||||
use anyhow::{anyhow, bail, Context, Result, Error};
|
||||
use chrono::{naive, NaiveDate};
|
||||
|
||||
use crate::bartib_file::Line;
|
||||
use crate::activity::Activity;
|
||||
use std::process::Command;
|
||||
|
||||
mod activity;
|
||||
pub mod bartib_file;
|
||||
|
@ -145,6 +146,21 @@ pub fn continue_last_activity(file_name: &str, project_name: Option<&str>, activ
|
|||
}
|
||||
}
|
||||
|
||||
pub fn start_editor(file_name: &str, optional_editor_command: Option<&str>) -> Result<()> {
|
||||
let editor_command = optional_editor_command.context("editor command is missing")?;
|
||||
let command = Command::new(editor_command).arg(file_name).spawn();
|
||||
|
||||
match command {
|
||||
Ok(mut child) => {
|
||||
child.wait().context("editor did not execute")?;
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
Err(anyhow!(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_last_activity(file_content: &Vec<Line>) -> Option<&Activity> {
|
||||
get_activities(&file_content)
|
||||
.filter(|activity| activity.is_stopped())
|
||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -125,9 +125,22 @@ fn main() -> Result<()> {
|
|||
.subcommand(
|
||||
SubCommand::with_name("projects").about("list all projects")
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("edit")
|
||||
.about("opens the activity log in an editor")
|
||||
.arg(
|
||||
Arg::with_name("editor")
|
||||
.short("e")
|
||||
.value_name("editor")
|
||||
.help("the command to start your prefered text editor")
|
||||
.env("EDITOR")
|
||||
.takes_value(true),
|
||||
)
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let file_name = matches.value_of("file").context("Please specify a file with your activity log either as -f option or as BARTIB_FILE environment variable")?;
|
||||
let file_name = matches.value_of("file")
|
||||
.context("Please specify a file with your activity log either as -f option or as BARTIB_FILE environment variable")?;
|
||||
|
||||
run_subcommand(&matches, file_name)
|
||||
}
|
||||
|
@ -172,6 +185,10 @@ fn run_subcommand(matches: &ArgMatches, file_name: &str) -> Result<()> {
|
|||
},
|
||||
("projects", Some(_)) => bartib::list_projects(file_name),
|
||||
("last", Some(_)) => bartib::display_last_activity(file_name),
|
||||
("edit", Some(sub_m)) => {
|
||||
let optional_editor_command = sub_m.value_of("editor");
|
||||
bartib::start_editor(file_name, optional_editor_command)
|
||||
},
|
||||
_ => bail!("Unknown command"),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue