prepare_game(&self.su().ds, &self.prctx, TABLE)?;
let command = self.su().ds.ss(
- "library-list @table@ wikimedia chess-yellow-?"
+ "library-list @table@ chess-yellow-?"
)?;
let output: String = self.otter(&command)?.into();
assert!( Regex::new("(?m)^wikimedia *chess-yellow-K *the yellow king$")?
"got: {}", &output);
let command = self.su().ds.ss(
- "library-add @table@ wikimedia chess-blue-?"
+ "library-add --lib wikimedia @table@ chess-blue-?"
)?;
let added = self.some_library_add(&command)?;
assert_eq!(added.len(), 6);
let st = Command::new("cmp").args(&[&bundle_file, "00000.zip"]).status()?;
if ! st.success() { panic!("cmp failed {}", st) }
- let command = ds.ss("library-add @table@ lemon example-lemon")?;
+ let command = ds.ss("library-add --lib lemon @table@ example-lemon")?;
let added = self.some_library_add(&command)?;
assert_eq!( added.len(), 1 );
MR::Libraries(libs)
}
- MC::LibraryListByGlob { game, glob: spec } => {
+ MC::LibraryListByGlob { game, lib, pat } => {
let (ag, gref) = start_access_game(&game)?;
let (results, _auth) =
access_bundles(
cs,&ag,&gref, &[TP::UploadBundles],
&mut |ig, _| {
let regs = ig.all_shapelibs();
- let libs = regs.lib_name_lookup(&spec.lib)?;
let mut results: Vec<shapelib::ItemEnquiryData> = default();
- for lib in &*libs {
- results.extend(lib.list_glob(&spec.item)?);
+ let libss = if let Some(lib) = &lib {
+ vec![regs.lib_name_lookup(lib)?]
+ } else {
+ regs.all_libs().collect()
+ };
+ for libs in libss {
+ for lib in libs {
+ results.extend(lib.list_glob(&pat)?);
+ }
}
Ok(results)
})?;
//---------- library-list ----------
-#[derive(Debug)]
+#[derive(Debug,Default)]
struct LibGlobArgs {
table_name: String,
- pat: shapelib::ItemSpec,
+ lib: Option<String>,
+ pat: Option<String>,
}
-impl Default for LibGlobArgs { fn default() -> Self { Self {
- table_name: default(),
- pat: shapelib::ItemSpec { lib: default(), item: default() },
-} } }
-
impl LibGlobArgs {
fn add_arguments<'ap, 'tlg: 'ap>(
&'tlg mut self,
use argparse::*;
ap.refer(&mut self.table_name).required()
.add_argument("TABLE-NAME",Store,"table name");
- // xxx allow lack of library name to list library names
- ap.refer(&mut self.pat.lib).required()
- .add_argument("LIB-NAME",Store,"library name");
- // xxx allow lack of pattern to list whole library
- ap.refer(&mut self.pat.item).required()
- .add_argument("ITEM-GLOB-PATTERN",Store,"item glob pattern");
+ ap.refer(&mut self.lib).metavar("LIBRARY")
+ .add_option(&["--lib"],StoreOption,"look only in LIBRARY");
+ ap.refer(&mut self.pat)
+ .add_argument("ITEM-GLOB-PATTERN",StoreOption,"item glob pattern");
+ }
+
+ fn lib(&self) -> Option<String> {
+ self.lib.clone()
+ }
+ fn pat(&self) -> String {
+ self.pat.as_ref().map(Deref::deref)
+ .unwrap_or("*")
+ .into()
}
}
let args = parse_args::<Args,_>(args, &subargs, &ok_id, None);
let mut chan = access_game(&ma, &args.table_name)?;
- let items = chan.list_items(&args.pat)?;
+ if args.lib.is_none() && args.pat.is_none() {
+ let game = chan.game.clone();
+ let libs = match chan.cmd(&MC::LibraryListLibraries { game })? {
+ MgmtResponse::Libraries(libs) => libs,
+ x => throw!(anyhow!(
+ "unexpected response to LibrarylistLibraries: {:?}", &x)),
+ };
+ for lib in libs {
+ println!("{}", lib);
+ }
+ return;
+ }
+
+ let items = chan.list_items(args.lib.clone(), args.pat())?;
for it in &items {
println!("{}", it);
}
}
}
- let items = chan.list_items(&args.tlg.pat)?;
+ let items = chan.list_items(args.tlg.lib(), args.tlg.pat())?;
let mut exitcode = 0;
let mut insns = vec![];
}
};
let spec = shapelib::ItemSpec {
- lib: args.tlg.pat.lib.clone(),
+ lib: it.libname.clone(),
item: it.itemname.as_str().to_owned(),
};
let spec = PiecesSpec {
}
#[throws(AE)]
- pub fn list_items(&mut self, pat: &shapelib::ItemSpec)
+ pub fn list_items(&mut self, lib: Option<String>, pat: String)
-> Vec<shapelib::ItemEnquiryData> {
// xxx allow globbing of library names
let cmd = MgmtCommand::LibraryListByGlob {
game: self.game.clone(),
- glob: pat.clone(),
+ lib, pat,
};
let mut items = match self.cmd(&cmd)? {
MgmtResponse::LibraryItems(items) => items,