Skip to content

Commit

Permalink
[antlir2][image_test] move help to subcommand
Browse files Browse the repository at this point in the history
Summary:
For more dynamic (in other words, useful) help, move it into the Rust binary.
This doesn't actually make the help more helpful, but opens the door to do so.

Test Plan:
```
❯ buck2 run fbcode//antlir/antlir2/testing/tests:test-rust-boot-centos9[container]
2dae0e08-92fc-404d-a1e1-1516d437dfc6 login: root (automatic login)

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                                                                    ┃
┃  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                                                                               ┃
┃                                                                                    ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
  ╲
   ╲   \_\_    _/_/
    ╲      \__/
           (oo)\_______
           (__)\       )\/\
               ||----w |
               ||     ||

[root@2dae0e08-92fc-404d-a1e1-1516d437dfc6 ~]#
```

Reviewed By: epilatow

Differential Revision: D65823556

fbshipit-source-id: 0d8f938b3c9c79f595114f6d76025802c2d83ff4
  • Loading branch information
vmagro authored and facebook-github-bot committed Nov 13, 2024
1 parent 56272ea commit 5b69325
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 52 deletions.
6 changes: 6 additions & 0 deletions antlir/antlir2/testing/image_test/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ rust_binary(
"clap",
"serde",
"tempfile",
"textwrap",
"tracing",
"tracing-subscriber",
":image_test_lib",
Expand Down Expand Up @@ -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"],
)
Expand Down
53 changes: 1 addition & 52 deletions antlir/antlir2/testing/image_test/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
# 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

cat <<EOF
________________________________________________________________________________
/ 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 /
--------------------------------------------------------------------------------
\\
\\ \_\_ _/_/
\\ \__/
(oo)\_______
(__)\ )\/\\
||----w |
|| ||
EOF
/__antlir2_image_test__/image-test shell-help
3 changes: 3 additions & 0 deletions antlir/antlir2/testing/image_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use anyhow::Result;
use clap::Parser;

mod runtime;
mod shell_help;
mod spawn;

pub(crate) use runtime::RuntimeSpec;
Expand All @@ -17,6 +18,7 @@ pub(crate) use runtime::RuntimeSpec;
enum Args {
/// Spawn a container to run the test
Spawn(spawn::Args),
ShellHelp(shell_help::Args),
}

fn main() -> Result<()> {
Expand All @@ -26,5 +28,6 @@ fn main() -> Result<()> {

match args {
Args::Spawn(a) => a.run(),
Args::ShellHelp(a) => a.run(),
}
}
81 changes: 81 additions & 0 deletions antlir/antlir2/testing/image_test/src/shell_help.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
}

0 comments on commit 5b69325

Please sign in to comment.