Skip to content

Commit 4c8bc09

Browse files
committed
Helpful error message for Docker not being installed
1 parent aad1b66 commit 4c8bc09

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/main.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
mod docker_client;
55
mod rails_new;
66
use rails_new::{Cli, Commands};
7-
use std::{io::Write, process::Command};
7+
use std::{io::Write, process::Command, io::ErrorKind};
88

99
use clap::Parser;
1010

@@ -23,22 +23,31 @@ fn main() {
2323

2424
// Run docker build --build-arg RUBY_VERSION=$RUBY_VERSION --build-arg RAILS_VERSION=$RAILS_VERSION -t rails-new-$RUBY_VERSION-$RAILS_VERSION
2525
// passing the content of DOCKERFILE to the command stdin
26-
let mut child = DockerClient::build_image(
26+
let child = DockerClient::build_image(
2727
&ruby_version,
2828
rails_version,
2929
os_specific::get_user_id(),
3030
os_specific::get_group_id(),
3131
rebuild,
3232
)
33-
.spawn()
34-
.expect("Failed to execute process");
33+
.spawn();
3534

36-
let mut stdin = child.stdin.take().expect("Failed to open stdin");
35+
let mut child_ref = match child {
36+
Ok(child) => child,
37+
Err(error) => {
38+
if error.kind() == ErrorKind::NotFound {
39+
println!("Docker is not installed");
40+
}
41+
std::process::exit(1);
42+
}
43+
};
44+
45+
let mut stdin = child_ref.stdin.take().expect("Failed to open stdin");
3746
std::thread::spawn(move || {
3847
stdin.write_all(os_specific::dockerfile_content()).unwrap();
3948
});
4049

41-
let status = child.wait().expect("failed to wait on child");
50+
let status = child_ref.wait().expect("failed to wait on child");
4251

4352
assert!(status.success());
4453

0 commit comments

Comments
 (0)