Skip to content

Commit a905fc1

Browse files
authored
Remove requirement of -go-package from typeshare with go feature (1Password#184)
* 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 <omar.miraj@agilebits.com> Add support for Kotlin inline value classes Signed-off-by: Omar Miraj <omar.miraj@agilebits.com> Introduce redacted typeshare parameter Signed-off-by: Omar Miraj <omar.miraj@agilebits.com> keep the file output deterministic Signed-off-by: Omar Miraj <omar.miraj@agilebits.com> 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 <omar.miraj@agilebits.com> Add determinism ensurance tests Signed-off-by: Omar Miraj <omar.miraj@agilebits.com> chore: update changelog and bump version numbers for release v1.10.0-beta.7 Signed-off-by: Omar Miraj <omar.miraj@agilebits.com> Explicitly format variant types in Go Signed-off-by: Omar Miraj <omar.miraj@agilebits.com> Remove dead code and switch if else to match Signed-off-by: Omar Miraj <omar.miraj@agilebits.com> Add check to see if no package flag is passed or in typeshare.toml Fmt fix Signed-off-by: Omar Miraj <omar.miraj@agilebits.com> 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 <omar.miraj@agilebits.com> 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 <omar.miraj@agilebits.com> Explicitly format variant types in Go Signed-off-by: Omar Miraj <omar.miraj@agilebits.com> Remove dead code and switch if else to match Signed-off-by: Omar Miraj <omar.miraj@agilebits.com> * make the package check more idiomatic * fix merge conflict regression --------- Signed-off-by: Omar Miraj <omar.miraj@agilebits.com>
1 parent 132c639 commit a905fc1

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

cli/data/tests/go_config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[go]
2+
package="testPackage"

cli/src/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,12 @@ mod test {
180180

181181
assert_eq!(config.swift.prefix, "test");
182182
}
183+
#[test]
184+
#[cfg(feature = "go")]
185+
fn go_package_test() {
186+
let path = config_file_path("go_config.toml");
187+
let config = load_config(Some(path)).unwrap();
188+
189+
assert_eq!(config.go.package, "testPackage");
190+
}
183191
}

cli/src/main.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn main() -> anyhow::Result<()> {
4646
.long("go-package")
4747
.help("Go package name")
4848
.takes_value(true)
49-
.required_if(ARG_TYPE, "go"),
49+
.required(false),
5050
);
5151
}
5252

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

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

6868
if options.is_present(ARG_GENERATE_CONFIG) {
69-
let config = override_configuration(Config::default(), &options);
69+
let config = override_configuration(Config::default(), &options)?;
7070
let file_path = options.value_of(ARG_CONFIG_FILE_NAME);
7171
config::store_config(&config, file_path).context("Failed to create new config file")?;
7272
}
@@ -196,7 +196,7 @@ fn language(
196196
}
197197

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

224224
#[cfg(feature = "go")]
225-
if let Some(go_package) = options.value_of(args::ARG_GO_PACKAGE) {
226-
config.go.package = go_package.to_string();
225+
{
226+
if let Some(go_package) = options.value_of(args::ARG_GO_PACKAGE) {
227+
config.go.package = go_package.to_string();
228+
}
229+
assert_go_package_present(&config)?;
227230
}
228-
229231
config.target_os = options
230232
.get_many::<String>(ARG_TARGET_OS)
231233
.map(|arg| arg.into_iter().map(ToString::to_string).collect::<Vec<_>>())
232234
.unwrap_or_default();
233-
config
235+
Ok(config)
234236
}
235237

236238
/// Prints out all parsing errors if any and returns Err.
@@ -255,3 +257,13 @@ fn check_parse_errors(parsed_crates: &BTreeMap<CrateName, ParsedData>) -> anyhow
255257
Ok(())
256258
}
257259
}
260+
261+
#[cfg(feature = "go")]
262+
fn assert_go_package_present(config: &Config) -> anyhow::Result<()> {
263+
if config.go.package.is_empty() {
264+
return Err(anyhow!(
265+
"Please provide a package name in the typeshare.toml or using --go-package <package name>"
266+
));
267+
}
268+
Ok(())
269+
}

core/src/rust_types.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,9 @@ pub enum RustType {
156156
/// - `SomeStruct<String>`
157157
/// - `SomeEnum<u32>`
158158
/// - `SomeTypeAlias<(), &str>`
159-
///
160-
/// However, there are some generic types that are considered to be _special_. These
161-
/// include `Vec<T>` `HashMap<K, V>`, and `Option<T>`, which are part of `SpecialRustType` instead
162-
/// of `RustType::Generic`.
159+
/// However, there are some generic types that are considered to be _special_. These
160+
/// include `Vec<T>` `HashMap<K, V>`, and `Option<T>`, which are part of `SpecialRustType` instead
161+
/// of `RustType::Generic`.
163162
///
164163
/// If a generic type is type-mapped via `typeshare.toml`, the generic parameters will be dropped automatically.
165164
Generic {

0 commit comments

Comments
 (0)