-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from destinygg/static-output-args
Add args to static output commands.
- Loading branch information
Showing
3 changed files
with
80 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
const CommandOutput = require('../command-output'); | ||
|
||
function staticCommand(staticOutput) { | ||
return () => new CommandOutput(null, staticOutput); | ||
return (input) => { | ||
let output = staticOutput; | ||
const args = input ? input.split(' ') : []; | ||
|
||
output = output.replace(/\{%(\d+)%\}/g, (_, i) => { | ||
if (parseInt(i, 10) && args[parseInt(i, 10) - 1]) { | ||
return args[parseInt(i, 10) - 1]; | ||
} | ||
return ''; | ||
}); | ||
|
||
return new CommandOutput(null, output); | ||
}; | ||
} | ||
|
||
module.exports = staticCommand; |
Oops, something went wrong.