-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmod.rs
More file actions
81 lines (65 loc) · 2.16 KB
/
Copy pathmod.rs
File metadata and controls
81 lines (65 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use std::{path::PathBuf, sync::LazyLock};
use clap::{Parser, Subcommand};
use regex::Regex;
use snafu::Snafu;
mod build;
mod completions;
mod image;
pub use build::*;
pub use completions::*;
pub use image::*;
use url::Host;
// This is derived from the general rule where the length of the tag can be up to 128 chars
// See: https://github.com/opencontainers/distribution-spec/blob/main/spec.md
// But that checking needs to be at a higher layer.
static VALID_IMAGE_TAG: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[a-zA-Z0-9_][a-zA-Z0-9_.-]+$").expect("regex is valid"));
#[derive(Debug, Snafu)]
pub enum ParseVendorVersionError {
#[snafu(display("invalid image tag characters for {version:?}"))]
ParseVersion { version: String },
}
#[derive(Debug, Parser)]
#[command(author, version, about)]
pub struct Cli {
/// Path to the configuration file.
#[arg(short, long = "configuration", global = true, default_value_os_t = Self::default_config_path())]
pub config_path: PathBuf,
#[command(subcommand)]
pub command: Command,
}
impl Cli {
fn default_config_path() -> PathBuf {
PathBuf::from("./boil.toml")
}
pub(super) fn default_vendor_version() -> String {
"0.0.0-dev".to_owned()
}
pub(super) fn default_registry() -> HostPort {
HostPort {
host: Host::Domain(String::from("oci.stackable.tech")),
port: None,
}
}
/// Ensure that the given version will be valid for use in the image tag
pub(super) fn parse_vendor_version(version: &str) -> Result<String, ParseVendorVersionError> {
if !VALID_IMAGE_TAG.is_match(version) {
return ParseVersionSnafu { version }.fail();
}
Ok(version.to_owned())
}
}
#[derive(Debug, Subcommand)]
pub enum Command {
/// Build one or more images.
///
/// Requires docker with the buildx extension.
#[command(alias = "some-chicken")]
Build(Box<BuildArguments>),
/// Display various structured outputs in JSON format.
Image(ImageArguments),
/// Alias for `image list`.
Images(ImageListArguments),
/// Generate shell completions.
Completions(CompletionsArguments),
}