Skip to content

Commit

Permalink
Added between subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsing committed Jun 12, 2020
1 parent eba171e commit d64f916
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ pub enum SubCommand {
#[structopt(short, long)]
description: Option<String>,
},
Between {
/// Time interval in which work was done
time: String,
/// Name of the project
project: Option<String>,
/// Description of the given project
#[structopt(short, long)]
description: Option<String>,
}
}

#[derive(StructOpt, Debug)]
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ fn run_app(args: Args) -> Result<i32, AppError> {
project,
description,
} => until(&mut log, &time, project, description),
SubCommand::Between {
time,
project,
description,
} => between(&mut log, &time, project, description),
SubCommand::While {
cmd,
project,
Expand Down
28 changes: 24 additions & 4 deletions src/subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,30 @@ pub fn until(
}

let interval = time::Interval::try_parse(time, &time::Search::Forward)?;
log.append_event_now(&Event::Start(project.clone(), description.clone()))?;
log.append_event(&Event::Stop(project, description), interval.end)?;
Ok(0)
}

/// The `between` function corresponds to the `between` command.
///
/// The command makes sure that user is free. If there is no work in progress the command will
/// append a `start` event at the specified start time with `project` name and `description` and
/// will finish by appending a `stop` event at the specified end time.
pub fn between(
log: &mut LogFile,
time: &str,
project: Option<String>,
description: Option<String>,
) -> Result<i32, AppError> {
let event = log.get_latest_event()?;
if is_working(&event) {
return Err(AppError::new(ErrorKind::User(
"Please stop the current work before starting new work.".to_string(),
)));
}

let interval = time::Interval::try_parse(time, &time::Search::Backward)?;
log.append_event(
&Event::Start(project.clone(), description.clone()),
interval.start,
Expand Down Expand Up @@ -282,7 +306,3 @@ pub fn r#while(
}
}
}

pub fn between() {}

pub fn remove() {}

0 comments on commit d64f916

Please sign in to comment.