Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
command-mapper
Advanced tools
Maps command aliases to real commands based on a mapping.json file.
Maps command aliases to real commands based on a mapping
options object or JSON file.
##Table of Contents##
npm install command-mapper
####CommandMapper###
CommandMapper
has a simple API:
var CommandMapper = require("command-mapper"),
mappingOptions = [{
command: "git",
alias: "g",
mappings: [{
command: "commit",
alias: "c",
options: {
"m": "-am"
}
}]
}];
console.log(CommandMapper.map(mappingOptions, "g c"));
// --> "git commit"
console.log(new CommandMapper(mappingOptions).map("g c -m"));
// --> "git commit -am"
####CommandMapper(mapping)####
Constructs a new CommandMapper
object with the passed mapping
options object or mapping options array i.e. it will accept a single mapping
options object or an array of them.
var mapper = new CommandMapper({ command: "git", alias: "g" });
####CommandMapper.map(mapping, input, [options])####
Maps the input to a real command based on the mapping passed.
If asArray
is specified as an option then an array of command line arguments
will be returned. By default it returns the command as a string.
console.log(CommandMapper.map({ command: "git", alias: "g", "default": "help" }, "g"));
// --> "git help"
console.log(CommandMapper.map({ command: "git", alias: "g", "default": "help" }, "g",
{ asArray: true }));
// --> [ "git", "help" ]
####CommandMapper.fromMappingJSONFile(file)####
Creates a new CommandMapper
object from a [mapping][mapping-object] JSON file.
var commandMapper = CommandMapper.fromMappingJSONFile(mappingJSONFile);
####map(input, [options])####
Maps the input (which is an aliased command) to the real command.
If asArray
is specified as an option then an array of command line arguments
will be returned. By default it returns the command as a string.
var mapper = new CommandMapper({ command: "git", alias: "g", "default": "help" });
console.log(mapper.map("g"));
// --> "git help"
var mapper = new CommandMapper({ command: "git", alias: "g", "default": "help" });
console.log(mapper.map("g", { asArray: true }));
// --> [ "git", "help" ]
A mapping object can consist of the follow properties:
####command####
The real command that the mapping object maps too. This is a required property.
{
"command": "git"
}
####alias####
The alias that represents the real command. This is a required property.
{
"command": "git",
"alias": "g"
}
g
will map to git
.
####default####
A string that will be appended to the command if no other args/options/aliases are available.
{
"command": "git",
"alias": "g",
"default": "help"
}
g
will map to git help
, however, g -o
will map to git -o
since an
argument has been passed to the g
alias.
####always####
A string that will always be appended to the command.
{
"command": "git diff",
"alias": "gd",
"always": "--color"
}
gd
will map to git diff --color
.
####options###
An options object which represents aliases for the command.
{
"command": "git diff",
"alias": "gd",
"always": "--color",
"options": {
"p": "--unified=8 -k -p"
}
}
gd -p
will map to git diff --color --unified=8 -k -p
.
Options can have a single argument that can be plugged into the mapping with
the special string %argument%
.
{
"command": "git diff",
"alias": "gd",
"options": {
"h": "--hard HEAD~%argument%"
}
}
gd -h3
or gd -h 3
would map to git diff --hard HEAD~3
.
If you'd like to have multi-character keys for the options object like:
{
"command": "git diff",
"alias": "gd",
"options": {
"hard": "--hard HEAD~%argument%"
}
}
Then make sure to write your alias option with a --
like so, gd --hard=3
,
which would output, git diff --hard HEAD~3
.
####mappings####
A nested mapping object which represents an alias to a sub command of the parent command.
{
"command": "git",
"alias": "g",
"mappings": [{
"command": "commit",
"alias": "c",
"default:" "-a"
}, {
"command": "diff",
"alias": "d",
"always": "--color"
}]
}
g c
will map to git commit -a
and g d
will map to git diff --color
.
####formula####
A string which represents the way in which the mapped command should look.
{
"command": "git",
"alias": "g",
"mappings": [{
"command": "push",
"alias": "p",
"formula": "%command% %1% %2% %options%",
"always": "--tag",
"default": "origin master"
}]
}
g p origin master
will map to git push origin master --tag
.
g p
will map to git push origin master --tag
as well.
Formulas provide a few built in values:
%command%
the mapped value of the command.%always%
the mapped value of the always property.%default%
the mapped value of the default property.%options%
the mapped value of all the alias' options.%args%
the mapped value of all the arguments in the alias.%1%
.. %n%
any % escape with a number mapps to the argument at index %n%.Any option/switch/argument that is passed to the mapping function which does not have a corresponding entry in the mapping option object will be automatically appended to the given command i.e. given:
{
"command": "git",
"alias": "g",
"default": "help"
}
g push origin master
will map to git push origin master
.
g commit -am
will map to git commit -a -m
.
g diff --unified=8
will map to git diff --unified=8
.
g diff -U8
will map to git diff -U8
.
g checkout -b branch
will map to git checkout -b branch
.
And so on.
FAQs
Maps command aliases to real commands based on a mapping.json file.
We found that command-mapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.