Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the export functionality #13

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
68a4ec2
Adding in the export library
rogeruiz Oct 30, 2022
2ef967a
Adding a basic export method that adds numbers
rogeruiz Oct 30, 2022
2807b2a
Continue making little steps;
rogeruiz Nov 1, 2022
03f9e41
Deleting the internal library;
rogeruiz Nov 2, 2022
843f826
Bring in the code organization; 🏗️
rogeruiz Nov 2, 2022
251c108
Cleaning things up a bit, but understanding more;
rogeruiz Nov 2, 2022
d435986
Converting the Result<T,E> to Option<T>;
rogeruiz Nov 5, 2022
a923ef4
Refactoring the run_export func; 🎉
rogeruiz Nov 5, 2022
2f9678c
Making progress by adding progress; 😉
rogeruiz Nov 5, 2022
6bdafe3
Adding some nice comments for later;
rogeruiz Nov 7, 2022
9d653d8
Removing all the formatters I won't be using;
rogeruiz Feb 5, 2023
bd9b444
Updating the deps;
rogeruiz Feb 5, 2023
2e8a488
Making path inputs PathBuf instead;
rogeruiz Feb 5, 2023
cc2c569
Get the `export` subcommand working;
rogeruiz Feb 5, 2023
ce18822
Getting rid of warnings while I'm developing;
rogeruiz Feb 5, 2023
605daa3
Improving the error handling for --workspace;
rogeruiz Feb 5, 2023
377c7b9
Making things more legible for `run_export()`;
rogeruiz Feb 5, 2023
484ecee
Adding in the `anyhow` crate for better errors;
rogeruiz Feb 5, 2023
8ef6388
Updating the error to Unsupported;
rogeruiz Feb 5, 2023
0bd0733
Attempting to use `anyhow`
rogeruiz Feb 5, 2023
fc19dbe
Capturing the error & output from Docker
rogeruiz Feb 18, 2023
d40a8c3
Trying another spinner for now
rogeruiz Feb 18, 2023
e3cbdc6
Cleaning up code and adding comments
rogeruiz Feb 18, 2023
7eb238a
Better error messaging from Scuttle
rogeruiz Feb 18, 2023
ad03469
Adding colors to custom Scuttle errors;
rogeruiz Feb 18, 2023
f70ee6f
Validating the output directory;
rogeruiz Feb 20, 2023
d9e9b15
Cleaning up my match statements;
rogeruiz Feb 20, 2023
367bfc9
Picking a different status spinner
rogeruiz Feb 20, 2023
2a7b8e2
Adding the start of documentation; 📝
rogeruiz Feb 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Bring in the code organization; 🏗️
  • Loading branch information
rogeruiz committed Nov 2, 2022
commit 843f826835baf35933c3f6a73e236e4c0b1ac66f
9 changes: 1 addition & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -20,4 +20,6 @@ edition = "2021"
[dependencies]
clap = { version = "4.0.18", features = ["derive"] }

scuttle_export = { path = "scuttle_export" }
bollard = "0.13.0"
futures-util = "0.3.25"
tokio = { version = "1.21.2", features = ["full"] }
16 changes: 16 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pub mod structurizr {

#[derive(Copy, Clone, PartialEq, Eq, clap::ValueEnum)]
pub enum Formatters {
PlantUML,
PlantUMLStructurizr,
PlantUMLC4,
Mermaid,
WebSequence,
Ilograph,
DOT,
JSON,
DSL,
Theme,
}
}
88 changes: 88 additions & 0 deletions src/export.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// mod constants;
// use crate::constants::structurizr;

pub mod command {

// use std::path::PathBuf;

use bollard::container::{Config, RemoveContainerOptions};
use bollard::models::HostConfig;
use bollard::Docker;

use bollard::exec::{CreateExecOptions, StartExecResults};
use bollard::image::CreateImageOptions;
use futures_util::stream::StreamExt;
use futures_util::TryStreamExt;

const IMAGE: &str = "structurizr/cli:latest";

#[tokio::main]
pub async fn run_docker(// workspace: PathBuf,
// format: structurizr::Formatters,
) -> Result<(), Box<dyn std::error::Error + 'static>> {
let docker = Docker::connect_with_socket_defaults().unwrap();

docker
.create_image(
Some(CreateImageOptions {
from_image: IMAGE,
..Default::default()
}),
None,
None,
)
.try_collect::<Vec<_>>()
.await?;

let cli_config = Config {
image: Some(IMAGE),
tty: Some(true),
host_config: Some(HostConfig {
auto_remove: Some(true),
..Default::default()
}),
..Default::default()
};

let id = docker
.create_container::<&str, &str>(None, cli_config)
.await?
.id;
docker.start_container::<String>(&id, None).await?;

// non interactive
let exec = docker
.create_exec(
&id,
CreateExecOptions {
attach_stdout: Some(true),
attach_stderr: Some(true),
cmd: Some(vec!["structurizr.sh", ""]),
..Default::default()
},
)
.await?
.id;
if let StartExecResults::Attached { mut output, .. } =
docker.start_exec(&exec, None).await?
{
while let Some(Ok(msg)) = output.next().await {
print!("{}", msg);
}
} else {
unreachable!();
}

docker
.remove_container(
&id,
Some(RemoveContainerOptions {
force: true,
..Default::default()
}),
)
.await?;

Ok(())
}
}
42 changes: 15 additions & 27 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::path::PathBuf;
mod constants;
mod export;

use crate::constants::structurizr;
use crate::export::command;

use clap::{Parser, Subcommand, ValueEnum};
use std::path::PathBuf;

use scuttle_export;
use clap::{Parser, Subcommand};

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
@@ -11,20 +15,6 @@ struct Cli {
command: Option<Commands>,
}

#[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]
enum Formatters {
PlantUML,
PlantUMLStructurizr,
PlantUMLC4,
Mermaid,
WebSequence,
Ilograph,
DOT,
JSON,
DSL,
Theme,
}

#[derive(Subcommand)]
enum Commands {
/// The export command exports DSL files into specified formatted files using Structurizr-CLI
@@ -34,8 +24,8 @@ enum Commands {
workspace: PathBuf,

/// A format that Structurizr-CLI supports
#[arg(short, long, value_enum, default_value_t = Formatters::PlantUML)]
formatter: Formatters,
#[arg(short, long, value_enum, default_value_t = structurizr::Formatters::PlantUML)]
format: structurizr::Formatters,

/// A file path for PlantUML files to be exported to
#[arg(short, long)]
@@ -44,8 +34,8 @@ enum Commands {
/// The render command renders DSL files into PNG files using a specific format
Render {
/// A format that Structurizr-CLI supports
#[arg(short, long, value_enum, default_value_t = Formatters::PlantUML)]
formatter: Formatters,
#[arg(short, long, value_enum, default_value_t = structurizr::Formatters::PlantUML)]
format: structurizr::Formatters,

/// Input file path for files
#[arg(short, long)]
@@ -59,15 +49,13 @@ fn main() {
match cli.command {
Some(Commands::Export {
workspace,
formatter,
format,
output,
}) => {
println!("The workspace is {:?}", workspace.as_path());
println!("The formatter is {:?}", formatter.to_possible_value());
println!("The output is {:?}", output.unwrap_or(PathBuf::from(".")));
scuttle_export::export();
// scuttle_export::run_docker(workspace, format, output);
export::command::run_docker();
}
Some(Commands::Render { input, formatter }) => {
Some(Commands::Render { input, format }) => {
todo!()
}
None => {}