瀏覽代碼

Add history incognito flag, minor use after move fix

timvisee 7 年之前
父節點
當前提交
9dd9752333
共有 5 個文件被更改,包括 31 次插入7 次删除
  1. 1 2
      ROADMAP.md
  2. 1 1
      cli/src/action/info.rs
  3. 8 0
      cli/src/cmd/handler.rs
  4. 5 0
      cli/src/cmd/matcher/main.rs
  5. 16 4
      cli/src/history_tool.rs

+ 1 - 2
ROADMAP.md

@@ -1,5 +1,4 @@
 # Release 0.1
-- History use flag
 - Define minimum arguments for options such as `--history`, do not allow empty
 - Update history file TTL and other properties on info fetch
 - Remote file expiry time:
@@ -7,7 +6,6 @@
   - Give all files the default expiry flag if not set (with uncertainty flag)
 - Create history command
 - History compiler flag
-- Incognito mode, to not remember files `--incognito`
 - Automatically get owner token, from file history when setting password
 - Allow file/directory archiving on upload
 - Allow unarchiving on download 
@@ -30,6 +28,7 @@
 - Allow hiding the progress bar, and/or showing simple progress (with `-q`)
 - Implement a quiet `-q` mode
 - Host configuration file for host tags, to easily upload to other hosts
+- History use flag
 
 # Other ideas
 - Rework encrypted reader/writer

+ 1 - 1
cli/src/action/info.rs

@@ -78,7 +78,7 @@ impl<'a> Info<'a> {
             .ok();
 
         // Add the file to the history
-        history_tool::add(&matcher_main, file);
+        history_tool::add(&matcher_main, file.clone());
 
         // Print the result
         println!("ID: {}", file.id());

+ 8 - 0
cli/src/cmd/handler.rs

@@ -81,6 +81,14 @@ impl<'a: 'b, 'b> Handler<'a> {
                 .global(true)
                 .help("History file to use")
                 .default_value(&DEFAULT_HISTORY_FILE))
+            .arg(Arg::with_name("incognito")
+                .long("incognito")
+                .short("i")
+                .alias("incog")
+                .alias("private")
+                .alias("priv")
+                .global(true)
+                .help("Don't update local history for actions"))
             .subcommand(CmdDelete::build())
             .subcommand(CmdDownload::build().display_order(2))
             .subcommand(CmdExists::build())

+ 5 - 0
cli/src/cmd/matcher/main.rs

@@ -45,6 +45,11 @@ impl<'a: 'b, 'b> MainMatcher<'a> {
             ),
         }
     }
+
+    /// Check whether we are incognito from the file history.
+    pub fn incognito(&self) -> bool {
+        self.matches.is_present("incognito")
+    }
 }
 
 impl<'a> Matcher<'a> for MainMatcher<'a> {

+ 16 - 4
cli/src/history_tool.rs

@@ -14,6 +14,12 @@ use util::print_error;
 fn add_error(matcher_main: &MainMatcher, file: RemoteFile)
     -> Result<(), HistoryError>
 {
+    // Ignore if incognito
+    if matcher_main.incognito() {
+        return Ok(());
+    }
+
+    // Load the history, add the file, and save
     let mut history = History::load_or_new(matcher_main.history())?;
     history.add(file);
     history.save().map_err(|err| err.into())
@@ -37,6 +43,12 @@ pub fn add(matcher_main: &MainMatcher, file: RemoteFile) {
 fn remove_error(matcher_main: &MainMatcher, file: &RemoteFile)
     -> Result<bool, HistoryError>
 {
+    // Ignore if incognito
+    if matcher_main.incognito() {
+        return Ok(false);
+    }
+
+    // Load the history, remove the file, and save
     let mut history = History::load_or_new(matcher_main.history())?;
     let removed = history.remove(file);
     history.save()?;
@@ -47,12 +59,12 @@ fn remove_error(matcher_main: &MainMatcher, file: &RemoteFile)
 /// ID, and save it again.
 /// True is returned if any file was removed.
 pub fn remove(matcher_main: &MainMatcher, file: &RemoteFile) -> bool {
-    if let Err(err) = remove_error(matcher_main, file) {
+    let result = remove_error(matcher_main, file);
+    let ok = result.is_ok();
+    if let Err(err) = result {
         print_error(err.context(
             "Failed to remove file from local history, ignoring",
         ));
-        false
-    } else {
-        true
     }
+    ok
 }