aboutsummaryrefslogtreecommitdiff
path: root/ticket/src/main.rs
diff options
context:
space:
mode:
authorMichael Gattozzi <mgattozzi@gmail.com>2019-11-27 17:57:29 -0500
committerMichael Gattozzi <mgattozzi@gmail.com>2019-12-02 15:06:03 -0500
commit0caa9551a904a1ba675fbde70435de6fb0a176d6 (patch)
tree1b6224f031e13e20358f00081ef1ec91f8b118a9 /ticket/src/main.rs
parentfc072f0656ceb99994f1217325aa11f932881d55 (diff)
Add a tui for ticket
This commit sets up a basic tui for the current functionality. It's traversable by keyboard and by mouse and shows the ticket state via tab, info in a row, and the description in it's own box when selected. This is necessary for a good user experience for in repo tools. Files are fine, but interactivity is better.
Diffstat (limited to 'ticket/src/main.rs')
-rw-r--r--ticket/src/main.rs42
1 files changed, 26 insertions, 16 deletions
diff --git a/ticket/src/main.rs b/ticket/src/main.rs
index 7e05adf..4d5457d 100644
--- a/ticket/src/main.rs
+++ b/ticket/src/main.rs
@@ -1,3 +1,7 @@
+mod actions;
+mod tui;
+
+use actions::*;
use anyhow::{
bail,
Result,
@@ -12,17 +16,21 @@ use serde::{
Deserialize,
Serialize,
};
-use shared::find_root;
use std::{
env,
fs,
- path::PathBuf,
process,
process::Command,
};
#[derive(structopt::StructOpt)]
-enum Args {
+struct Args {
+ #[structopt(subcommand)]
+ cmd: Option<Cmd>,
+}
+
+#[derive(structopt::StructOpt)]
+enum Cmd {
/// Initialize the repo to use ticket
Init,
New,
@@ -40,19 +48,25 @@ fn main(args: Args) {
env::set_var("RUST_LOG", "info");
});
pretty_env_logger::init();
- if let Err(e) = match args {
- Args::Init => init(),
- Args::New => new(),
- Args::Show { id } => show(id),
- Args::Close { id } => close(id),
- } {
+
+ if let Some(cmd) = args.cmd {
+ if let Err(e) = match cmd {
+ Cmd::Init => init(),
+ Cmd::New => new(),
+ Cmd::Show { id } => show(id),
+ Cmd::Close { id } => close(id),
+ } {
+ error!("{}", e);
+ std::process::exit(1);
+ }
+ } else if let Err(e) = tui::run() {
error!("{}", e);
std::process::exit(1);
}
}
fn init() -> Result<()> {
- let root = find_root()?.join(".dev-suite").join("ticket");
+ let root = ticket_root()?;
debug!("Creating ticket directory at {}.", root.display());
debug!("Creating open directory.");
fs::create_dir_all(&root.join("open"))?;
@@ -141,10 +155,6 @@ fn new() -> Result<()> {
Ok(())
}
-fn ticket_root() -> Result<PathBuf> {
- Ok(find_root()?.join(".dev-suite").join("ticket"))
-}
-
fn show(id: usize) -> Result<()> {
debug!("Getting ticket root.");
let ticket_root = ticket_root()?;
@@ -236,7 +246,7 @@ fn close(id: usize) -> Result<()> {
}
#[derive(Serialize, Deserialize)]
-struct Ticket {
+pub struct Ticket {
title: String,
status: Status,
number: usize,
@@ -245,7 +255,7 @@ struct Ticket {
}
#[derive(Serialize, Deserialize)]
-enum Status {
+pub enum Status {
Open,
Closed,
}