diff --git a/Cargo.toml b/Cargo.toml index 679e76b..b8c8fc3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "neocities_cli" version = "0.1.3" -author = ["Jacob Benison "] +authors = ["Jacob Benison"] description = "A CLI tool for managing websites hosted on Neocities." keywords = ["neocities", "webmaster", "open-source", "static-site"] repository = "https://github.com/ge3224/neocities" diff --git a/src/client/delete.rs b/src/client/delete.rs index 84b931e..37aebd9 100644 --- a/src/client/delete.rs +++ b/src/client/delete.rs @@ -38,43 +38,46 @@ impl Delete { fn warning( &self, - args: &Vec, + args: Vec, mut writer: impl std::io::Write, ) -> Result { - let intro = - format!("\x1b[93mWarning.\x1b[0m Are you sure you want to delete the following files?"); - self.write(intro.as_str(), &mut writer)?; + let warn = "\x1b[93mWarning.\x1b[0m Are you sure you want to delete the following files?\n"; + self.write(warn, &mut writer)?; for (i, arg) in args.iter().enumerate() { - let item = format!("{}: \x1b[92m{}\x1b[0m", i + 1, arg); + let item = format!("{}: \x1b[92m{}\x1b[0m\n", i + 1, arg); self.write(item.as_str(), &mut writer)?; } - self.write("Please input either Y or N.", &mut writer)?; + self.write("Please input either Y or N.\n", &mut writer)?; + + let mut cancel_delete = true; loop { let mut input = String::new(); - io::stdin().read_line(&mut input).unwrap(); + io::stdin().read_line(&mut input)?; let input = input.trim(); match input { "Y" | "y" => { - self.write("Ok. Continuing with delete of files.", &mut writer)?; + self.write("Ok. Continuing with delete of files.\n", &mut writer)?; + cancel_delete = false; break; } "N" | "n" => { - self.write("Canceling delete operation.", &mut writer)?; - return Ok(false); + self.write("Canceling delete operation.\n", &mut writer)?; + break; } _ => { - let err = format!("Invalid input: '{}'. Please try again.", input); + let err = format!("Invalid input: '{}'. Please try again.\n", input); self.write(err.as_str(), &mut writer)?; } } } - Ok(true) + + Ok(cancel_delete) } } @@ -83,7 +86,7 @@ impl Executable for Delete { let mut stdout = std::io::stdout(); if args.len() < 1 { - let output = format!("\n{}\nusage: {}\n", self.get_long_desc(), self.get_usage()); + let output = format!("{}\nusage: {}\n", self.get_long_desc(), self.get_usage()); self.write(output.as_str(), &mut stdout)?; return Ok(()); } @@ -93,11 +96,14 @@ impl Executable for Delete { return Ok(()); } - let proceed = self.warning(&args, &mut stdout)?; + let cancel = self.warning(args[..].to_vec(), &mut stdout)?; - if proceed == true { + if cancel == false { let data = NcDelete::fetch(args)?; - let output = format!("{} - {}", data.result, data.message); + let output = format!( + "\x1b[93mStatus\x1b[0m: {} - {}\n", + data.result, data.message + ); self.write(output.as_str(), &mut stdout)?; } diff --git a/src/client/key.rs b/src/client/key.rs index 9061e86..63e0bfb 100644 --- a/src/client/key.rs +++ b/src/client/key.rs @@ -47,7 +47,7 @@ impl Key { mut writer: impl std::io::Write, ) -> Result, NeocitiesErr> { if let Some(key) = cred.get_api_key() { - let output = format!("{KEY_SET_MSG}: {}", key); + let output = format!("{KEY_SET_MSG}\n{}\n", key); writer.write_all(output.as_bytes())?; return Ok(None); } @@ -106,9 +106,8 @@ const DESC: &'static str = "Retrieve an API Key for your Neocities user account" const DESC_SHORT: &'static str = "Neocities API Key"; -const KEY_SET_MSG: &'static str = " -Your Neocities API key has already been set for the NEOCITIES_KEY environment variable -"; +const KEY_SET_MSG: &'static str = + "Your Neocities API key is already set on your local machine, $NEOCITIES_KEY:"; const USE_KEY_MSG: &'static str = " Use your API key by setting the following environment variable: diff --git a/src/client/list.rs b/src/client/list.rs index 03505b7..7b69aac 100644 --- a/src/client/list.rs +++ b/src/client/list.rs @@ -32,8 +32,7 @@ impl List { } fn write(&self, msg: &str, mut writer: impl std::io::Write) -> Result<(), NeocitiesErr> { - let output = format!("\n{}\n", msg); - writer.write_all(output.as_bytes())?; + writer.write_all(msg.as_bytes())?; Ok(()) } @@ -75,7 +74,7 @@ impl List { } } } else { - self.write("No files were found", &mut writer)?; + self.write("No files were found\n", &mut writer)?; }; Ok(()) @@ -104,10 +103,10 @@ impl List { let output: String; if is_dir { - output = format!("{}{}/\x1b[90m {}\x1b[0m", self.dir_color, path, date); + output = format!("{}{}/\x1b[90m {}\x1b[0m\n", self.dir_color, path, date); } else { output = format!( - "{}{}\x1b[0m ({})\x1b[90m {}\x1b[0m", + "{}{}\x1b[0m ({})\x1b[90m {}\x1b[0m\n", self.file_color, path, file_size, date ); } @@ -124,9 +123,9 @@ impl List { ) -> Result<(), NeocitiesErr> { let output: String; if is_dir { - output = format!("{}{}/\x1b[0m", self.dir_color, path); + output = format!("{}{}/\x1b[0m\n", self.dir_color, path); } else { - output = format!("{}{}\x1b[0m", self.file_color, path,); + output = format!("{}{}\x1b[0m\n", self.file_color, path,); } self.write(output.as_str(), &mut writer)?; diff --git a/src/client/upload.rs b/src/client/upload.rs index 953e630..ad2e074 100644 --- a/src/client/upload.rs +++ b/src/client/upload.rs @@ -32,7 +32,7 @@ impl Upload { } fn write(&self, msg: &str, mut writer: impl std::io::Write) -> Result<(), NeocitiesErr> { - let output = format!("\n{}\n", msg); + let output = format!("{}", msg); writer.write_all(output.as_bytes())?; Ok(()) } @@ -42,7 +42,10 @@ impl Upload { res: UploadResponse, mut writer: impl std::io::Write, ) -> Result<(), NeocitiesErr> { - let output = format!("\n{} - {}\n", &res.result, &res.message); + let output = format!( + "\x1b[93mStatus\x1b[0m: {} - {}\n", + &res.result, &res.message + ); writer.write_all(output.as_bytes())?; Ok(()) } @@ -53,7 +56,7 @@ impl Executable for Upload { let mut stdout = std::io::stdout(); if args.len() < 1 { - let output = format!("{}\nusage: {}", self.get_long_desc(), self.get_usage()); + let output = format!("{}\nusage: {}\n", self.get_long_desc(), self.get_usage()); self.write(output.as_str(), &mut stdout)?; return Ok(()); } diff --git a/src/client/version.rs b/src/client/version.rs index 712dc60..d3b1ad6 100644 --- a/src/client/version.rs +++ b/src/client/version.rs @@ -4,8 +4,6 @@ use std::io; /// The string literal a user must type to run functionality in this module pub const KEY: &'static str = "version"; -const DESC: &'static str = "Show the version number of the neocities client"; -const DESC_SHORT: &'static str = "Show neocities version"; /// An implementation of `Executable` that outputs the version of this `neocities_cli` application pub struct Version { @@ -53,6 +51,9 @@ impl Executable for Version { } } +const DESC: &'static str = "Show the version number of this Neocities client"; +const DESC_SHORT: &'static str = "Show neocities version"; + #[cfg(test)] mod tests { use super::{Version, DESC, DESC_SHORT, KEY}; diff --git a/tests/fixtures/bar.js b/tests/fixtures/bar.js new file mode 100644 index 0000000..b1b2aab --- /dev/null +++ b/tests/fixtures/bar.js @@ -0,0 +1 @@ +console.log("foo bar baz"); diff --git a/tests/fixtures/images/baz.jpg b/tests/fixtures/images/baz.jpg new file mode 100644 index 0000000..6223c62 Binary files /dev/null and b/tests/fixtures/images/baz.jpg differ