Fine
}
+ MC::ListAccounts { all } => {
+ let ag = AccountsGuard::lock();
+ let names = if all == Some(true) {
+ let auth = cs.superuser.ok_or(ME::AuthorisationError)?;
+ ag.list_accounts_all(auth.into())
+ } else {
+ let AccountSpecified { notional_account, auth, .. } =
+ cs.account.as_ref().ok_or(ME::SpecifyAccount)?;
+ ag.list_accounts_scope(¬ional_account.scope, *auth)
+ };
+ MR::AccountsList(names)
+ }
+
MC::CreateGame { game, insns } => {
let mut ag = AccountsGuard::lock();
let mut games = games_lock();
self.save_accounts_now()?;
}
+ pub fn list_accounts_all(&self, _: AuthorisationSuperuser)
+ -> Vec<Arc<AccountName>> {
+ let accounts = self.0.as_ref().expect("loaded");
+ accounts.names.keys()
+ .cloned().collect()
+ }
+
+ pub fn list_accounts_scope(&self, scope: &AccountScope,
+ _: Authorisation<AccountName>)
+ -> Vec<Arc<AccountName>> {
+ let accounts = self.0.as_ref().expect("loaded");
+ accounts.names.keys()
+ .filter(|name| &name.scope == scope)
+ .cloned().collect()
+ }
+
#[throws(AccountsSaveError)]
pub fn save_accounts_now(&self) {
let accounts = self.0.as_ref().expect("loaded");
call,
)}
}
+
+//---------- list-accounts ----------
+
+mod list_accounts {
+ use super::*;
+
+ #[derive(Default,Debug)]
+ struct Args {
+ all: bool,
+ }
+
+ fn subargs(sa: &mut Args) -> ArgumentParser {
+ use argparse::*;
+ let mut ap = ArgumentParser::new();
+ ap.refer(&mut sa.all)
+ .add_option(&["--all"],StoreTrue,
+ "user superuser access to list all accounts");
+ ap
+ }
+
+ #[throws(AE)]
+ fn call(_sc: &Subcommand, ma: MainOpts, args: Vec<String>) {
+ let args = parse_args::<Args,_>(args, &subargs, &ok_id, None);
+ let mut conn = connect(&ma)?;
+ let all = Some(args.all);
+ let accounts = match conn.cmd(&MC::ListAccounts { all })? {
+ MR::AccountsList(g) => g,
+ x => throw!(anyhow!("unexpected response to ListAccounts: {:?}", &x)),
+ };
+ for a in accounts {
+ println!("{:?}", a);
+ }
+ }
+
+ inventory::submit!{Subcommand(
+ "list-accounts",
+ "List accounts in your account scope",
+ call,
+ )}
+}
CreateAccount(AccountDetails),
UpdateAccount(AccountDetails),
DeleteAccount(AccountName),
+ ListAccounts { all: Option<bool> },
SelectAccount(AccountName), // success does not mean account exists
CheckAccount, // success *does* mean account exists and we have access
Fine,
Error { error: MgmtError },
AlterGame { error: Option<MgmtError>, responses: Vec<MgmtGameResponse> },
+ AccountsList(Vec<Arc<AccountName>>),
GamesList(Vec<Arc<InstanceName>>),
LibraryItems(Vec<shapelib::ItemEnquiryData>),
}
self.write(&cmd).context("send command")?;
let resp = self.read().context("read response")?;
match &resp {
- Fine | GamesList{..} | LibraryItems(_) => { },
+ Fine | AccountsList{..} | GamesList{..} | LibraryItems(_) => { },
AlterGame { error: None, .. } => { },
Error { error } => {
Err(error.clone()).context(