chiark / gitweb /
accounts: Allow otter prep_access_account to never update it
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 2 Jun 2021 16:13:42 +0000 (17:13 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 2 Jun 2021 17:06:26 +0000 (18:06 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otter.rs
src/commands.rs

index c74e3b692338a445becfa6d5e29497a41bd21b06..e43cfb505c3d89e9ffae7a79ba018a49dd23ddb0 100644 (file)
@@ -120,7 +120,7 @@ impl MainOpts {
   #[throws(AE)]
   fn access_account(&self) -> Conn {
     let mut conn = connect(self)?;
-    conn.prep_access_account(self)?;
+    conn.prep_access_account(self, true)?;
     conn
   }
 
@@ -566,7 +566,8 @@ deref_to_field_mut!{Conn, MgmtChannel, chan}
 
 impl Conn {
   #[throws(AE)]
-  fn prep_access_account(&mut self, ma: &MainOpts) {
+  fn prep_access_account(&mut self, ma: &MainOpts,
+                         maybe_update_account: bool) {
     #[derive(Debug)]
     struct Wantup(bool);
     impl Wantup {
@@ -576,12 +577,15 @@ impl Conn {
       }
     }
     let mut wantup = Wantup(false);
-    let mut ad = AccountDetails {
+
+    let mut ad = if maybe_update_account { AccountDetails {
       account:  ma.account.clone(),
       nick:     wantup.u(&ma.nick),
       timezone: wantup.u(&ma.timezone),
       layout:   wantup.u(&ma.layout),
       access:   wantup.u(&ma.access).map(Into::into),
+    } } else {
+      AccountDetails::default(ma.account.clone())
     };
 
     fn is_no_account<T>(r: &Result<T, anyhow::Error>) -> bool {
index d4e4d23fc3ec1779bda1156fcbaad95e2c706e1d..83e59c36a5e81ea7b0177480c041379e6d589a61 100644 (file)
@@ -280,6 +280,13 @@ pub enum MgmtError {
   #[error("command forbides account specified")]     AccountSpecified,
 }
 
+impl AccountDetails {
+  pub fn default(account: AccountName) -> AccountDetails { AccountDetails {
+    account,
+    nick: None, timezone: None, layout: None, access: None,
+  } }
+}
+
 impl From<InternalError> for MgmtError {
   fn from(e: InternalError) -> MgmtError {
     MgmtError::ServerFailure(format!("internal error: {}", &e))