ソースを参照

Do not allow empty owner token input

timvisee 7 年 前
コミット
ab1e715601
2 ファイル変更17 行追加6 行削除
  1. 0 1
      IDEAS.md
  2. 17 5
      cli/src/util.rs

+ 0 - 1
IDEAS.md

@@ -1,5 +1,4 @@
 # Ideas
-- Prompt for owner tokens
 - allow creating non existent directories with the `-f` flag 
 - only allow file extension renaming on upload with `-f` flag
 - no interact flag

+ 17 - 5
cli/src/util.rs

@@ -90,6 +90,7 @@ pub fn set_clipboard(content: String) -> Result<(), Box<StdError>> {
 
 /// Prompt the user to enter a password.
 // TODO: do not prompt if no-interactive
+// TODO: only allow emtpy password if forced
 pub fn prompt_password() -> String {
     match prompt_password_stderr("Password: ") {
         Ok(password) => password,
@@ -123,12 +124,12 @@ pub fn ensure_password(password: &mut Option<String>, needs: bool) {
 }
 
 /// Prompt the user to enter some value.
-/// The prompt that is shown should be passed to `prompt`,
+/// The prompt that is shown should be passed to `msg`,
 /// excluding the `:` suffix.
 // TODO: do not prompt if no-interactive
-pub fn prompt(prompt: &str) -> String {
+pub fn prompt(msg: &str) -> String {
     // Show the prompt
-    eprint!("{}: ", prompt);
+    eprint!("{}: ", msg);
     let _ = stderr().flush();
 
     // Get the input
@@ -139,8 +140,19 @@ pub fn prompt(prompt: &str) -> String {
         ));
     }
 
-    // Trim and return
-    input.trim().into()
+    // Trim
+    let input = input.trim().to_owned();
+
+    // The input must not be empty
+    if input.is_empty() {
+        eprintln!(
+            "Empty input given, which is not allowed. Use {} to cancel.",
+            "[CTRL+C]".yellow(),
+        );
+        return prompt(msg);
+    }
+
+    input
 }
 
 /// Prompt the user to enter an owner token.