diff --git a/antlir/antlir2/testing/image_test/BUCK b/antlir/antlir2/testing/image_test/BUCK index c7aafff69d..4306434296 100644 --- a/antlir/antlir2/testing/image_test/BUCK +++ b/antlir/antlir2/testing/image_test/BUCK @@ -24,6 +24,7 @@ rust_binary( "clap", "serde", "tempfile", + "textwrap", "tracing", "tracing-subscriber", ":image_test_lib", @@ -55,6 +56,11 @@ feature.new( dst = "/etc/profile.d/zz-help.sh", mode = "a+rx", ), + feature.ensure_dirs_exist(dirs = "/__antlir2_image_test__"), + feature.install( + src = ":image-test", + dst = "/__antlir2_image_test__/image-test", + ), ], visibility = ["PUBLIC"], ) diff --git a/antlir/antlir2/testing/image_test/help.sh b/antlir/antlir2/testing/image_test/help.sh index df52d67f4a..5aa1f3a3f6 100644 --- a/antlir/antlir2/testing/image_test/help.sh +++ b/antlir/antlir2/testing/image_test/help.sh @@ -4,55 +4,4 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -# Generated with: -# -# cowsay -f moose -W 80 < Result<()> { @@ -26,5 +28,6 @@ fn main() -> Result<()> { match args { Args::Spawn(a) => a.run(), + Args::ShellHelp(a) => a.run(), } } diff --git a/antlir/antlir2/testing/image_test/src/shell_help.rs b/antlir/antlir2/testing/image_test/src/shell_help.rs new file mode 100644 index 0000000000..3f23b632e4 --- /dev/null +++ b/antlir/antlir2/testing/image_test/src/shell_help.rs @@ -0,0 +1,81 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +use anyhow::Result; +use clap::Parser; + +#[derive(Parser, Debug)] +pub(crate) struct Args {} + +const MESSAGE: &str = r#" +This is an antlir2 booted image test. + +Press ^] three times within 1s to kill the container. + +You have been auto-logged in to a root console. Feel free to mess around here, +any changes you make will be thrown away when the container exits. + +Soon, this will be populated with a copy-pasteable command, but for now... + +To run your test interactively: + +In another shell on your host: + +'buck2 build --show-full-output $test[inner_test]' + +In this shell: + +Run the binary at that path printed above +EOF +"#; + +const WIDTH: usize = 80; +const PADDING: usize = 2; + +const MOOSE: &str = r#" ╲ + ╲ \_\_ _/_/ + ╲ \__/ + (oo)\_______ + (__)\ )\/\ + ||----w | + || || +"#; + +impl Args { + pub(crate) fn run(self) -> Result<()> { + let wrapped = textwrap::wrap(MESSAGE, WIDTH); + let mut buf = String::with_capacity(MESSAGE.len() + (4 * WIDTH * wrapped.len())); + buf.push('┏'); + for _ in 0..(WIDTH + PADDING * 2) { + buf.push('━'); + } + buf.push('┓'); + buf.push('\n'); + for line in wrapped { + buf.push('┃'); + for _ in 0..PADDING { + buf.push(' '); + } + buf.push_str(&line); + let padding = WIDTH - line.len() + PADDING; + for _ in 0..padding { + buf.push(' '); + } + buf.push('┃'); + buf.push('\n'); + } + buf.push('┗'); + for _ in 0..(WIDTH + PADDING * 2) { + buf.push('━'); + } + buf.push('┛'); + buf.push('\n'); + buf.push_str(MOOSE); + println!("{}", buf); + Ok(()) + } +}