From f1f45eb31a744b28582c9359af4d502b7845001f Mon Sep 17 00:00:00 2001 From: Richard Lupton Date: Fri, 17 Jul 2020 01:08:17 +0100 Subject: [PATCH] Subcommand to list volumes and their paths Signed-off-by: Richard Lupton --- src/cli.rs | 4 ++++ src/main.rs | 21 +++++++++++++++++++++ src/volumes.rs | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index d9fa808..293a8f4 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -13,6 +13,10 @@ pub(crate) enum Subcommand { #[structopt(name = "pull")] Pull {}, + /// Emit information about volumes + #[structopt(name = "volumes")] + Volume {}, + /// Generate shell completions to stdout. #[structopt(name = "completion")] Completion { diff --git a/src/main.rs b/src/main.rs index e190611..cd79249 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,6 +68,11 @@ fn run_floki_from_args(args: &Cli) -> Result<(), Error> { Ok(Cli::clap().gen_completions_to("floki", *shell, &mut std::io::stdout())) } + Some(Subcommand::Volume {}) => { + list_volumes(&environ, &config); + Ok(()) + } + // Launch an interactive floki shell (the default) None => { let inner_command = config.shell.inner_shell().to_string(); @@ -86,6 +91,22 @@ fn run_floki_container( interpret::run_container(&environ, &config, &inner_command) } +/// Print the volumes used in the current configuration +fn list_volumes(environ: &environment::Environment, config: &FlokiConfig) { + println!("{:20} {:20} {}", "NAME", "MOUNT", "HOSTPATH"); + for (name, volume) in config.volumes.iter() { + let hostpath = + volumes::cache_path(&environ.floki_workspace, &environ.config_file, name, volume); + let mount = &volume.mount; + println!( + "{:20} {:20} {}", + name, + mount.to_string_lossy(), + hostpath.to_string_lossy() + ); + } +} + /// Configure the logger fn configure_logging(verbosity: u8) -> Result<(), Error> { let level = match verbosity { diff --git a/src/volumes.rs b/src/volumes.rs index 8c7789b..f2cfedd 100644 --- a/src/volumes.rs +++ b/src/volumes.rs @@ -24,7 +24,7 @@ pub(crate) fn resolve_volume_mounts<'a>( .collect() } -fn cache_path( +pub(crate) fn cache_path( work_path: &path::PathBuf, config_filepath: &path::PathBuf, name: &str,