diff --git a/app/Cli.hs b/app/Cli.hs index 784421a..70cae0e 100644 --- a/app/Cli.hs +++ b/app/Cli.hs @@ -36,10 +36,6 @@ opts cwd = let ) & Opts.liftA (\a -> fromString a :: FilePath) ) - -- For Testing Only - -- <|> pure (fromString "./test/datatypetool.toml" :: FilePath) - - -- For Production <|> pure (cwd <> fromString "/datatypetool.toml" :: FilePath) ) <*> ( ( length diff --git a/app/Config/Config.hs b/app/Config/Config.hs index 180720e..4561252 100644 --- a/app/Config/Config.hs +++ b/app/Config/Config.hs @@ -7,6 +7,7 @@ import Data.Function ((&)) import qualified Data.List as List import qualified Data.List.NonEmpty as NE import qualified Data.Map.Strict as Map +import qualified Data.Maybe as Maybe import Data.Text (Text) import qualified Data.Text as Text import qualified Lang.Elm.Config as ElmConfig @@ -41,10 +42,15 @@ datatypetoolCodec = Config ) .= sources <*> (Toml.table - (Toml.dimap - fromSpacing - toSpacing - (Toml.string "spacing") + ( Toml.dioptional + (Toml.dimap + fromSpacing + toSpacing + (Toml.string "spacing") + ) + & Toml.dimap + (Just) + (Maybe.fromMaybe Spaces4) ) "datatypetool" ) diff --git a/docs/datatypetool_toml.md b/docs/datatypetool_toml.md index 1ef3abd..02f5206 100644 --- a/docs/datatypetool_toml.md +++ b/docs/datatypetool_toml.md @@ -4,14 +4,21 @@ The `datatypetool.toml` file should live at the root of your project. It contain Here's a listing of the settings to configure: -- `sources`: - - A list of strings resembling directory paths. - - Can be relative or absolute. - - If relative, the origin is the directory containing the `datatypetool.toml` file. - - Should point to the directories where all necessary `*.type` files live. - - Ideally should be just one destination, but can be more if needed. +- `[datatypetool]`: + - `sources` + - A string resembling a directory path. + - Can be relative or absolute. + - If relative, the origin is the directory containing the `datatypetool.toml` file. + - Should point to the directory where all necessary `*.type` files live. + - `spacing` + - Must be one of the following: + - `"spaces2"` (AKA, two-spaces for indenting) + - `"spaces3"` (AKA, three-spaces for indenting) + - `"spaces4"` (AKA, four-spaces for indenting) + - `"tabs"` (AKA, tab literal `\t`) + - if the entire `spacing` parameter is omitted, the default is `"spaces4"` -- `targets.*`: +- `[targets]` |> `[targets.*]`: - Settings for targets vary from language to language, but _all_ languages share two common settings: - `output_location`: - Should point to the output directory for generated types for the specified language. diff --git a/docs/datatypetool_type_files.md b/docs/datatypetool_type_files.md index 7b4d90b..e7c9eb8 100644 --- a/docs/datatypetool_type_files.md +++ b/docs/datatypetool_type_files.md @@ -17,15 +17,15 @@ Data Types with in `*.type` files can be one of four options: - A `constant`: - A value that is always the same, and should be across languages. - __THIS SHOULD NOT BE USED FOR SENSITIVE ITEMS LIKE PASSWORDS.__ - - If you need something for sensitive things, maybe consider a [dotenv vault](https://www.dotenv.org/security/) or [HashiCorp's Vault](https://www.hashicorp.com/products/vault), or something. + - If you need something for sensitive things, maybe consider a [dotenv vault](https://www.dotenv.org/security/) or [HashiCorp's Vault](https://www.hashicorp.com/products/vault) or something. - ex.: `Meaning_Of_Life = 42` -Type names in `*.type` files should be un Capitalized_Snake_Case. This is probably a weird choice at first glance, but we'll explain why it makes sense. It's all about name conversion when we generate files: -- Converting from regular_snake_case to camelCase or PascalCase, it's simple: +Type names in `*.type` files should be in Capitalized_Snake_Case. This is probably a weird choice at first glance, but we'll explain why it makes sense. It's all about name conversion when we generate files: +- Converting from quiet_snake_case to camelCase or PascalCase, it's simple: - Remove the underscore and capitalize the following letter - BUT: What if you have a name like api_versions? That would become ApiVersions, which maybe you prefer the semantics of an entirely-capitalized "API". -- Converting from camelCase or PascalCase to snake_case, it _seems_ easy: - - Add an underscore before capitalized letters (except the first one), and lowercase all of them. +- Converting from camelCase or PascalCase to quiet_snake_case, it _seems_ easy: + - Add an underscore before capitalized letters (except the first one, for PascalCase), and lowercase all of them. - BUT: What if you have a name like APIVersions? That would become a_p_i_versions, which is gross, albeit understandable. - Capitalized_Snake_Case allows us to preserve capitalization __and__ semantics, so it makes the most sense for creating types in any language's preferred casing. We want to make the cross-language types, and not make arguments over each language's preferred casing. @@ -33,11 +33,11 @@ The basic structure of a `*.type` file is just a list of types. No header or mod Comments are denoted with a `#`. -There is a __strict__ constraint of indentation at the moment, and it __must__ be 4 spaces or a tab character. +There is a __strict__ constraint of indentation at the moment, and it __must__ be the spacing set in `datatypetool.toml |> spacing`. If omitted, it will be 4 spaces. To define a type, first define which type you need: `alias`, `enum`, `model`, or `constant`. Then, give it a Capitalized_Snake_Case name and a colon. Like YAML, colons open up an indented block below it for nested fields. -All types can have a `meta` field. This is for things specific to that type, that aren't a core part of the type. Things like `doc` strings, or `lang`-uage settings, or a `ref`-erence to another `*.type` file. The `meta` field is optional, though, if you don't need any of that. +All types can have a `meta` field. This is for things specific to that type, that aren't a core part of the type. Things like `doc` strings, or `lang`-uage settings, or a `ref`-erence to another `*.type` file. The `meta` field is optional, if you don't need any of that. Then, you need to do the actual type-defining. @@ -75,8 +75,8 @@ If you are making a `model`: - Each field should contain a field with just the field's name, in Uppercase_Snake_Case, for conversion. - Each model-field must contain a field named `type`. - This contains the type intended for the field. - - Each model-field may contain a field named `default`. - - This contains a default value for the field if not supplied one on-construction. + Example: ``` @@ -88,13 +88,9 @@ model Important_Data: That: type: Nullable Int - default: - Null Where: type: Cardinal_Directions - default: - North ``` If you are making a `constant`: diff --git a/docs/datatyletool_types.md b/docs/datatypetool_types.md similarity index 100% rename from docs/datatyletool_types.md rename to docs/datatypetool_types.md diff --git a/docs/specific_language_requirements.md b/docs/specific_language_requirements.md index 07a857f..c1500a7 100644 --- a/docs/specific_language_requirements.md +++ b/docs/specific_language_requirements.md @@ -19,5 +19,4 @@ ## Python -- Required packages: - - \ No newline at end of file +- Required packages: \ No newline at end of file diff --git a/testProject/src/dtt/basic_test.gleam b/testProject/src/dtt/basic_test.gleam index 32a9da8..2b4c80e 100644 --- a/testProject/src/dtt/basic_test.gleam +++ b/testProject/src/dtt/basic_test.gleam @@ -86,5 +86,5 @@ pub fn important_data_decoder(json: Dynamic) -> Result(ImportantData, List(Decod } -/// Temporarily a function because Dict's cant be constructed free-hand. -pub fn constant_life() -> Int {42} \ No newline at end of file +/// Temporarily a function solely because Dict's cant be constructed free-hand. +pub fn life() -> Int {42} \ No newline at end of file diff --git a/testProject/src/dtt/folder/another_test.gleam b/testProject/src/dtt/folder/another_test.gleam index fa47bfb..99f00ca 100644 --- a/testProject/src/dtt/folder/another_test.gleam +++ b/testProject/src/dtt/folder/another_test.gleam @@ -42,5 +42,5 @@ pub fn a_b_c_decoder(json: Dynamic) -> Result(ABC, List(DecodeError)) { /// This is where to find DataTypeTool -/// Temporarily a function because Dict's cant be constructed free-hand. -pub fn constant_this_repo() -> String {"https://codeberg.org/dneaves/datatypetool"} \ No newline at end of file +/// Temporarily a function solely because Dict's cant be constructed free-hand. +pub fn this_repo() -> String {"https://codeberg.org/dneaves/datatypetool"} \ No newline at end of file diff --git a/testProject/src/dtt/folder/complex_tests.gleam b/testProject/src/dtt/folder/complex_tests.gleam index 4ecd255..6e93ae4 100644 --- a/testProject/src/dtt/folder/complex_tests.gleam +++ b/testProject/src/dtt/folder/complex_tests.gleam @@ -35,5 +35,5 @@ pub fn complicated_data_decoder(json: Dynamic) -> Result(ComplicatedData, List(D } -/// Temporarily a function because Dict's cant be constructed free-hand. -pub fn constant_test_dict() -> Dict(String, String) {dict.from_list([#("Key1", "Val1"), #("Key2", "Val2"), #("Key3", "Val3"), #("Key4", "Val4")])} \ No newline at end of file +/// Temporarily a function solely because Dict's cant be constructed free-hand. +pub fn test_dict() -> Dict(String, String) {dict.from_list([#("Key1", "Val1"), #("Key2", "Val2"), #("Key3", "Val3"), #("Key4", "Val4")])} \ No newline at end of file