aboutsummaryrefslogtreecommitdiff
path: root/ticket/src/actions.rs
diff options
context:
space:
mode:
authorMichael Gattozzi <mgattozzi@gmail.com>2019-12-13 15:42:16 -0500
committerMichael Gattozzi <mgattozzi@gmail.com>2019-12-13 15:42:16 -0500
commit8161a5742ff361d19b6dc4a3373d1135bbbff82e (patch)
tree57d90f770658d5266d3ac974ac7ca540df1051fd /ticket/src/actions.rs
parentb32b1478dec75cc8282036bae56097a1e29fb47f (diff)
Refactor ticket to use common methods
While this had already been done with `src/actions.rs` before not everything had been updated and new commands had been added since then to the cli tool. This commit fixes things up quite a bit and simplifies some of the code as a result.
Diffstat (limited to 'ticket/src/actions.rs')
-rw-r--r--ticket/src/actions.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/ticket/src/actions.rs b/ticket/src/actions.rs
index b6d8cb0..d2ebf24 100644
--- a/ticket/src/actions.rs
+++ b/ticket/src/actions.rs
@@ -1,4 +1,5 @@
use crate::{
+ Status,
Ticket,
TicketV0,
};
@@ -117,3 +118,30 @@ pub fn uuid_v1() -> Result<Uuid> {
&[random(), random(), random(), random(), random(), random()],
)?)
}
+
+#[allow(clippy::needless_pass_by_value)]
+pub fn save_ticket(ticket: Ticket) -> Result<()> {
+ fs::write(ticket_path(&ticket)?, toml::to_string_pretty(&ticket)?)?;
+ Ok(())
+}
+
+pub fn ticket_file_name(ticket: &Ticket) -> String {
+ let mut name = ticket
+ .title
+ .split_whitespace()
+ .collect::<Vec<&str>>()
+ .join("-");
+ name.push_str(".toml");
+ name = name.to_lowercase();
+ name
+}
+
+pub fn ticket_path(ticket: &Ticket) -> Result<PathBuf> {
+ Ok(
+ match ticket.status {
+ Status::Open => open_tickets()?,
+ Status::Closed => closed_tickets()?,
+ }
+ .join(ticket_file_name(&ticket)),
+ )
+}