From b283fcdfb843a873921f1ae7bc634ca9d048f503 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Mon, 27 Nov 2023 05:03:05 -0700 Subject: [PATCH] Rename type "text" to "line". --- README.md | 8 ++++---- include/validator.h | 6 +++--- specs/mix/spec.json | 2 +- specs/touch/spec.json | 2 +- src/evaluator.c | 2 +- src/validator.c | 4 ++-- test/test_validator.h | 10 +++++----- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index bc12106..ede0fab 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ We start with an example. Consider the following *spec*, which we'll name ```json { "filename": { - "type": "text", + "type": "line", "prompt": "What file should I create for you? " } } @@ -128,7 +128,7 @@ child objects called *fields*. A typical `spec.json` file looks like: ```json { "fieldname": { - "type": "text", + "type": "line", "prompt": "Prompt for field> " }, ... @@ -136,7 +136,7 @@ child objects called *fields*. A typical `spec.json` file looks like: ``` In this example, the first field is called `"fieldname"`. `bootstrap` sees this field and writes the prompt `"Prompt for field> "` to `stdout`. Since -`"fieldname"` has type `"text"`, `bootstrap` will wait for the user to input +`"fieldname"` has type `"line"`, `bootstrap` will wait for the user to input a string (submitted with a newline). If the user were to enter `fieldvalue` in response to the prompt, the `runner` @@ -150,7 +150,7 @@ of alphanumeric characters or underscores and cannot start with a digit. The value of `type` determines how a field is prompted for. Note the value of `type` is case insenstive. The currently supported list of types are: -* `text` +* `line` * The simplest prompt type. Takes in a free-form response submitted after a newline (`\n`) is encountered. diff --git a/include/validator.h b/include/validator.h index 6189853..353ddb7 100644 --- a/include/validator.h +++ b/include/validator.h @@ -14,7 +14,7 @@ @brief The types of fields `bootstrap` can handle. */ enum FieldType { - FT_TEXT = 1, + FT_LINE = 1, }; /** @@ -26,11 +26,11 @@ file. For instance, the fields of: ```json { "abc": { - "type": "text", + "type": "line", "prompt": "ABC> " }, "def": { - "type": "text", + "type": "line", "prompt": "DEF> " }, } diff --git a/specs/mix/spec.json b/specs/mix/spec.json index fa31cb2..6c191de 100644 --- a/specs/mix/spec.json +++ b/specs/mix/spec.json @@ -1,6 +1,6 @@ { "app": { - "type": "text", + "type": "line", "prompt": "App Name> " } } diff --git a/specs/touch/spec.json b/specs/touch/spec.json index 37cb2e7..df6ff73 100644 --- a/specs/touch/spec.json +++ b/specs/touch/spec.json @@ -1,6 +1,6 @@ { "filename": { - "type": "text", + "type": "line", "prompt": "What file should I create for you? " } } diff --git a/src/evaluator.c b/src/evaluator.c index d2a139c..103d674 100644 --- a/src/evaluator.c +++ b/src/evaluator.c @@ -50,7 +50,7 @@ static const char *prompt_field(struct Field *field) { char *response = calloc(1, 1024); switch (field->type) { - case FT_TEXT: + case FT_LINE: // TODO: Probably want this buffer size to be a bit more dynamic. if (fgets(response, 1024, stdin)) { size_t len = strlen(response); diff --git a/src/validator.c b/src/validator.c index 45292b8..8933920 100644 --- a/src/validator.c +++ b/src/validator.c @@ -67,8 +67,8 @@ static struct Error *read_field( goto cleanup; } - if (strcmp_ci(type->valuestring, "text") == 0) { - (*out)->type = FT_TEXT; + if (strcmp_ci(type->valuestring, "line") == 0) { + (*out)->type = FT_LINE; } else { error = ERROR_NEW( ERROR_VALIDATOR_FIELD_TYPE_UNKNOWN, diff --git a/test/test_validator.h b/test/test_validator.h index 345b29e..f46cab5 100644 --- a/test/test_validator.h +++ b/test/test_validator.h @@ -73,7 +73,7 @@ static void test_validator_field_name_leading_digit() { struct TestValidatorFixture *fixture = test_validator_setup( "{" " \"1abc\": {" - " \"type\": \"text\"" + " \"type\": \"line\"" " }" "}" ); @@ -93,7 +93,7 @@ static void test_validator_field_name_non_alnum() { struct TestValidatorFixture *fixture = test_validator_setup( "{" " \"a~bc\": {" - " \"type\": \"text\"" + " \"type\": \"line\"" " }" "}" ); @@ -150,7 +150,7 @@ static void test_validator_valid_type_ci() { struct TestValidatorFixture *fixture = test_validator_setup( "{" " \"key\": {" - " \"type\": \"tExT\"," + " \"type\": \"LiNe\"," " \"prompt\": \"What value for key?\"" " }" "}" @@ -167,7 +167,7 @@ static void test_validator_field_prompt_invalid() { struct TestValidatorFixture *fixture = test_validator_setup( "{" " \"key\": {" - " \"type\": \"text\"," + " \"type\": \"line\"," " \"prompt\": 2" " }" "}" @@ -187,7 +187,7 @@ static void test_validator_valid() { struct TestValidatorFixture *fixture = test_validator_setup( "{" " \"key\": {" - " \"type\": \"text\"," + " \"type\": \"line\"," " \"prompt\": \"What value for key?\"" " }" "}"