Skip to content

Commit 5f72bb0

Browse files
authored
Merge branch 'master' into master
2 parents 41b790a + 3a9db5c commit 5f72bb0

File tree

7 files changed

+124
-62
lines changed

7 files changed

+124
-62
lines changed

Cargo.lock

Lines changed: 53 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
[package]
22
name = "clink"
3-
version = "0.1.0"
3+
authors = ["Mary Strodl <[email protected]>", "Willard Nilges <[email protected]>"]
4+
version = "0.1.1"
45
edition = "2021"
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

89
[dependencies]
9-
clap = "2.33.3"
1010
url = "2.2.2"
1111
serde_json = "1.0.71"
1212
serde = "1.0.130"
1313
ncurses = "5.101.0"
1414
http = "0.2.5"
1515
rpassword = "5.0"
1616
users = "0.11.0"
17-
18-
[dependencies.isahc]
19-
version = "1.6.0"
20-
features = ["json", "spnego"]
17+
clap = { version = "3.1.6", features = ["cargo"] }
18+
isahc = { version = "1.6.0", features = ["json", "spnego"] }

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Clink
2+
3+
Clink is a command line interface for ordering drinks from any of the vending machines on floor.
4+
5+
It comes with a command line that can be used to list and purchase drinks.
6+
7+
![image](https://user-images.githubusercontent.com/42927786/157095410-d208a41d-adcb-4991-b9c1-3e7a8ed38f8f.png)
8+
9+
Or, if you prefer a more graphical experience, you can use the ncurses UI.
10+
11+
![image](https://user-images.githubusercontent.com/42927786/157095299-7c97a0a0-9bb7-4366-ba4f-94324189b950.png)
12+
13+
## Usage
14+
15+
To use clink, simply...
16+
17+
1. Log onto any user machine
18+
2. Run `kinit` to get a kerberos token
19+
3. Run `clink`
20+
21+
![output2](https://user-images.githubusercontent.com/42927786/157098855-302db1ed-13b8-4be5-b1bf-4431ea83e92f.gif)
22+
23+
## Development
24+
```
25+
git clone [email protected]/computersciencehouse/clink
26+
cd clink
27+
cargo build
28+
```

src/commands/drop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clap::ArgMatches;
22

33
use crate::api::API;
44

5-
pub fn drop(matches: &ArgMatches<'_>, api: &mut API) -> Result<(), Box<dyn std::error::Error>> {
5+
pub fn drop(matches: &ArgMatches, api: &mut API) -> Result<(), Box<dyn std::error::Error>> {
66
// We can unwrap these because they're required arguments:
77
let machine = matches.value_of("machine").unwrap();
88
let slot = matches.value_of("slot").unwrap();

src/commands/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde_json::{Map, Value};
66
use crate::api::APIError;
77
use crate::api::API;
88

9-
pub fn list(matches: &ArgMatches<'_>, api: &mut API) -> Result<(), Box<dyn std::error::Error>> {
9+
pub fn list(matches: &ArgMatches, api: &mut API) -> Result<(), Box<dyn std::error::Error>> {
1010
let token = api.get_token()?;
1111

1212
let client = HttpClient::new()?;

src/main.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
1-
use clap::{App, Arg, ArgMatches, SubCommand};
1+
use clap::{command, Arg, ArgMatches, Command};
22

33
pub mod api;
44
pub mod commands;
55

66
mod ui;
77

88
fn main() {
9-
let matches = App::new("CLI Drink")
10-
.version("1.0.0")
11-
.author("Mary Strodl <[email protected]>")
9+
let matches = command!("CLI Drink")
1210
.about("Drops drinks from CSH vending machines")
1311
.subcommand(
14-
SubCommand::with_name("list")
12+
Command::new("list")
1513
.about("Display available slots")
1614
.arg(
17-
Arg::with_name("machine")
15+
Arg::new("machine")
1816
.index(1)
1917
.help("Which machine should be listed?")
2018
.required(false),
2119
),
2220
)
2321
.subcommand(
24-
SubCommand::with_name("drop")
22+
Command::new("drop")
2523
.about("Drops a drink")
2624
.arg(
27-
Arg::with_name("machine")
25+
Arg::new("machine")
2826
.index(1)
2927
.help("Machine to drop from")
3028
.required(true),
3129
)
3230
.arg(
33-
Arg::with_name("slot")
31+
Arg::new("slot")
3432
.index(2)
3533
.help("Slot to drop from")
3634
.required(true),
@@ -50,16 +48,20 @@ fn process_command(matches: ArgMatches) -> Result<(), Box<dyn std::error::Error>
5048
} else if let Some(matches) = matches.subcommand_matches("drop") {
5149
return commands::drop::drop(matches, &mut api);
5250
} else {
53-
cli();
51+
cli(&mut api);
5452
return Ok(());
5553
}
5654
}
5755

58-
fn cli() {
59-
60-
let mut api = api::API::new(); // Cheetos.
61-
56+
fn cli(api: &mut api::API) {
6257
ui::ui_common::launch();
63-
ui::machine::pick_machine(&mut api);
64-
ui::ui_common::end();
58+
let task = match ui::machine::pick_machine(api) {
59+
Ok(_) => {
60+
ui::ui_common::end();
61+
}
62+
Err(err) => {
63+
ui::ui_common::end();
64+
eprintln!("{}", err);
65+
}
66+
};
6567
}

src/ui/machine.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use ncurses::*;
22
use crate::ui::inventory;
33
use crate::ui::ui_common;
44
use serde_json::{Map, Value};
5+
use crate::api::APIError;
56
use crate::api;
67

7-
pub fn pick_machine(api: &mut api::API) {
8+
pub fn pick_machine(api: &mut api::API) -> Result<(), Box<dyn std::error::Error>> {
89
/* Get the screen bounds. */
910
let mut max_x = 0;
1011
let mut max_y = 0;
@@ -27,8 +28,14 @@ pub fn pick_machine(api: &mut api::API) {
2728
mvwprintw(win, 1, 2, "SELECT A MACHINE");
2829
mvwprintw(win, 2, 2, "================");
2930

30-
let mut credits = api::API::get_credits(api);
31-
mvwprintw(win, height - 2, width - 20, format!("Credits: {}", credits.unwrap()).as_str());
31+
let mut credits = match api::API::get_credits(api) {
32+
Ok(credits) => credits,
33+
Err(err) => {
34+
eprintln!("{}", err);
35+
return Err(Box::new(APIError::Unauthorized));
36+
}
37+
};
38+
mvwprintw(win, height - 2, width - 20, format!("Credits: {}", credits).as_str());
3239

3340
let machine_status = match api::API::get_machine_status(api) {
3441
Ok(status) => {
@@ -74,10 +81,16 @@ pub fn pick_machine(api: &mut api::API) {
7481
KEY_RIGHT => {
7582
inventory::build_menu(api, &machine_status, selected_machine);
7683
// Refresh credits in case we bought anything.
77-
credits = api::API::get_credits(api);
84+
credits = match api::API::get_credits(api) {
85+
Ok(credits) => credits,
86+
Err(err) => {
87+
eprintln!("{}", err);
88+
return Err(Box::new(APIError::Unauthorized));
89+
}
90+
};
7891
wmove(win, height-2, width-20);
7992
wclrtoeol(win);
80-
mvwprintw(win, height-2, width-20, format!("Credits: {}", credits.unwrap()).as_str());
93+
mvwprintw(win, height-2, width-20, format!("Credits: {}", credits).as_str());
8194
box_(win, 0, 0);
8295
refresh();
8396
wrefresh(win);
@@ -104,6 +117,7 @@ pub fn pick_machine(api: &mut api::API) {
104117
key = getch();
105118
}
106119
ui_common::destroy_win(win);
120+
Ok(())
107121
}
108122
_ => {
109123
endwin();

0 commit comments

Comments
 (0)