-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
222 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Publish | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*' | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: cargo publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "talenta" | ||
version = "0.1.0" | ||
version = "0.2.0" | ||
authors = ["el7cosmos <[email protected]>"] | ||
edition = "2018" | ||
description = "Talenta CLI" | ||
|
@@ -10,6 +10,10 @@ license = "MIT OR Apache-2.0" | |
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
exclude = [ | ||
".github/*" | ||
] | ||
|
||
[dependencies] | ||
ansi_term = "0.12" | ||
chrono = "0.4" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use structopt::StructOpt; | ||
|
||
#[derive(Default, Debug, StructOpt)] | ||
#[structopt(about = "Request checkin only attendance")] | ||
pub(super) struct Checkin {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use structopt::StructOpt; | ||
|
||
#[derive(Default, Debug, StructOpt)] | ||
#[structopt(about = "Request checkout only attendance")] | ||
pub(super) struct Checkout {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
mod checkin; | ||
mod checkout; | ||
|
||
use crate::attendance::checkin::Checkin; | ||
use crate::attendance::checkout::Checkout; | ||
use crate::client::Client; | ||
use crate::config::Config; | ||
use crate::date::Date; | ||
use crate::time::Time; | ||
use crate::Command; | ||
use ansi_term::Colour; | ||
use dialoguer::theme::ColorfulTheme; | ||
use dialoguer::Input; | ||
use reqwest::StatusCode; | ||
use structopt::clap::{Error, ErrorKind}; | ||
use structopt::StructOpt; | ||
|
||
#[derive(Debug, StructOpt)] | ||
enum AttendanceCommand { | ||
Checkin(Checkin), | ||
Checkout(Checkout), | ||
} | ||
|
||
#[derive(Default, StructOpt)] | ||
#[structopt(about = "Request attendance")] | ||
pub(super) struct Attendance { | ||
#[structopt(skip)] | ||
client: Client, | ||
#[structopt(skip)] | ||
theme: ColorfulTheme, | ||
|
||
#[structopt(long)] | ||
reason: Option<String>, | ||
#[structopt( | ||
default_value, | ||
long, | ||
help = "Effective date (yyyy-mm-dd)", | ||
value_name = "DATE" | ||
)] | ||
date: Date, | ||
#[structopt(long, value_name = "TIME")] | ||
checkin_time: Option<Time>, | ||
#[structopt(long, value_name = "TIME")] | ||
checkout_time: Option<Time>, | ||
|
||
#[structopt(subcommand)] | ||
cmd: Option<AttendanceCommand>, | ||
} | ||
|
||
impl Command for Attendance { | ||
fn run(&self) { | ||
let config = Config::load().unwrap(); | ||
let token = match config.token() { | ||
None => Error::with_description( | ||
&format!( | ||
"Not logged in yet. Try: {}", | ||
Colour::Blue.bold().paint("talenta login") | ||
), | ||
ErrorKind::ValueValidation, | ||
) | ||
.exit(), | ||
Some(token) => token, | ||
}; | ||
|
||
match self.cmd.as_ref() { | ||
None => { | ||
let checkin_time = self.checkin_time.unwrap_or_else(|| { | ||
Input::with_theme(&self.theme) | ||
.with_prompt("Checkin time (HH:mm)") | ||
.interact() | ||
.unwrap() | ||
}); | ||
|
||
let checkout_time = self.checkout_time.unwrap_or_else(|| { | ||
Input::with_theme(&self.theme) | ||
.with_prompt("Checkout time (HH:mm)") | ||
.interact() | ||
.unwrap() | ||
}); | ||
|
||
let reason = self.reason.clone().unwrap_or_else(|| { | ||
Input::with_theme(&self.theme) | ||
.with_prompt("Reason") | ||
.interact() | ||
.unwrap() | ||
}); | ||
|
||
match self.client.attendance_request( | ||
token, | ||
&reason, | ||
self.date.into(), | ||
checkin_time.into(), | ||
checkout_time.into(), | ||
) { | ||
Ok(response) => { | ||
let status = StatusCode::from_u16(response.status()).unwrap(); | ||
match status.is_success() { | ||
true => Attendance::success(response.message()), | ||
false => Error::with_description( | ||
&response.message(), | ||
ErrorKind::ValueValidation, | ||
) | ||
.exit(), | ||
} | ||
} | ||
Err(err) => { | ||
Error::with_description(&err.to_string(), ErrorKind::ValueValidation).exit() | ||
} | ||
}; | ||
} | ||
Some(cmd) => match cmd { | ||
AttendanceCommand::Checkin(_checkin) => unimplemented!(), | ||
AttendanceCommand::Checkout(_checkout) => unimplemented!(), | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters