Rename type "text" to "line".

pull/10/head v0.1.1
Joshua Potter 2023-11-27 05:03:05 -07:00
parent ef265afc48
commit b283fcdfb8
7 changed files with 17 additions and 17 deletions

View File

@ -24,7 +24,7 @@ We start with an example. Consider the following *spec*, which we'll name
```json ```json
{ {
"filename": { "filename": {
"type": "text", "type": "line",
"prompt": "What file should I create for you? " "prompt": "What file should I create for you? "
} }
} }
@ -128,7 +128,7 @@ child objects called *fields*. A typical `spec.json` file looks like:
```json ```json
{ {
"fieldname": { "fieldname": {
"type": "text", "type": "line",
"prompt": "Prompt for field> " "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 In this example, the first field is called `"fieldname"`. `bootstrap` sees this
field and writes the prompt `"Prompt for field> "` to `stdout`. Since 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). a string (submitted with a newline).
If the user were to enter `fieldvalue` in response to the prompt, the `runner` 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 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: `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 * The simplest prompt type. Takes in a free-form response submitted after a
newline (`\n`) is encountered. newline (`\n`) is encountered.

View File

@ -14,7 +14,7 @@
@brief The types of fields `bootstrap` can handle. @brief The types of fields `bootstrap` can handle.
*/ */
enum FieldType { enum FieldType {
FT_TEXT = 1, FT_LINE = 1,
}; };
/** /**
@ -26,11 +26,11 @@ file. For instance, the fields of:
```json ```json
{ {
"abc": { "abc": {
"type": "text", "type": "line",
"prompt": "ABC> " "prompt": "ABC> "
}, },
"def": { "def": {
"type": "text", "type": "line",
"prompt": "DEF> " "prompt": "DEF> "
}, },
} }

View File

@ -1,6 +1,6 @@
{ {
"app": { "app": {
"type": "text", "type": "line",
"prompt": "App Name> " "prompt": "App Name> "
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"filename": { "filename": {
"type": "text", "type": "line",
"prompt": "What file should I create for you? " "prompt": "What file should I create for you? "
} }
} }

View File

@ -50,7 +50,7 @@ static const char *prompt_field(struct Field *field) {
char *response = calloc(1, 1024); char *response = calloc(1, 1024);
switch (field->type) { switch (field->type) {
case FT_TEXT: case FT_LINE:
// TODO: Probably want this buffer size to be a bit more dynamic. // TODO: Probably want this buffer size to be a bit more dynamic.
if (fgets(response, 1024, stdin)) { if (fgets(response, 1024, stdin)) {
size_t len = strlen(response); size_t len = strlen(response);

View File

@ -67,8 +67,8 @@ static struct Error *read_field(
goto cleanup; goto cleanup;
} }
if (strcmp_ci(type->valuestring, "text") == 0) { if (strcmp_ci(type->valuestring, "line") == 0) {
(*out)->type = FT_TEXT; (*out)->type = FT_LINE;
} else { } else {
error = ERROR_NEW( error = ERROR_NEW(
ERROR_VALIDATOR_FIELD_TYPE_UNKNOWN, ERROR_VALIDATOR_FIELD_TYPE_UNKNOWN,

View File

@ -73,7 +73,7 @@ static void test_validator_field_name_leading_digit() {
struct TestValidatorFixture *fixture = test_validator_setup( struct TestValidatorFixture *fixture = test_validator_setup(
"{" "{"
" \"1abc\": {" " \"1abc\": {"
" \"type\": \"text\"" " \"type\": \"line\""
" }" " }"
"}" "}"
); );
@ -93,7 +93,7 @@ static void test_validator_field_name_non_alnum() {
struct TestValidatorFixture *fixture = test_validator_setup( struct TestValidatorFixture *fixture = test_validator_setup(
"{" "{"
" \"a~bc\": {" " \"a~bc\": {"
" \"type\": \"text\"" " \"type\": \"line\""
" }" " }"
"}" "}"
); );
@ -150,7 +150,7 @@ static void test_validator_valid_type_ci() {
struct TestValidatorFixture *fixture = test_validator_setup( struct TestValidatorFixture *fixture = test_validator_setup(
"{" "{"
" \"key\": {" " \"key\": {"
" \"type\": \"tExT\"," " \"type\": \"LiNe\","
" \"prompt\": \"What value for key?\"" " \"prompt\": \"What value for key?\""
" }" " }"
"}" "}"
@ -167,7 +167,7 @@ static void test_validator_field_prompt_invalid() {
struct TestValidatorFixture *fixture = test_validator_setup( struct TestValidatorFixture *fixture = test_validator_setup(
"{" "{"
" \"key\": {" " \"key\": {"
" \"type\": \"text\"," " \"type\": \"line\","
" \"prompt\": 2" " \"prompt\": 2"
" }" " }"
"}" "}"
@ -187,7 +187,7 @@ static void test_validator_valid() {
struct TestValidatorFixture *fixture = test_validator_setup( struct TestValidatorFixture *fixture = test_validator_setup(
"{" "{"
" \"key\": {" " \"key\": {"
" \"type\": \"text\"," " \"type\": \"line\","
" \"prompt\": \"What value for key?\"" " \"prompt\": \"What value for key?\""
" }" " }"
"}" "}"