diff --git a/README.md b/README.md index c9f2d79..58e50a5 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,14 @@ The built executable is installed into the folder `~/.cargo/bin` by default. ### Docker CLI plugin -Coming soon for integration with the familiar Docker CLI. +Optionally, Wheelsticks can be set up as a Docker CLI plugin. With that, calls +to `wheelsticks deploy` can be replaced by `docker deploy`, which some people +prefer. Example [setup](https://github.com/docker/cli/issues/1534): + +```bash +mkdir --parents ~/.docker/cli-plugins +ln --symbolic "$(which wheelsticks)" ~/.docker/cli-plugins/docker-deploy +``` ## Usage diff --git a/src/docker_cli_plugin_metadata.rs b/src/docker_cli_plugin_metadata.rs new file mode 100644 index 0000000..42aeb71 --- /dev/null +++ b/src/docker_cli_plugin_metadata.rs @@ -0,0 +1,46 @@ +pub fn go() -> anyhow::Result { + let authors = env!("CARGO_PKG_AUTHORS"); + let first_author_name = authors + .split_once(" <") + .ok_or(anyhow::anyhow!("{authors}"))? + .0; + Ok(serde_json::to_string_pretty(&Metadata { + schema_version: "0.1.0".into(), + short_description: env!("CARGO_PKG_DESCRIPTION").into(), + url: env!("CARGO_PKG_HOMEPAGE").into(), + vendor: first_author_name.into(), + version: env!("CARGO_PKG_VERSION").into(), + })?) +} + +#[derive(serde::Serialize)] +#[serde(rename_all = "PascalCase")] +struct Metadata { + schema_version: String, + short_description: String, + #[serde(rename = "URL")] + url: String, + vendor: String, + version: String, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn handles() -> anyhow::Result<()> { + let metadata = go()?; + assert_eq!( + metadata, + r#"{ + "SchemaVersion": "0.1.0", + "ShortDescription": "Zero-downtime deployments for Docker Compose", + "URL": "https://github.com/evolutics/wheelsticks", + "Vendor": "Benjamin Fischer", + "Version": "1.0.0" +}"#, + ); + Ok(()) + } +} diff --git a/src/main.rs b/src/main.rs index bcbdec7..fc36218 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ mod command; mod deploy; mod docker; +mod docker_cli_plugin_metadata; mod log; use clap::Parser; @@ -116,6 +117,12 @@ fn main() -> anyhow::Result<()> { wait_timeout: wait_timeout.map(|wait_timeout| wait_timeout.to_string()), }) } + + Subcommand::DockerCliPluginMetadata => { + let metadata = docker_cli_plugin_metadata::go()?; + println!("{metadata}"); + Ok(()) + } } } @@ -278,8 +285,7 @@ enum ComposeEngine { enum Subcommand { // Source for some arguments: // https://docs.docker.com/engine/reference/commandline/compose_up/ - - // TODO: Support use as plugin (https://github.com/docker/cli/issues/1534). + // /// Create or update services /// /// Builds, (re)creates, and starts containers for a service. @@ -351,6 +357,9 @@ enum Subcommand { service_names: Vec, }, + + #[command(hide = true)] + DockerCliPluginMetadata, } #[derive(Clone, ValueEnum)]