Repository: 1Password/typeshare
Pull request #46 (2023-01-01 15:14:40)

Correct the command line options in the docs
`-l` works but `-t` doesn't. The interactive help says to use `-l`.

```
⬢[chris@toolbox figma-rust]$ typeshare -l typescript -o typescript.ts .
⬢[chris@toolbox figma-rust]$ typeshare -t typescript -o typescript.ts .
error: Found argument '-t' which wasn't expected, or isn't valid in this context

	If you tried to supply `-t` as a value rather than a flag, use `-- -t`

USAGE:
    typeshare [OPTIONS] [directories]...
    typeshare <SUBCOMMAND>

For more information try --help
⬢[chris@toolbox figma-rust]$ typeshare --help
typeshare 1.0.1
Command Line Tool for generating language files with typeshare

USAGE:
    typeshare [OPTIONS] [directories]...
    typeshare <SUBCOMMAND>

ARGS:
    <directories>...    Directories within which to recursively find and process rust files

OPTIONS:
    -c, --config-file <CONFIGFILENAME>
            Configuration file for typeshare

    -g, --generate-config-file
            Generates a configuration file based on the other options specified. The file will be
            written to typeshare.toml by default or to the file path specified by the --config-file
            option.

    -h, --help
            Print help information

    -j, --java-package <JAVAPACKAGE>
            JAVA package name

    -l, --lang <TYPE>
            Language of generated types [possible values: kotlin, swift, typescript]

    -m, --module-name <MODULENAME>
            Kotlin serializer module name

    -o, --output-file <output-file>
            File to write output to. mtime will be preserved if the file contents don't change

    -s, --swift-prefix <SWIFTPREFIX>
            Prefix for generated Swift types

    -V, --version
            Print version information

SUBCOMMANDS:
    completions    Generate shell completions
    help           Print this message or the help of the given subcommand(s)
```


InquisitivePenguin: Thank you!
InquisitivePenguin: @ccouzens Would you be able to sign your commit?

Patch:
diff --git a/core/src/language/kotlin.rs b/core/src/language/kotlin.rs
index cb399a5..f40e507 100644
--- a/core/src/language/kotlin.rs
+++ b/core/src/language/kotlin.rs
@@ -309,7 +309,7 @@ impl Kotlin {
             .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
         write!(
             w,
-            "\tval {}: {}{}",
+            "\tvar {}: {}{}",
             remove_dash_from_identifier(&f.id.renamed),
             ty,
             (f.has_default && !f.ty.is_optional())
diff --git a/docs/src/usage/configuration.md b/docs/src/usage/configuration.md
index 9c2deb9..5b75a4d 100644
--- a/docs/src/usage/configuration.md
+++ b/docs/src/usage/configuration.md
@@ -4,7 +4,7 @@ The behaviour of Typeshare can be customized by either passing options on the co
 
 ## Command Line Options
 
-- `-t`, `--type` 
+- `-l`, `--lang`
     (Required) The language you want your definitions to be generated in. Currently, this option can be set to either `kotlin`, `swift`, `go`, or `typescript`.
 - `-o`, `--output-file`
     (Required) The file path to which the generated definitions will be written.


Test patch:
diff --git a/core/data/tests/anonymous_struct_with_rename/output.kt b/core/data/tests/anonymous_struct_with_rename/output.kt
index 29c9fa1..3a925b8 100644
--- a/core/data/tests/anonymous_struct_with_rename/output.kt
+++ b/core/data/tests/anonymous_struct_with_rename/output.kt
@@ -12,26 +12,26 @@ import kotlinx.serialization.*
 /// Generated type representing the anonymous struct variant `List` of the `AnonymousStructWithRename` Rust enum
 @Serializable
 data class AnonymousStructWithRenameListInner (
-	val list: List<String>
+	var list: List<String>
 )
 
 /// Generated type representing the anonymous struct variant `LongFieldNames` of the `AnonymousStructWithRename` Rust enum
 @Serializable
 data class AnonymousStructWithRenameLongFieldNamesInner (
-	val some_long_field_name: String,
-	val and: Boolean,
-	val but_one_more: List<String>
+	var some_long_field_name: String,
+	var and: Boolean,
+	var but_one_more: List<String>
 )
 
 /// Generated type representing the anonymous struct variant `KebabCase` of the `AnonymousStructWithRename` Rust enum
 @Serializable
 data class AnonymousStructWithRenameKebabCaseInner (
 	@SerialName("another-list")
-	val another_list: List<String>,
+	var another_list: List<String>,
 	@SerialName("camelCaseStringField")
-	val camelCaseStringField: String,
+	var camelCaseStringField: String,
 	@SerialName("something-else")
-	val something_else: Boolean
+	var something_else: Boolean
 )
 
 @Serializable
diff --git a/core/data/tests/can_apply_prefix_correctly/output.kt b/core/data/tests/can_apply_prefix_correctly/output.kt
index 641639d..9767240 100644
--- a/core/data/tests/can_apply_prefix_correctly/output.kt
+++ b/core/data/tests/can_apply_prefix_correctly/output.kt
@@ -11,7 +11,7 @@ import kotlinx.serialization.*
 
 @Serializable
 data class ItemDetailsFieldValue (
-	val hello: String
+	var hello: String
 )
 
 @Serializable
diff --git a/core/data/tests/can_generate_generic_enum/output.kt b/core/data/tests/can_generate_generic_enum/output.kt
index 2baaaa0..c5f8013 100644
--- a/core/data/tests/can_generate_generic_enum/output.kt
+++ b/core/data/tests/can_generate_generic_enum/output.kt
@@ -11,7 +11,7 @@ import kotlinx.serialization.*
 
 @Serializable
 data class StructUsingGenericEnum (
-	val enum_field: GenericEnum<String, Short>
+	var enum_field: GenericEnum<String, Short>
 )
 
 @Serializable
@@ -40,27 +40,27 @@ sealed class GenericEnumUsingGenericEnum<T> {
 /// Generated type representing the anonymous struct variant `VariantF` of the `GenericEnumsUsingStructVariants` Rust enum
 @Serializable
 data class GenericEnumsUsingStructVariantsVariantFInner<T> (
-	val action: T
+	var action: T
 )
 
 /// Generated type representing the anonymous struct variant `VariantG` of the `GenericEnumsUsingStructVariants` Rust enum
 @Serializable
 data class GenericEnumsUsingStructVariantsVariantGInner<T, U> (
-	val action: T,
-	val response: U
+	var action: T,
+	var response: U
 )
 
 /// Generated type representing the anonymous struct variant `VariantH` of the `GenericEnumsUsingStructVariants` Rust enum
 @Serializable
 data class GenericEnumsUsingStructVariantsVariantHInner (
-	val non_generic: Int
+	var non_generic: Int
 )
 
 /// Generated type representing the anonymous struct variant `VariantI` of the `GenericEnumsUsingStructVariants` Rust enum
 @Serializable
 data class GenericEnumsUsingStructVariantsVariantIInner<T, U> (
-	val vec: List<T>,
-	val action: MyType<T, U>
+	var vec: List<T>,
+	var action: MyType<T, U>
 )
 
 @Serializable
diff --git a/core/data/tests/can_generate_generic_struct/output.kt b/core/data/tests/can_generate_generic_struct/output.kt
index 274bb1f..7f6eb86 100644
--- a/core/data/tests/can_generate_generic_struct/output.kt
+++ b/core/data/tests/can_generate_generic_struct/output.kt
@@ -11,15 +11,15 @@ import kotlinx.serialization.*
 
 @Serializable
 data class GenericStruct<A, B> (
-	val field_a: A,
-	val field_b: List<B>
+	var field_a: A,
+	var field_b: List<B>
 )
 
 @Serializable
 data class GenericStructUsingGenericStruct<T> (
-	val struct_field: GenericStruct<String, T>,
-	val second_struct_field: GenericStruct<T, String>,
-	val third_struct_field: GenericStruct<T, List<T>>
+	var struct_field: GenericStruct<String, T>,
+	var second_struct_field: GenericStruct<T, String>,
+	var third_struct_field: GenericStruct<T, List<T>>
 )
 
 @Serializable
diff --git a/core/data/tests/can_generate_simple_struct_with_a_comment/output.kt b/core/data/tests/can_generate_simple_struct_with_a_comment/output.kt
index 78166b6..c6ff80e 100644
--- a/core/data/tests/can_generate_simple_struct_with_a_comment/output.kt
+++ b/core/data/tests/can_generate_simple_struct_with_a_comment/output.kt
@@ -16,10 +16,10 @@ class Location
 @Serializable
 data class Person (
 	/// This is another comment
-	val name: String,
-	val age: UByte,
-	val info: String? = null,
-	val emails: List<String>,
-	val location: Location
+	var name: String,
+	var age: UByte,
+	var info: String? = null,
+	var emails: List<String>,
+	var location: Location
 )
 
diff --git a/core/data/tests/can_generate_struct_with_skipped_fields/output.kt b/core/data/tests/can_generate_struct_with_skipped_fields/output.kt
index 2bfa5c6..b511112 100644
--- a/core/data/tests/can_generate_struct_with_skipped_fields/output.kt
+++ b/core/data/tests/can_generate_struct_with_skipped_fields/output.kt
@@ -11,7 +11,7 @@ import kotlinx.serialization.*
 
 @Serializable
 data class MyStruct (
-	val a: Int,
-	val c: Int
+	var a: Int,
+	var c: Int
 )
 
diff --git a/core/data/tests/can_handle_anonymous_struct/output.kt b/core/data/tests/can_handle_anonymous_struct/output.kt
index f28ad83..a1ff938 100644
--- a/core/data/tests/can_handle_anonymous_struct/output.kt
+++ b/core/data/tests/can_handle_anonymous_struct/output.kt
@@ -13,16 +13,16 @@ import kotlinx.serialization.*
 @Serializable
 data class AutofilledByUsInner (
 	/// The UUID for the fill
-	val uuid: String
+	var uuid: String
 )
 
 /// Generated type representing the anonymous struct variant `SomethingElse` of the `AutofilledBy` Rust enum
 @Serializable
 data class AutofilledBySomethingElseInner (
 	/// The UUID for the fill
-	val uuid: String,
+	var uuid: String,
 	/// Some other thing
-	val thing: Int
+	var thing: Int
 )
 
 /// Enum keeping track of who autofilled a field
@@ -41,14 +41,14 @@ sealed class AutofilledBy {
 /// Generated type representing the anonymous struct variant `AnonVariant` of the `EnumWithManyVariants` Rust enum
 @Serializable
 data class EnumWithManyVariantsAnonVariantInner (
-	val uuid: String
+	var uuid: String
 )
 
 /// Generated type representing the anonymous struct variant `AnotherAnonVariant` of the `EnumWithManyVariants` Rust enum
 @Serializable
 data class EnumWithManyVariantsAnotherAnonVariantInner (
-	val uuid: String,
-	val thing: Int
+	var uuid: String,
+	var thing: Int
 )
 
 /// This is a comment (yareek sameek wuz here)
diff --git a/core/data/tests/can_handle_serde_rename/output.kt b/core/data/tests/can_handle_serde_rename/output.kt
index bce25b0..0c61505 100644
--- a/core/data/tests/can_handle_serde_rename/output.kt
+++ b/core/data/tests/can_handle_serde_rename/output.kt
@@ -15,11 +15,11 @@ class OtherType
 /// This is a comment.
 @Serializable
 data class Person (
-	val name: String,
-	val age: UByte,
-	val extraSpecialFieldOne: Int,
-	val extraSpecialFieldTwo: List<String>? = null,
-	val nonStandardDataType: OtherType,
-	val nonStandardDataTypeInArray: List<OtherType>? = null
+	var name: String,
+	var age: UByte,
+	var extraSpecialFieldOne: Int,
+	var extraSpecialFieldTwo: List<String>? = null,
+	var nonStandardDataType: OtherType,
+	var nonStandardDataTypeInArray: List<OtherType>? = null
 )
 
diff --git a/core/data/tests/can_handle_serde_rename_all/output.kt b/core/data/tests/can_handle_serde_rename_all/output.kt
index 9b71133..0237bd3 100644
--- a/core/data/tests/can_handle_serde_rename_all/output.kt
+++ b/core/data/tests/can_handle_serde_rename_all/output.kt
@@ -12,18 +12,18 @@ import kotlinx.serialization.*
 /// This is a Person struct with camelCase rename
 @Serializable
 data class Person (
-	val firstName: String,
-	val lastName: String,
-	val age: UByte,
-	val extraSpecialField1: Int,
-	val extraSpecialField2: List<String>? = null
+	var firstName: String,
+	var lastName: String,
+	var age: UByte,
+	var extraSpecialField1: Int,
+	var extraSpecialField2: List<String>? = null
 )
 
 /// This is a Person2 struct with UPPERCASE rename
 @Serializable
 data class Person2 (
-	val FIRST_NAME: String,
-	val LAST_NAME: String,
-	val AGE: UByte
+	var FIRST_NAME: String,
+	var LAST_NAME: String,
+	var AGE: UByte
 )
 
diff --git a/core/data/tests/can_handle_serde_rename_on_top_level/output.kt b/core/data/tests/can_handle_serde_rename_on_top_level/output.kt
index 3703ca8..8a4dd14 100644
--- a/core/data/tests/can_handle_serde_rename_on_top_level/output.kt
+++ b/core/data/tests/can_handle_serde_rename_on_top_level/output.kt
@@ -15,11 +15,11 @@ class OtherType
 /// This is a comment.
 @Serializable
 data class PersonTwo (
-	val name: String,
-	val age: UByte,
-	val extraSpecialFieldOne: Int,
-	val extraSpecialFieldTwo: List<String>? = null,
-	val nonStandardDataType: OtherType,
-	val nonStandardDataTypeInArray: List<OtherType>? = null
+	var name: String,
+	var age: UByte,
+	var extraSpecialFieldOne: Int,
+	var extraSpecialFieldTwo: List<String>? = null,
+	var nonStandardDataType: OtherType,
+	var nonStandardDataTypeInArray: List<OtherType>? = null
 )
 
diff --git a/core/data/tests/can_handle_unit_type/output.kt b/core/data/tests/can_handle_unit_type/output.kt
index 355a4c1..144811e 100644
--- a/core/data/tests/can_handle_unit_type/output.kt
+++ b/core/data/tests/can_handle_unit_type/output.kt
@@ -12,7 +12,7 @@ import kotlinx.serialization.*
 /// This struct has a unit field
 @Serializable
 data class StructHasVoidType (
-	val thisIsAUnit: Unit
+	var thisIsAUnit: Unit
 )
 
 /// This enum has a variant associated with unit data
diff --git a/core/data/tests/generate_types/output.kt b/core/data/tests/generate_types/output.kt
index 543fcbb..ff6e225 100644
--- a/core/data/tests/generate_types/output.kt
+++ b/core/data/tests/generate_types/output.kt
@@ -14,14 +14,14 @@ class CustomType
 
 @Serializable
 data class Types (
-	val s: String,
-	val static_s: String,
-	val int8: Byte,
-	val float: Float,
-	val double: Double,
-	val array: List<String>,
-	val dictionary: HashMap<String, Int>,
-	val optional_dictionary: HashMap<String, Int>? = null,
-	val custom_type: CustomType
+	var s: String,
+	var static_s: String,
+	var int8: Byte,
+	var float: Float,
+	var double: Double,
+	var array: List<String>,
+	var dictionary: HashMap<String, Int>,
+	var optional_dictionary: HashMap<String, Int>? = null,
+	var custom_type: CustomType
 )
 
diff --git a/core/data/tests/kebab_case_rename/output.kt b/core/data/tests/kebab_case_rename/output.kt
index bf34afb..138f21b 100644
--- a/core/data/tests/kebab_case_rename/output.kt
+++ b/core/data/tests/kebab_case_rename/output.kt
@@ -13,10 +13,10 @@ import kotlinx.serialization.*
 @Serializable
 data class Things (
 	@SerialName("bla")
-	val bla: String,
+	var bla: String,
 	@SerialName("label")
-	val label: String? = null,
+	var label: String? = null,
 	@SerialName("label-left")
-	val label_left: String? = null
+	var label_left: String? = null
 )
 
diff --git a/core/data/tests/recursive_enum_decorator/output.kt b/core/data/tests/recursive_enum_decorator/output.kt
index 47f9f70..a2888dd 100644
--- a/core/data/tests/recursive_enum_decorator/output.kt
+++ b/core/data/tests/recursive_enum_decorator/output.kt
@@ -25,13 +25,13 @@ sealed class Options {
 /// Generated type representing the anonymous struct variant `Exactly` of the `MoreOptions` Rust enum
 @Serializable
 data class MoreOptionsExactlyInner (
-	val config: String
+	var config: String
 )
 
 /// Generated type representing the anonymous struct variant `Built` of the `MoreOptions` Rust enum
 @Serializable
 data class MoreOptionsBuiltInner (
-	val top: MoreOptions
+	var top: MoreOptions
 )
 
 @Serializable
diff --git a/core/data/tests/resolves_qualified_type/output.kt b/core/data/tests/resolves_qualified_type/output.kt
index b4d033e..bebe4e4 100644
--- a/core/data/tests/resolves_qualified_type/output.kt
+++ b/core/data/tests/resolves_qualified_type/output.kt
@@ -11,11 +11,11 @@ import kotlinx.serialization.*
 
 @Serializable
 data class QualifiedTypes (
-	val unqualified: String,
-	val qualified: String,
-	val qualified_vec: List<String>,
-	val qualified_hashmap: HashMap<String, String>,
-	val qualified_optional: String? = null,
-	val qualfied_optional_hashmap_vec: HashMap<String, List<String>>? = null
+	var unqualified: String,
+	var qualified: String,
+	var qualified_vec: List<String>,
+	var qualified_hashmap: HashMap<String, String>,
+	var qualified_optional: String? = null,
+	var qualfied_optional_hashmap_vec: HashMap<String, List<String>>? = null
 )
 
diff --git a/core/data/tests/serialize_field_as/output.kt b/core/data/tests/serialize_field_as/output.kt
index d355918..1a534be 100644
--- a/core/data/tests/serialize_field_as/output.kt
+++ b/core/data/tests/serialize_field_as/output.kt
@@ -11,8 +11,8 @@ import kotlinx.serialization.*
 
 @Serializable
 data class EditItemViewModelSaveRequest (
-	val context: String,
-	val values: List<EditItemSaveValue>,
-	val fill_action: AutoFillItemActionRequest? = null
+	var context: String,
+	var values: List<EditItemSaveValue>,
+	var fill_action: AutoFillItemActionRequest? = null
 )
 
diff --git a/core/data/tests/test_i54_u53_type/output.kt b/core/data/tests/test_i54_u53_type/output.kt
index a22a133..d3a1b65 100644
--- a/core/data/tests/test_i54_u53_type/output.kt
+++ b/core/data/tests/test_i54_u53_type/output.kt
@@ -11,7 +11,7 @@ import kotlinx.serialization.*
 
 @Serializable
 data class Foo (
-	val a: Long,
-	val b: ULong
+	var a: Long,
+	var b: ULong
 )
 
diff --git a/core/data/tests/test_serde_default_struct/output.kt b/core/data/tests/test_serde_default_struct/output.kt
index af8aa1a..41eb081 100644
--- a/core/data/tests/test_serde_default_struct/output.kt
+++ b/core/data/tests/test_serde_default_struct/output.kt
@@ -11,6 +11,6 @@ import kotlinx.serialization.*
 
 @Serializable
 data class Foo (
-	val bar: Boolean? = null
+	var bar: Boolean? = null
 )
 
diff --git a/core/data/tests/test_serde_iso8601/output.kt b/core/data/tests/test_serde_iso8601/output.kt
index f69b0b5..4566fa8 100644
--- a/core/data/tests/test_serde_iso8601/output.kt
+++ b/core/data/tests/test_serde_iso8601/output.kt
@@ -11,6 +11,6 @@ import kotlinx.serialization.*
 
 @Serializable
 data class Foo (
-	val time: String
+	var time: String
 )
 
diff --git a/core/data/tests/test_serde_url/output.kt b/core/data/tests/test_serde_url/output.kt
index 6fd543c..32434a8 100644
--- a/core/data/tests/test_serde_url/output.kt
+++ b/core/data/tests/test_serde_url/output.kt
@@ -11,6 +11,6 @@ import kotlinx.serialization.*
 
 @Serializable
 data class Foo (
-	val url: String
+	var url: String
 )
 
diff --git a/core/data/tests/test_type_alias/output.kt b/core/data/tests/test_type_alias/output.kt
index 5b765dc..da9c568 100644
--- a/core/data/tests/test_type_alias/output.kt
+++ b/core/data/tests/test_type_alias/output.kt
@@ -13,6 +13,6 @@ typealias Bar = String
 
 @Serializable
 data class Foo (
-	val bar: Bar
+	var bar: Bar
 )
 
diff --git a/core/data/tests/use_correct_integer_types/output.kt b/core/data/tests/use_correct_integer_types/output.kt
index 38f225b..991bc57 100644
--- a/core/data/tests/use_correct_integer_types/output.kt
+++ b/core/data/tests/use_correct_integer_types/output.kt
@@ -12,11 +12,11 @@ import kotlinx.serialization.*
 /// This is a comment.
 @Serializable
 data class Foo (
-	val a: Byte,
-	val b: Short,
-	val c: Int,
-	val e: UByte,
-	val f: UShort,
-	val g: UInt
+	var a: Byte,
+	var b: Short,
+	var c: Int,
+	var e: UByte,
+	var f: UShort,
+	var g: UInt
 )