New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

omelette

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

omelette - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

2

package.json

@@ -11,3 +11,3 @@ {

"author": "Fatih Kadir Akın <fka@fatihak.in>",
"version": "0.3.2",
"version": "0.4.0",
"licenses": [

@@ -14,0 +14,0 @@ {

@@ -1,2 +0,2 @@

# Omelette.js v0.3.1
# Omelette.js v0.4.0

@@ -6,2 +6,4 @@ [![Build Status](https://travis-ci.org/f/omelette.png?branch=master)](https://travis-ci.org/f/omelette)

```bash
yarn add omelette
# or
npm install omelette

@@ -14,4 +16,4 @@ ```

```coffeescript
omelette "githubber <module> <command> <suboption>"
```javascript
omelette('githubber <module> <command> <suboption>')
```

@@ -25,20 +27,20 @@

```coffeescript
omelette "<programname>[|<shortname>|<short>|<...>] <module> [<command> <suboption> <...>]"
```javascript
omelette('<programname>[|<shortname>|<short>|<...>] <module> [<command> <suboption> <...>]')
```
## Quickstart
## Quick Start
Implementing omelette is very easy.
```coffeescript
#!/usr/bin/env coffee
```javascript
import * as omelette from 'omelette';
omelette = require "omelette"
comp = omelette "programname|prgmnm|prgnm <firstargument>"
const completion = omelette('programname|prgmnm|prgnm <firstargument>');
comp.on "firstargument", ->
@reply ["hello", "cruel", "world"]
completion.on('firstargument', ({ reply }) => {
reply(["hello", "cruel", "world"]);
});
comp.init()
comp.init();
```

@@ -56,66 +58,68 @@

```coffeescript
#!/usr/bin/env coffee
```javascript
import * as omelette from 'omelette';
omelette = require "omelette"
// Write your CLI template.
const completion = omelette(`githubber|gh <action> <user> <repo>`);
# Write your CLI template.
complete = omelette "githubber|gh <action> <user> <repo>"
// Bind events for every template part.
completion.on("action", ({ reply }) => reply(["clone", "update", "push"]));
# Bind events for every template part.
complete.on "action", -> @reply ["clone", "update", "push"]
completion.on("user", ({ reply }) => reply(fs.readdirSync("/Users/")));
complete.on "user", (action)-> @reply fs.readdirSync "/Users/"
completion.on("repo", ({ before, reply }) => {
reply([
`http://github.com/${before}/helloworld`,
`http://github.com/${before}/blabla`
]);
);
complete.on "repo", (user)->
@reply [
"http://github.com/#{user}/helloworld"
"http://github.com/#{user}/blabla"
]
// Initialize the omelette.
completion.init();
# Initialize the omelette.
complete.init()
// If you want to have a setup feature, you can use `omeletteInstance.setupShellInitFile()` function.
if (~process.argv.indexOf('--setup') {
complete.setupShellInitFile();
}
# If you want to have a setup feature, you can use `omeletteInstance.setupShellInitFile()` function.
if ~process.argv.indexOf '--setup'
complete.setupShellInitFile()
# Rest is yours
console.log "Your program's default workflow."
console.log process.argv
// Rest is yours
console.log("Your program's default workflow.");
console.log(process.argv);
```
If you like oldschool:
`complete.reply` is the completion replier. You must pass the options into that method.
### ES6 Template Literals 🚀
You can use **Template Literals** to define your completion with a simpler (super easy) API.
```javascript
var fs = require("fs"),
omelette = require("omelette");
import * as omelette from 'omelette';
// Write your CLI template.
var complete = omelette("githubber|gh <action> <user> <repo>");
// Just pass a template literal to use super easy API.
omelette`hello ${['cruel', 'nice']} ${['world', 'mars']}`.init();
```
complete.on("action", function() {
this.reply(["clone", "update", "push"]);
});
Also you can still use lambda functions to make more complex template literals:
complete.on("user", function(action) {
this.reply(fs.readdirSync("/Users/"));
});
#### Advanced Template Literals
complete.on("repo", function(user) {
this.reply([
"http://github.com/" + user + "/helloworld",
"http://github.com/" + user + "/blabla"
]);
});
```javascript
import * as omelette from 'omelette';
// Initialize the omelette.
complete.init();
omelette`
githubber|gh
${['pull', 'push', 'star'] /* Direct command list */}
${require('some/other/commands') /* Import from another file */}
${getFromRemote('http://api.example.com/commands') /* Remote call at the beginning */}
${({ reply }) => fetch('http://api.example.com/lazy-commands').then(reply) /* Fetch when argument <tab>bed */}
${() => fs.readdirSync("/Users/") /* Access filesystem via Node */}
${({ before }) => [ /* Use parameters like `before`, `line`, `fragment` or `reply` */
`${before}/helloworld`,
`${before}/blabla`
]}
`.init();
// If you want to have a setup feature, you can use `omeletteInstance.setupShellInitFile()` function.
if (~process.argv.indexOf '--setup') {
complete.setupShellInitFile();
}
// No extra configuration required.
// Rest is yours.
console.log("Your program's default workflow.");

@@ -125,4 +129,2 @@ console.log(process.argv);

`complete.reply` is the completion replier. You should pass the options into that method.
### Install

@@ -183,7 +185,10 @@

Callbacks have three parameters:
Callbacks have two parameters:
- The number of fragment *just for global event*
- The parent word.
- The whole command line buffer allow you to parse and reply as you wish.
- The fragment name (e.g.`command` of `<command>` template) *(only in global event)*
- The meta data
- `fragment`: The number of fragment.
- `prev`: The previous word.
- `line`: The whole command line buffer allow you to parse and reply as you wish.
- `reply`: This is the reply function to use *this-less* API.

@@ -194,4 +199,4 @@ ### Global Event

```coffeescript
complete.on "complete", (fragment, word, line)-> @reply ["hello", "world"]
```javascript
complete.on('complete', (fragment, { reply }) => reply(["hello", "world"]));
```

@@ -203,4 +208,4 @@

```coffeescript
complete.on "$1", (word, line)-> @reply ["hello", "world"]
```javascript
complete.on('$1', ({ reply }) => reply(["hello", "world"]))
```

@@ -214,4 +219,4 @@

```coffeescript
omelette "githubber|gh <module> <command> <suboption>"
```javascript
omelette('githubber|gh <module> <command> <suboption>');
```

@@ -225,6 +230,6 @@

git clone https://github.com/f/omelette
cd omelette/examples
cd omelette/example
alias githubber="./githubber" # The app should be global, completion will search it on global level.
./githubber --setup --debug # --setup is not provided by omelette, you should proxy it.
# (reload bash, or source ~/.bash_profile)
# (reload bash, or source ~/.bash_profile or ~/.config/fish/config.fish)
omelette-debug-githubber # See Debugging section

@@ -231,0 +236,0 @@ githubber<tab>

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.12.3
// Generated by CoffeeScript 1.12.5

@@ -29,3 +29,3 @@ /*

function Omelette() {
var isZsh, ref;
var isFish, isZsh, ref;
this.compgen = process.argv.indexOf("--compgen");

@@ -35,6 +35,7 @@ this.install = process.argv.indexOf("--completion") > -1;

isZsh = process.argv.indexOf("--compzsh") > -1;
isFish = process.argv.indexOf("--compfish") > -1;
this.isDebug = process.argv.indexOf("--debug") > -1;
this.fragment = parseInt(process.argv[this.compgen + 1]) - (isZsh ? 1 : 0);
this.word = process.argv[this.compgen + 2];
this.line = process.argv[this.compgen + 3];
this.word = this.line.trim().split(/\s+/).pop();
ref = process.env, this.HOME = ref.HOME, this.SHELL = ref.SHELL;

@@ -58,5 +59,12 @@ }

Omelette.prototype.generate = function() {
this.emit("complete", this.fragments[this.fragment - 1], this.word, this.line);
this.emit(this.fragments[this.fragment - 1], this.word, this.line);
this.emit("$" + this.fragment, this.word, this.line);
var data;
data = {
before: this.word,
fragment: this.fragment,
line: this.line,
reply: this.reply
};
this.emit("complete", this.fragments[this.fragment - 1], data);
this.emit(this.fragments[this.fragment - 1], data);
this.emit("$" + this.fragment, data);
return process.exit();

@@ -69,3 +77,3 @@ };

}
console.log(words.join("\n"));
console.log(typeof words.join === "function" ? words.join(os.EOL) : void 0);
return process.exit();

@@ -79,3 +87,3 @@ };

var completion;
completion = "_" + program + "_complette";
completion = "_" + program + "_completion";
return "### " + program + " completion - begin. generated by omelette.js ###\nif type compdef &>/dev/null; then\n " + completion + "() {\n compadd -- `" + _this.program + " --compzsh --compgen \"${CURRENT}\" \"${words[CURRENT-1]}\" \"${BUFFER}\"`\n }\n compdef " + completion + " " + program + "\nelif type complete &>/dev/null; then\n " + completion + "() {\n COMPREPLY=( $(compgen -W '$(" + _this.program + " --compbash --compgen \"${COMP_CWORD}\" \"${COMP_WORDS[COMP_CWORD-1]}\" \"${COMP_LINE}\")' -- \"${COMP_WORDS[COMP_CWORD]}\") )\n }\n complete -F " + completion + " " + program + "\nfi\n### " + program + " completion - end ###";

@@ -95,3 +103,3 @@ };

var completion;
completion = "_" + program + "_complette";
completion = "_" + program + "_completion";
return "### " + program + " completion - begin. generated by omelette.js ###\nfunction " + completion + "\n " + _this.program + " --compfish --compgen (count (commandline -poc)) (commandline -pt) (commandline -pb)\nend\ncomplete -f -c " + program + " -a '(" + completion + ")'\n### " + program + " completion - end ###";

@@ -198,5 +206,14 @@ };

module.exports = function(template) {
var _omelette, fragments, program, ref;
ref = template.split(/\s+/), program = ref[0], fragments = 2 <= ref.length ? slice.call(ref, 1) : [];
module.exports = function() {
var _omelette, args, callback, callbacks, fn, fragment, fragments, i, index, len, program, ref, ref1, template;
template = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
if (template instanceof Array && args.length > 0) {
ref = [template[0].trim(), args], program = ref[0], callbacks = ref[1];
fragments = callbacks.map(function(callback, index) {
return "arg" + index;
});
} else {
ref1 = template.split(/\s+/), program = ref1[0], fragments = 2 <= ref1.length ? slice.call(ref1, 1) : [];
callbacks = [];
}
fragments = fragments.map(function(fragment) {

@@ -209,2 +226,14 @@ return fragment.replace(/^\<+|\>+$/g, '');

_omelette.checkInstall();
fn = function(callback) {
return _omelette.on(fragment, function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return this.reply(callback instanceof Array ? callback : callback.apply(null, args));
});
};
for (index = i = 0, len = callbacks.length; i < len; index = ++i) {
callback = callbacks[index];
fragment = "arg" + index;
fn(callback);
}
return _omelette;

@@ -211,0 +240,0 @@ };

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc