@ohos-ports/cash-true 0.0.0-stage → 0.0.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,49 @@
1
- # Temporary Holding Version
1
+ # cash-true
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ---
4
+
5
+
6
+ This is a cross-platform, 100% ES6 implementation of the Unix `true` command.
7
+
8
+ ```bash
9
+ npm install cash-true -g
10
+ ```
11
+
12
+ This will install `true` globally in your system path.
13
+
14
+ For help on the command, type:
15
+
16
+ ```bash
17
+ > true --help
18
+ ```
19
+
20
+ ## More
21
+
22
+ This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript.
23
+
24
+
25
+ ## Related
26
+
27
+ - [cash](https://github.com/dthree/cash) - Main project
28
+ - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands
29
+ - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal
30
+
31
+ #### Individual commands
32
+
33
+ - [cash-cat](https://npmjs.com/package/cash-cat)
34
+ - [cash-cp](https://npmjs.com/package/cash-cp)
35
+ - [cash-false](https://npmjs.com/package/cash-false)
36
+ - [cash-kill](https://npmjs.com/package/cash-kill)
37
+ - [cash-ls](https://npmjs.com/package/cash-ls)
38
+ - [cash-mkdir](https://npmjs.com/package/cash-mkdir)
39
+ - [cash-mv](https://npmjs.com/package/cash-mv)
40
+ - [cash-pwd](https://npmjs.com/package/cash-pwd)
41
+ - [cash-sort](https://npmjs.com/package/cash-sort)
42
+ - [cash-touch](https://npmjs.com/package/cash-touch)
43
+ - [cash-true](https://npmjs.com/package/cash-true)
44
+ - [cash-rm](https://npmjs.com/package/cash-rm)
45
+
46
+
47
+ ## License
48
+
49
+ MIT © [David Caccavella](https://github.com/dthree)
package/bin/parser.js ADDED
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ module.exports = function (args, command) {
4
+ args.splice(0, 2);
5
+ var pipes = (args.indexOf('|') > -1);
6
+ if (args.length === 0) {
7
+ // If we don't have to parse arguments, do
8
+ // the quickest load: just the raw js file
9
+ // of the command and nothing else.
10
+ var cmd = require('./../dist/commands/' + command)();
11
+ cmd.exec.call(console, {options: {}}, {});
12
+ } else if (pipes === false) {
13
+ // If we need to parse args for this
14
+ // command only, pull up vorpal and just load
15
+ // that one command.
16
+ var vorpal = require('vorpal')();
17
+ vorpal.api = {};
18
+ require('./../dist/commands/' + command)(vorpal);
19
+ args = args.join(' ');
20
+
21
+ // If we passed in a help request, load in
22
+ // the help file.
23
+ if (args.indexOf('help') > -1 || args.indexOf('?') > -1) {
24
+ let help;
25
+ try {
26
+ help = require('./../dist/help/' + command + '.js');
27
+ help = String(help).replace(/^\n|\n$/g, '');
28
+ } catch (e) {}
29
+ let cmdObj = vorpal.find(command);
30
+ if (cmdObj && help) {
31
+ cmdObj.help(function (argus, cb) {
32
+ cb(help);
33
+ })
34
+ }
35
+ }
36
+ vorpal.exec(command + ' ' + args).catch(function () {});
37
+ } else {
38
+ // If we get into piping other commands,
39
+ // we need to go full bore and load the
40
+ // entire cash library.
41
+ // I guess we could technically parse all
42
+ // of the passed args, look for applicable
43
+ // commands and only load those, but that's
44
+ // some messy work for something that might
45
+ // not matter. If you're reading this and
46
+ // have deemed it matters, do a PR.
47
+ var cash = require('./../dist/index');
48
+ cash.vorpal.exec(command + ' ' + args.join(' '));
49
+ }
50
+ };
package/bin/true.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('./parser')(process.argv, 'true');
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ var interfacer = require('./../util/interfacer');
4
+
5
+ var _true = {
6
+ exec: function exec() {
7
+ // Always return 0
8
+ return 0;
9
+ }
10
+ };
11
+
12
+ module.exports = function (vorpal) {
13
+ if (vorpal === undefined) {
14
+ return _true;
15
+ }
16
+ vorpal.api.true = _true;
17
+ vorpal.command('true').action(function (args, callback) {
18
+ return interfacer.call(this, {
19
+ command: _true,
20
+ callback: callback
21
+ });
22
+ });
23
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ module.exports = "\nUsage: true [OPTION]\nDo nothing, successfully\n\nThis command simply exits with status 0 (success).\n\n --help display this help and exit\n\nReport true bugs to <https://github.com/dthree/cash>\nCash home page: <http://cash.js.org/>\n";
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ // Replace out env variables.
4
+
5
+ var parseEnvVariables = function parseEnvVariables(input) {
6
+ var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g;
7
+
8
+ return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) {
9
+ var varName = capture1 || capture2 || capture3;
10
+ // Return the value of the variable, or the empty string if not there
11
+ return process.env.hasOwnProperty(varName) ? process.env[varName] : '';
12
+ });
13
+ };
14
+
15
+ var preparser = function preparser(input) {
16
+ input = parseEnvVariables(input);
17
+ return input;
18
+ };
19
+
20
+ module.exports = preparser;
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Simple binding interface between
5
+ * each command's function and the caller
6
+ * of the command, whether by `cash.command`
7
+ * or by being invoked by Vorpal.
8
+ * This exists to abstract complexity
9
+ * and create a standard in interfacing
10
+ * commands acorss muliple execution paths.
11
+ *
12
+ * @param {Object} opt
13
+ * @api public
14
+ */
15
+
16
+ module.exports = function (opt) {
17
+ var self = this;
18
+ var stdout = '';
19
+ opt.options = opt.options || {};
20
+ opt.callback = opt.callback || function () {};
21
+ opt.command = opt.command || {
22
+ exec: function exec() {}
23
+ };
24
+
25
+ var logger = {
26
+ log: function log(out) {
27
+ stdout += out + '\n';
28
+ if (opt.silent !== true) {
29
+ // process.stdout.write(out) // to do - handle newline problem.
30
+ self.log(out);
31
+ }
32
+ }
33
+ };
34
+
35
+ function onResult(result) {
36
+ result = result === undefined ? 0 : result;
37
+ opt.callback(null, stdout);
38
+ return stdout;
39
+ }
40
+
41
+ if (opt.async === true) {
42
+ return opt.command.exec.call(logger, opt.args, opt.options, onResult);
43
+ }
44
+ return onResult(opt.command.exec.call(logger, opt.args, opt.options));
45
+ };
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@ohos-ports/cash-true",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.2-beta.1",
4
+ "description": "Cross-platform implementation of the Unix 'true' command.",
5
+ "main": "./dist/commands/true.js",
6
+ "scripts": {},
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/ohos-ports/ohos-ports.git",
10
+ "directory": "ports/cash-true/0.0.2"
11
+ },
12
+ "keywords": [
13
+ "cash",
14
+ "terminal",
15
+ "emulator",
16
+ "cygwin",
17
+ "cli",
18
+ "windows",
19
+ "linux",
20
+ "unix",
21
+ "posix",
22
+ "bash",
23
+ "tty",
24
+ "util",
25
+ "vorpal",
26
+ "vorpal.js"
27
+ ],
28
+ "author": "dthree",
29
+ "license": "MIT",
30
+ "bugs": {
31
+ "url": "https://github.com/ohos-ports/ohos-ports/issues"
32
+ },
33
+ "homepage": "https://github.com/dthree/cash#readme",
34
+ "devDependencies": {},
35
+ "bin": {
36
+ "true": "./bin/true.js"
37
+ },
38
+ "dependencies": {
39
+ "vorpal": "^1.10.8"
40
+ },
41
+ "engines": {
42
+ "node": ">= 4",
43
+ "iojs": ">= 1.0.0"
44
+ },
45
+ "files": [
46
+ "dist",
47
+ "bin"
48
+ ]
49
+ }