Skip to content

Commit

Permalink
adding small cli
Browse files Browse the repository at this point in the history
  • Loading branch information
noahgift committed Mar 27, 2023
1 parent 4bca547 commit e1188e7
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
9 changes: 9 additions & 0 deletions distroless-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "distcli"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = {version="4.0.32", features=["derive"]}
8 changes: 8 additions & 0 deletions distroless-cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM rust:1.67.1 as build-env
WORKDIR /app
COPY . /app
RUN cargo build --release

FROM gcr.io/distroless/cc
COPY --from=build-env /app/target/release/distcli /
CMD ["./distcli"]
15 changes: 15 additions & 0 deletions distroless-cli/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
format:
cargo fmt --quiet

lint:
@rustup component add clippy 2> /dev/null
cargo clippy --quiet

test:
cargo test --quiet


run:
cargo run -- greet --name bob

all: format lint test run
3 changes: 3 additions & 0 deletions distroless-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Run the 27mb binary do this:

`docker run -it --rm 61503cf1e0b3 ./distcli greet --name bob`
28 changes: 28 additions & 0 deletions distroless-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//A command-line tool to play Marco Polo
use clap::Parser;

#[derive(Parser)]
#[clap(version = "1.0", author = "Noah Gift", about = "hello world")]
struct Cli {
#[clap(subcommand)]
command: Option<Commands>,
}

#[derive(Parser)]
enum Commands {
#[clap(version = "1.0", author = "Noah Gift")]
Greet {
#[clap(short, long)]
name: String,
},
}

fn main() {
let args = Cli::parse();
match args.command {
Some(Commands::Greet { name }) => {
println!("Hello, {}!", name);
}
None => println!("No subcommand was used"),
}
}

0 comments on commit e1188e7

Please sign in to comment.