Skip to content

Commit dcf5a40

Browse files
authored
refactor(boil)!: Refactor internal code structure (#1451)
* refactor(boil)!: Refactor internal code structure This also restructures the CLI interface slightly: - `boil show images` is now `boil image list` - `boil images` is an alias for `boil image list` This is done in preparation for an upcoming `boil image check` command. * chore: Add dev comment about commented out unit tests * chore: Add dev comment linking to upstream PR * chore: Add doc comment to ImageSelector struct
1 parent f12fcf4 commit dcf5a40

19 files changed

Lines changed: 171 additions & 159 deletions

rust/boil/README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ boil build airflow opa
2626

2727
# Display a list of all images and their declared versions as structured JSON
2828
# output
29-
boil show images
29+
boil image list
3030

3131
# Display a list of versions of the image located in the 'airflow' folder
32-
boil show images airflow
33-
34-
# Soon (hopefully) implemented
35-
boil show graph
32+
boil image list airflow
3633
```
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ use snafu::{ResultExt, Snafu, ensure};
1010
use strum::EnumDiscriminants;
1111
use url::Host;
1212

13-
use crate::build::{
13+
use crate::core::{
1414
docker::BuildArgument,
15-
image::Image,
15+
image::ImageSelector,
1616
platform::{Architecture, TargetPlatform},
1717
};
1818

1919
#[derive(Debug, Args)]
2020
pub struct BuildArguments {
2121
/// The image(s) which should be build. The format is name[=version,...].
2222
#[arg(help_heading = "Image Options", required = true)]
23-
pub images: Vec<Image>,
23+
pub images: Vec<ImageSelector>,
2424

2525
// NOTE (@Techassi): Should this maybe be renamed to vendor_version?
2626
/// The image version being built.

rust/boil/src/cli/completions.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use clap::{Args, ValueEnum};
2+
3+
#[derive(Debug, Args)]
4+
pub struct CompletionsArguments {
5+
/// Shell to generate completions for.
6+
#[arg(value_enum)]
7+
pub shell: Shell,
8+
}
9+
10+
#[derive(Clone, Debug, ValueEnum)]
11+
pub enum Shell {
12+
/// Bourne Again SHell
13+
Bash,
14+
15+
/// Elvish shell
16+
Elvish,
17+
18+
/// Friendly Interactive SHell
19+
Fish,
20+
21+
/// Z SHell
22+
Zsh,
23+
24+
/// Nushell
25+
Nushell,
26+
}
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
use clap::{Args, ValueEnum};
1+
use clap::{Args, Subcommand, ValueEnum};
22

3-
use crate::build::image::Image;
3+
use crate::core::image::ImageSelector;
44

55
#[derive(Debug, Args)]
6-
pub struct ShowImagesArguments {
6+
pub struct ImageArguments {
7+
#[command(subcommand)]
8+
pub command: ImageCommand,
9+
}
10+
11+
#[derive(Debug, Subcommand)]
12+
pub enum ImageCommand {
13+
List(ImageListArguments),
14+
}
15+
16+
#[derive(Debug, Args)]
17+
pub struct ImageListArguments {
718
/// Optionally specify one or more images to display.
8-
pub image: Vec<Image>,
19+
pub image: Vec<ImageSelector>,
920

1021
/// Pretty print the structured output.
1122
#[arg(long, value_enum, default_value_t = Pretty::default())]
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ use std::path::PathBuf;
22

33
use clap::{Parser, Subcommand};
44

5-
use crate::{build::cli::BuildArguments, completions::CompletionsArguments, show::ShowArguments};
5+
mod build;
6+
mod completions;
7+
mod image;
8+
9+
pub use build::*;
10+
pub use completions::*;
11+
pub use image::*;
612

713
#[derive(Debug, Parser)]
814
#[command(author, version, about)]
@@ -30,7 +36,10 @@ pub enum Command {
3036
Build(Box<BuildArguments>),
3137

3238
/// Display various structured outputs in JSON format.
33-
Show(ShowArguments),
39+
Image(ImageArguments),
40+
41+
/// Alias for `image list`.
42+
Images(ImageListArguments),
3443

3544
/// Generate shell completions.
3645
Completions(CompletionsArguments),
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@ use std::{
66
use snafu::{OptionExt, ResultExt, Snafu, ensure};
77

88
use crate::{
9-
build::{bakefile::Bakefile, cli::BuildArguments},
9+
cli::BuildArguments,
1010
config::Config,
11+
core::bakefile::{self, Bakefile},
1112
utils::CommandExt,
1213
};
1314

14-
pub mod bakefile;
15-
pub mod cli;
16-
pub mod docker;
17-
pub mod image;
18-
pub mod platform;
19-
2015
#[derive(Debug, Snafu)]
2116
pub enum Error {
2217
#[snafu(display("failed to create bakefile"))]
Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,11 @@
1-
use clap::{Args, Command, CommandFactory, ValueEnum};
1+
use clap::{Command, CommandFactory};
22
use clap_complete::{
33
Generator,
44
Shell::{Bash, Elvish, Fish, Zsh},
55
};
66
use clap_complete_nushell::Nushell;
77

8-
use crate::cli::Cli;
9-
10-
#[derive(Debug, Args)]
11-
pub struct CompletionsArguments {
12-
/// Shell to generate completions for.
13-
#[arg(value_enum)]
14-
pub shell: Shell,
15-
}
16-
17-
#[derive(Clone, Debug, ValueEnum)]
18-
pub enum Shell {
19-
/// Bourne Again SHell
20-
Bash,
21-
22-
/// Elvish shell
23-
Elvish,
24-
25-
/// Friendly Interactive SHell
26-
Fish,
27-
28-
/// Z SHell
29-
Zsh,
30-
31-
/// Nushell
32-
Nushell,
33-
}
8+
use crate::cli::{Cli, CompletionsArguments, Shell};
349

3510
/// This is the `boil completions` command handler function.
3611
pub fn run_command(arguments: CompletionsArguments) {
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@ use std::{collections::BTreeMap, io::IsTerminal};
33
use snafu::{ResultExt, Snafu};
44

55
use crate::{
6-
build::bakefile::{Targets, TargetsError, TargetsOptions},
7-
show::images::cli::{Pretty, ShowImagesArguments},
6+
cli::{ImageListArguments, Pretty},
7+
core::bakefile::{self, Targets, TargetsOptions},
88
};
99

10-
pub mod cli;
11-
1210
#[derive(Debug, Snafu)]
1311
pub enum Error {
1412
#[snafu(display("failed to serialize list as JSON"))]
1513
SerializeList { source: serde_json::Error },
1614

1715
#[snafu(display("failed to build list of targets"))]
18-
BuildTargets { source: TargetsError },
16+
BuildTargets { source: bakefile::TargetsError },
1917
}
2018

2119
/// This is the `boil show images` command handler function.
22-
pub fn run_command(arguments: ShowImagesArguments) -> Result<(), Error> {
20+
pub fn list_images(arguments: ImageListArguments) -> Result<(), Error> {
2321
let list: BTreeMap<_, _> = if arguments.image.is_empty() {
2422
Targets::all(TargetsOptions { only_entry: true })
2523
.context(BuildTargetsSnafu)?

rust/boil/src/cmd/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod build;
2+
pub mod completions;
3+
pub mod image;

rust/boil/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::Deserialize;
44
use snafu::{ResultExt, Snafu};
55
use url::Url;
66

7-
use crate::build::docker::BuildArguments;
7+
use crate::core::docker;
88

99
#[derive(Debug, Snafu)]
1010
pub enum ConfigError {
@@ -16,7 +16,7 @@ pub enum ConfigError {
1616
#[derive(Debug, Deserialize)]
1717
#[serde(rename_all = "kebab-case")]
1818
pub struct Config {
19-
pub build_arguments: BuildArguments,
19+
pub build_arguments: docker::BuildArguments,
2020
pub metadata: Metadata,
2121
}
2222

0 commit comments

Comments
 (0)