Skip to content

Commit

Permalink
add azure-autorust bin (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctaggart authored Jul 5, 2022
1 parent 62d0b85 commit 872e58a
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 101 deletions.
1 change: 1 addition & 0 deletions services/autorust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
members = [
"codegen",
"openapi",
"azure-autorust",
]
10 changes: 10 additions & 0 deletions services/autorust/azure-autorust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "azure-autorust"
version = "0.1.0"
authors = ["Cameron Taggart <[email protected]>"]
edition = "2021"
publish = false

[dependencies]
autorust_codegen = { path = "../codegen" }
clap = { version = "3.2.7", features = ["derive"] }
112 changes: 112 additions & 0 deletions services/autorust/azure-autorust/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// cargo run --release -p azure-autorust

use autorust_codegen::{
crates::{list_crate_names, list_dirs},
gen::gen_crate,
get_mgmt_readmes, get_svc_readmes,
jinja::{CargoToml, CheckAllServicesYml, PublishSdksYml, PublishServicesYml},
Result, RunConfig,
};
use clap::Parser;

#[derive(Debug, clap::Parser)]
struct Args {
/// Generate the publish GitHub workflows
#[clap(long)]
publish: bool,
}

fn main() -> Result<()> {
let args = Args::parse();
gen_mgmt()?;
gen_svc()?;
gen_services_workspace()?;
gen_workflow_check_all_services()?;
if args.publish {
gen_workflow_publish_sdks()?;
gen_workflow_publish_services()?;
}
Ok(())
}

fn gen_mgmt() -> Result<()> {
const OUTPUT_FOLDER: &str = "../mgmt";
const ONLY_SERVICES: &[&str] = &[];
let run_config = &mut RunConfig::new("azure_mgmt_");
for (i, spec) in get_mgmt_readmes()?.iter().enumerate() {
if !ONLY_SERVICES.is_empty() {
if ONLY_SERVICES.contains(&spec.spec()) {
println!("{} {}", i + 1, spec.spec());
gen_crate(spec, run_config, OUTPUT_FOLDER)?;
}
} else {
println!("{} {}", i + 1, spec.spec());
gen_crate(spec, run_config, OUTPUT_FOLDER)?;
}
}
Ok(())
}

fn gen_svc() -> Result<()> {
const OUTPUT_FOLDER: &str = "../svc";
const ONLY_SERVICES: &[&str] = &[];
let run_config = &mut RunConfig::new("azure_svc_");
for (i, spec) in get_svc_readmes()?.iter().enumerate() {
if !ONLY_SERVICES.is_empty() {
if ONLY_SERVICES.contains(&spec.spec()) {
println!("{} {}", i + 1, spec.spec());
gen_crate(spec, run_config, OUTPUT_FOLDER)?;
}
} else {
println!("{} {}", i + 1, spec.spec());
gen_crate(spec, run_config, OUTPUT_FOLDER)?;
}
}
Ok(())
}

fn gen_services_workspace() -> Result<()> {
let dirs = list_dirs()?;
let dirs: Vec<String> = dirs.iter().map(|dir| dir.as_str().replace('\\', "/").replace("../", "")).collect();

let yml = CargoToml { dirs };
yml.create("../Cargo.toml")?;
Ok(())
}

fn gen_workflow_check_all_services() -> Result<()> {
let packages = list_crate_names()?;
let packages = &packages.iter().map(String::as_str).collect();

let yml = CheckAllServicesYml { packages };
yml.create("../../.github/workflows/check-all-services.yml")?;
Ok(())
}

fn gen_workflow_publish_sdks() -> Result<()> {
let packages = &vec![
"azure_core",
"azure_data_cosmos",
"azure_data_tables",
"azure_identity",
"azure_iot_hub",
"azure_messaging_eventgrid",
"azure_messaging_servicebus",
"azure_security_keyvault",
"azure_storage",
"azure_storage_blobs",
"azure_storage_datalake",
"azure_storage_queues",
];
let yml = PublishSdksYml { packages };
yml.create("../../.github/workflows/publish-sdks.yml")?;
Ok(())
}

fn gen_workflow_publish_services() -> Result<()> {
let packages = list_crate_names()?;
let packages = &packages.iter().map(String::as_str).collect();
let yml = PublishServicesYml { packages };
yml.create("../../.github/workflows/publish-services.yml")?;
Ok(())
}
23 changes: 0 additions & 23 deletions services/autorust/codegen/examples/gen_mgmt.rs

This file was deleted.

23 changes: 0 additions & 23 deletions services/autorust/codegen/examples/gen_svc.rs

This file was deleted.

55 changes: 0 additions & 55 deletions services/autorust/codegen/examples/gen_workspace.rs

This file was deleted.

0 comments on commit 872e58a

Please sign in to comment.