feat: add logo, tty

This commit is contained in:
2020-11-22 01:12:12 +08:00
parent 3d7cbb0d65
commit b3d6a603d6
4 changed files with 35 additions and 0 deletions

View File

@@ -37,6 +37,11 @@ Other commands:
$ dockerbuild :rustc --version
```
Hide logo:
```shell
$ LOGO=off dockerbuild :rustc --version
```
Docker official images:
https://hub.docker.com/_/rust

12
dockerbuild.logo.txt Normal file
View File

@@ -0,0 +1,12 @@
{color1} ___ ___ {color2} ___ ___ ___ {colore}
{color1} ( ) ( ) {color2} ( ) .-. ( ) ( ){colore}
{color1} .-.| | .--. .--. | | ___ .--. ___ .-. {color2} | |.-. ___ ___ ( __) | | .-.| | {colore}
{color1} / \ | / \ / \ | | ( ) / \ ( ) \ {color2} | / \ ( )( ) (''") | | / \ | {colore}
{color1}| .-. | | .-. ; | .-. ; | | ' / | .-. ; | ' .-. ; {color2} | .-. | | | | | | | | | | .-. | {colore}
{color1}| | | | | | | | | |(___) | |,' / | | | | | / (___){color2} | | | | | | | | | | | | | | | | {colore}
{color1}| | | | | | | | | | | . '. | |/ | | | {color2} | | | | | | | | | | | | | | | | {colore}
{color1}| | | | | | | | | | ___ | | `. \ | ' _.' | | {color2} | | | | | | | | | | | | | | | | {colore}
{color1}| ' | | | ' | | | '( ) | | \ \ | .'.-. | | {color2} | ' | | | | ; ' | | | | | ' | | {colore}
{color1}' `-' / ' `-' / ' `-' | | | \ . ' `-' / | | {color2} ' `-' ; ' `-' / | | | | ' `-' / {colore}
{color1} `.__,' `.__.' `.__,' (___ ) (___) `.__.' (___) {color2} `.__. '.__.' (___) (___) `.__,' {colore}

View File

@@ -19,6 +19,7 @@ pub struct DockerCmd {
docker_run_gid: Option<u32>,
volumns: Vec<(String, String)>,
mirror: Option<String>,
tty: bool,
}
#[allow(dead_code)]
@@ -27,6 +28,7 @@ impl DockerCmd {
success!("Docker image: {}", docker_name);
Self {
docker_name: docker_name.into(),
tty: true,
..Default::default()
}
}
@@ -51,6 +53,11 @@ impl DockerCmd {
self
}
pub fn tty(&mut self, tty: bool) -> &mut Self {
self.tty = tty;
self
}
pub fn add_volumn(&mut self, outer_vol: &str, docker_vol: &str) -> &mut Self {
self.volumns.push((outer_vol.into(), docker_vol.into()));
self
@@ -60,6 +67,9 @@ impl DockerCmd {
let mut cmd = Command::new(DOCKER_CMD);
cmd.arg("run");
cmd.arg("--rm");
if self.tty {
cmd.arg("-t");
}
cmd.arg("--user");
cmd.arg(&format!("{}:{}",
self.docker_run_uid.unwrap_or_else(|| users::get_current_uid() as u32),

View File

@@ -12,6 +12,14 @@ use rust_util::util_file;
use docker_util::DockerCmd;
fn main() {
let is_display_logo = std::env::var("LOGO").ok().unwrap_or_else(|| "show".into());
if vec!["on", "yes", "display", "show"].iter().any(|v| **v == is_display_logo) {
println!("{}", include_str!("../dockerbuild.logo.txt")
.replace("{color1}", "\x1B[1m\x1B[91m")
.replace("{colore}", "\x1B[0m")
.replace("{color2}", "\x1B[32m")
);
}
information!("{} v{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
let docker_build_config = config::load_docker_build_config_or_default();