2.7.3 • Published 3 years ago

kmdr-parser v2.7.3

Weekly downloads
42
License
MIT
Repository
github
Last release
3 years ago

Kmdr Schema Parser/Validator

A parser/validator for kmdr specs in YAML or JSON format

Installation

With npm

npm install kmdr-parser -g

With yarn

yarn global add kmdr-parser

Usage

CLI

$ kmdr-parser -h
Usage: kmdr-parser [options] <file> [files...]

Options:
  -v, --version            Output the current version
  -l, --log-level <level>  Set the log level (default: "info")
  -h, --help               output usage information

Validating a schema

$ kmdr-parser examples/en/kmdr.yaml
[INFO] Opening file examples/en/kmdr.yaml...
[INFO] The schema examples/en/kmdr.yaml is VALID! It contains { options: 1, subcommands: 2, examples: 0 }

The CLI also takes multiple file names to validate

$ kmdr-parser examples/en/kmdr.yaml
[INFO] Opening file examples/en/kmdr.yaml...
[INFO] The schema examples/en/kmdr.yaml is VALID! It contains { options: 1, subcommands: 2, examples: 0 }
[INFO] Opening file examples/en/kmdr.yaml...
[INFO] The schema examples/en/kmdr.yaml is VALID! It contains { options: 1, subcommands: 2, examples: 0 }
[INFO] Opening file examples/en/rmdir.yaml...
[WARN] The schema examples/en/rmdir.yaml is VALID, but it has 1 warning(s)!
[WARN] Option field "summary" at path [ 'rmdir' ]: Field must end with a letter character (a-z) "Remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is similar to 'rmdir a/b/c a/b a'"

API

import Schema from "kmdr-parser";

const schema = {
  name: "kmdr",
  summary: "The CLI tool for explaining shell commands from your terminal"
};

try {
  const kmdrSchema = new Schema(schema);
} catch (err) {
  console.error(err);
}

Schema

Every program explained by kmdr has a schema with key-value pairs defining the properties of commands.

KeyDefinitionRequiredTypeDefault
nameThe name of the program or subcommandYesstring
summaryA short explanation of what the programYesstring
descriptionA verbose explanation of what the program doesNostring
versionThe version of the program used for building this schemaNostring
localeThe target language of the schemaNostring"en"
subcommandsThe subcommands available in the programNosubcommand[]
optionsThe options available in the programNooption[]
linkLink to the program's pageNostring
stickyOptionsWhether the program accepts sticky options (e.g. -rf for -r and -f)Nobooleanfalse
environmentEnvironment variables picked up by the programNoenvironment[]
examplesList of command examplesNoexample[]

The option object

KeyDefinitionRequiredTypeDefault
longThe long format of the option (e.g. --file)No if short is providedstring[][]
shortThe short format of the option (e.g. -f for --file)No if long is providedstring[][]
summaryA short explanation of the optionYesstring
descriptionA verbose explanation of the optionNostring
expectsArgWhether the option expects an argument or notNobooleanfalse
defaultArgDefault value if argument is missingNostring

The subcommand object

A programs subcommands encapsulate specialized tasks that a program can do. Subcommands usually follow immediately after the program name in a command. Some examples are:

  • npm uninstall: remove is a sub command of the program npm
  • yarn install: install is a sub command of the program yarn
  • docker images: images is a sub command of docker
  • git commit: commit is a sub command of docker

A subcommand can have 0 or more subcommands available for execution:

  • docker network create: docker has a subcommand network and network has a subcommand create
  • git submodule add: git has a subcommand submodule and submodule has a subcommand add

Subcommands have similar key-value pairs to programs. In Table 2.0 we see that there are some new key-value pairs and different key-value pairs are marked as required when compared to the program key-value pair set.

KeyDefinitionRequiredTypeDefault
nameThe name of the program or subcommandYesstring
summaryA short explanation of the subcommandYesstring
aliasesAliasesNostring
descriptionA verbose explanation of the subcommandNostring
subcommandsThe subcommands available in the subcommandNosubcommands[]
optionsThe options available in the subcommandNooptions[]
examplesCommand examplesNoexamples[]

The example object

KeyDefinitionRequiredTypeDefault
commandThe commandYesstring
summaryA short explanation of what the command doesYesstring

The environment object

KeyDefinitionRequiredTypeDefault
nameThe name of the environment variableYesstring
summaryA short explanation of the environment variableYesstring
2.7.3

3 years ago

2.7.0

3 years ago

2.6.1

3 years ago

2.6.0

3 years ago

2.5.0

3 years ago

2.4.2

4 years ago

2.4.1

4 years ago

2.3.0

4 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.1.0-3

4 years ago

2.1.0-4

4 years ago

2.1.0

4 years ago

2.1.0-2

4 years ago

2.1.0-1

4 years ago

2.1.0-0

4 years ago

2.0.0-0

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.2.0-1

4 years ago

1.2.0-0

4 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago