Skip to content

Commit a08c140

Browse files
committed
fix: do not fail if fonts directory does not exist (like on NixOS)
Also adds --print-cmd in debug build, and small fixes
1 parent 0f272c8 commit a08c140

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

src/cli.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ pub struct Cli {
1010
#[arg(long)]
1111
pub dry_run: bool,
1212

13+
/// Debug only option to print the parsed options
14+
#[cfg(debug_assertions)]
15+
#[arg(long)]
16+
pub print_cmd: bool,
17+
1318
/// Increase verbosity
1419
#[arg(short, long, value_name = "Error|Warn|Info|Debug|Trace", default_value_t = log::Level::Warn, env = crate::ENV_LOG_LEVEL)]
1520
pub log_level: log::Level,
@@ -74,8 +79,6 @@ const START_HEADING_EXPERIMENTAL: &str = "EXPERIMENTAL";
7479
#[derive(Args, Debug, Clone)]
7580
pub struct CmdStartArgs {
7681
/// Enter shell after container initialization finishes
77-
///
78-
/// Ignored if stdout is not a terminal (ex. a pipe)
7982
#[arg(short = 'E', long, env = crate::ENV_ENTER_ON_START)]
8083
pub enter: bool,
8184

@@ -144,7 +147,7 @@ pub struct CmdStartArgs {
144147
/// Add capabilities, or drop them with by prefixing `!cap`
145148
///
146149
/// For more details about capabilities read `man 7 capabilities`
147-
#[arg(long = "cap", value_name = "[!]CAPABILITY", help_heading = START_HEADING_PERMISSIONS)]
150+
#[arg(long = "cap", value_name = "[!]CAPABILITY", value_delimiter = ',', help_heading = START_HEADING_PERMISSIONS)]
148151
pub capabilities: Vec<String>,
149152

150153
/// File, image or config to use to start a container

src/commands/cmd_start/util.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn get_hostname() -> Result<String> {
1717

1818
// then as a fallback use hostname executable
1919
let cmd = Command::new("hostname")
20-
.output()
20+
.log_output()
2121
.with_context(|| "Could not call hostname")?;
2222

2323
let hostname = String::from_utf8_lossy(&cmd.stdout);
@@ -188,8 +188,14 @@ pub fn mount_wayland(ctx: &Context, cli_args: &CmdStartArgs, cmd: &mut Command)
188188
));
189189
}
190190

191-
// add fonts just in case
192-
cmd.arg("--volume=/usr/share/fonts:/usr/share/fonts/host:ro");
191+
// add fonts if they exist
192+
let system_fonts = Path::new("/usr/share/fonts");
193+
if system_fonts.exists() {
194+
cmd.arg(format!(
195+
"--volume={}:/usr/share/fonts/host:ro",
196+
system_fonts.to_string_lossy()
197+
));
198+
}
193199

194200
// legacy ~/.fonts
195201
let home_dot_fonts = ctx.user_home.join(".fonts");
@@ -202,7 +208,6 @@ pub fn mount_wayland(ctx: &Context, cli_args: &CmdStartArgs, cmd: &mut Command)
202208

203209
// font dir ~/.local/share/fonts
204210
let home_dot_local_fonts = ctx.user_home.join(".local").join("share").join("fonts");
205-
206211
if home_dot_local_fonts.exists() {
207212
cmd.arg(format!(
208213
"--volume={}:/usr/share/fonts/host_local:ro",

src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ fn main() -> Result<()> {
4040
Context::new(args.dry_run, Box::new(engine::Podman))
4141
};
4242

43+
// print parsed options
44+
if cfg!(debug_assertions) {
45+
if args.print_cmd {
46+
dbg!(args);
47+
return Ok(());
48+
}
49+
}
50+
4351
match args.cmd {
4452
CliCommands::Start(x) => commands::start_container(get_ctx()?, x)?,
4553
CliCommands::Shell(x) => commands::open_shell(get_ctx()?, x)?,

0 commit comments

Comments
 (0)