Skip to content

Commit

Permalink
Remove requirement of -go-package from typeshare with go feature (#184)
Browse files Browse the repository at this point in the history
* Remove requirement of -go-package from typeshare with go feature

Add check to see if no package flag is passed or in typeshare.toml

Fmt fix

clippy fix

Cleanup logic and make it cleaner

fix logic

fix return value

cargo clippy fix

Cleanup function

fix logic of go_package function

update logic for error handling

fix logic to correctly return package name

Capitalize all variant names when configuration specifies so in Go

Signed-off-by: Omar Miraj <[email protected]>

Add support for Kotlin inline value classes

Signed-off-by: Omar Miraj <[email protected]>

Introduce redacted typeshare parameter

Signed-off-by: Omar Miraj <[email protected]>

keep the file output deterministic

Signed-off-by: Omar Miraj <[email protected]>

Deterministic output

I want to use a parallel iterator while walking the input folders however in order to maintain a deterministic output I'll have to keep the crate to parsed data sorted along with the types within each parsed data. Consequently the tests have been updated since they did not have this sorting before.

Signed-off-by: Omar Miraj <[email protected]>

Add determinism ensurance tests

Signed-off-by: Omar Miraj <[email protected]>

chore: update changelog and bump version numbers for release v1.10.0-beta.7

Signed-off-by: Omar Miraj <[email protected]>

Explicitly format variant types in Go

Signed-off-by: Omar Miraj <[email protected]>

Remove dead code and switch if else to match

Signed-off-by: Omar Miraj <[email protected]>

Add check to see if no package flag is passed or in typeshare.toml

Fmt fix

Signed-off-by: Omar Miraj <[email protected]>

Cleanup logic and make it cleaner

update logic for error handling

fix logic to correctly return package name

Capitalize all variant names when configuration specifies so in Go

Signed-off-by: Omar Miraj <[email protected]>

keep the file output deterministic

Deterministic output

I want to use a parallel iterator while walking the input folders however in order to maintain a deterministic output I'll have to keep the crate to parsed data sorted along with the types within each parsed data. Consequently the tests have been updated since they did not have this sorting before.

Signed-off-by: Omar Miraj <[email protected]>

Explicitly format variant types in Go

Signed-off-by: Omar Miraj <[email protected]>

Remove dead code and switch if else to match

Signed-off-by: Omar Miraj <[email protected]>

* make the package check more idiomatic

* fix merge conflict regression

---------

Signed-off-by: Omar Miraj <[email protected]>
  • Loading branch information
MOmarMiraj authored Aug 28, 2024
1 parent 132c639 commit a905fc1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
2 changes: 2 additions & 0 deletions cli/data/tests/go_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[go]
package="testPackage"
8 changes: 8 additions & 0 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,12 @@ mod test {

assert_eq!(config.swift.prefix, "test");
}
#[test]
#[cfg(feature = "go")]
fn go_package_test() {
let path = config_file_path("go_config.toml");
let config = load_config(Some(path)).unwrap();

assert_eq!(config.go.package, "testPackage");
}
}
28 changes: 20 additions & 8 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn main() -> anyhow::Result<()> {
.long("go-package")
.help("Go package name")
.takes_value(true)
.required_if(ARG_TYPE, "go"),
.required(false),
);
}

Expand All @@ -63,10 +63,10 @@ fn main() -> anyhow::Result<()> {

let config_file = options.value_of(ARG_CONFIG_FILE_NAME);
let config = config::load_config(config_file).context("Unable to read configuration file")?;
let config = override_configuration(config, &options);
let config = override_configuration(config, &options)?;

if options.is_present(ARG_GENERATE_CONFIG) {
let config = override_configuration(Config::default(), &options);
let config = override_configuration(Config::default(), &options)?;
let file_path = options.value_of(ARG_CONFIG_FILE_NAME);
config::store_config(&config, file_path).context("Failed to create new config file")?;
}
Expand Down Expand Up @@ -196,7 +196,7 @@ fn language(
}

/// Overrides any configuration values with provided arguments
fn override_configuration(mut config: Config, options: &ArgMatches) -> Config {
fn override_configuration(mut config: Config, options: &ArgMatches) -> anyhow::Result<Config> {
if let Some(swift_prefix) = options.value_of(ARG_SWIFT_PREFIX) {
config.swift.prefix = swift_prefix.to_string();
}
Expand All @@ -222,15 +222,17 @@ fn override_configuration(mut config: Config, options: &ArgMatches) -> Config {
}

#[cfg(feature = "go")]
if let Some(go_package) = options.value_of(args::ARG_GO_PACKAGE) {
config.go.package = go_package.to_string();
{
if let Some(go_package) = options.value_of(args::ARG_GO_PACKAGE) {
config.go.package = go_package.to_string();
}
assert_go_package_present(&config)?;
}

config.target_os = options
.get_many::<String>(ARG_TARGET_OS)
.map(|arg| arg.into_iter().map(ToString::to_string).collect::<Vec<_>>())
.unwrap_or_default();
config
Ok(config)
}

/// Prints out all parsing errors if any and returns Err.
Expand All @@ -255,3 +257,13 @@ fn check_parse_errors(parsed_crates: &BTreeMap<CrateName, ParsedData>) -> anyhow
Ok(())
}
}

#[cfg(feature = "go")]
fn assert_go_package_present(config: &Config) -> anyhow::Result<()> {
if config.go.package.is_empty() {
return Err(anyhow!(
"Please provide a package name in the typeshare.toml or using --go-package <package name>"
));
}
Ok(())
}
7 changes: 3 additions & 4 deletions core/src/rust_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,9 @@ pub enum RustType {
/// - `SomeStruct<String>`
/// - `SomeEnum<u32>`
/// - `SomeTypeAlias<(), &str>`
///
/// However, there are some generic types that are considered to be _special_. These
/// include `Vec<T>` `HashMap<K, V>`, and `Option<T>`, which are part of `SpecialRustType` instead
/// of `RustType::Generic`.
/// However, there are some generic types that are considered to be _special_. These
/// include `Vec<T>` `HashMap<K, V>`, and `Option<T>`, which are part of `SpecialRustType` instead
/// of `RustType::Generic`.
///
/// If a generic type is type-mapped via `typeshare.toml`, the generic parameters will be dropped automatically.
Generic {
Expand Down

0 comments on commit a905fc1

Please sign in to comment.