-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de8d731
commit e7e3982
Showing
64 changed files
with
10,167 additions
and
211 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "cargo-pulumi-gen" | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
clap.workspace = true | ||
pulumi_wasm_generator.workspace = true | ||
anyhow.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
use anyhow::{Context, Result}; | ||
use clap::{Parser, Subcommand}; | ||
|
||
use std::fs; | ||
use std::path::Path; | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(version, about, long_about = None)] | ||
struct App { | ||
#[clap(subcommand)] | ||
command: Command, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum Command { | ||
GenProvider { | ||
#[arg(short, long)] | ||
schema: String, | ||
|
||
#[arg(short, long)] | ||
output: String, | ||
|
||
#[arg(short, long)] | ||
remove: Option<bool>, | ||
}, | ||
GenRust { | ||
#[arg(short, long)] | ||
schema: String, | ||
|
||
#[arg(short, long)] | ||
output: String, | ||
|
||
#[arg(short, long)] | ||
remove: Option<bool>, | ||
}, | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let args = App::parse(); | ||
|
||
match args.command { | ||
Command::GenProvider { | ||
schema, | ||
output: destination, | ||
remove, | ||
} => { | ||
check_if_schema_exists(schema.as_ref())?; | ||
check_if_not_empty(destination.as_ref(), remove)?; | ||
pulumi_wasm_generator::generate_wasm_provider(schema.as_ref(), destination.as_ref())?; | ||
} | ||
Command::GenRust { | ||
schema, | ||
output: destination, | ||
remove, | ||
} => { | ||
check_if_schema_exists(schema.as_ref())?; | ||
check_if_not_empty(destination.as_ref(), remove)?; | ||
pulumi_wasm_generator::generate_rust_library(schema.as_ref(), destination.as_ref())?; | ||
} | ||
}; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn check_if_schema_exists(schema: &Path) -> Result<()> { | ||
if !schema.exists() { | ||
Err(anyhow::anyhow!( | ||
"Schema file [{}] does not exist", | ||
schema.display() | ||
)) | ||
} else if !schema.is_file() { | ||
Err(anyhow::anyhow!( | ||
"Schema [{}] is not a file", | ||
schema.display() | ||
)) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
|
||
fn check_if_not_empty(output_directory: &Path, remove: Option<bool>) -> Result<()> { | ||
let remove = remove.unwrap_or(false); | ||
if output_directory.exists() && remove { | ||
fs::remove_dir_all(output_directory).context(format!( | ||
"Cannot remove directory [{}]", | ||
output_directory.display() | ||
))?; | ||
} | ||
fs::create_dir_all(output_directory).context(format!( | ||
"Cannot create directory [{}]", | ||
output_directory.display() | ||
))?; | ||
let is_empty = output_directory | ||
.read_dir() | ||
.context(format!( | ||
"Cannot read directory [{}]", | ||
output_directory.display() | ||
))? | ||
.next() | ||
.is_none(); | ||
if !is_empty { | ||
Err(anyhow::anyhow!( | ||
"Directory \"{}\" is not empty", | ||
output_directory.display() | ||
)) | ||
} else { | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Proper way of getting package schema: https://github.com/pulumi/pulumi/blob/2366960ae545d31c52f1e9a6b8b35184511c3b84/pkg/cmd/pulumi/package_extract_schema.go#L28 | ||
|
||
Basically: | ||
1. Download executable | ||
2. Use GRPC request GetSchema |
Oops, something went wrong.