How to use structured-cli - 10 common examples

To help you get started, we’ve selected a few structured-cli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github auth0 / wt-cli / bin / bundle / analyze.js View on Github external
var Cli = require('structured-cli');
var Path = require('path');


module.exports = Cli.createCommand('analyze', {
    description: '[DEPRECATED] Specify dependencies via package.json',
    plugins: [
        // require('../_plugins/profile'),
    ],
    params: {
        'filename': {
            description: 'Path to the webtask\'s code.',
            type: 'string',
            defaultValue: Path.join(process.cwd(), 'webtask.js'),
        },
    },
    handler: handleBundleAnalyze,
});


// Command handler
github auth0 / wt-cli / bin / serve.js View on Github external
const Bluebird = require('bluebird');
const Chalk = require('chalk');
const Cli = require('structured-cli');
const Dotenv = require('dotenv');
const Fs = require('fs');
const keyValList2Object = require('../lib/keyValList2Object');
const Path = require('path');
const Runtime = require('webtask-runtime');
const _ = require('lodash');
const config = require('./serveCommon')();

config.description = "Run a webtask as a local http server";
config.handler = handleWebtaskServe;

module.exports = Cli.createCommand('serve', config);

// Command handler

function handleWebtaskServe(args) {
    keyValList2Object(args, 'secrets');
    keyValList2Object(args, 'params');

    if (args.secretsFile) {
        try {
            const filename = Path.resolve(process.cwd(), args.secretsFile);
            const content = Fs.readFileSync(filename, 'utf8');
            const secrets = Dotenv.parse(content);

            for (let secret in secrets) {
                if (!args.secrets.hasOwnProperty(secret)) {
                    args.secrets[secret] = secrets[secret];
github auth0 / wt-cli / bin / auth0_scaffold.js View on Github external
var Chalk = require('chalk');
var Cli = require('structured-cli');
var _ = require('lodash');
var keyValList2Object = require('../lib/keyValList2Object');
var auth0Extensions = require('auth0-hooks-templates');
var extensionTypes = Object.keys(auth0Extensions).sort();


module.exports = Cli.createCommand('scaffold', {
    description: 'Scaffold the Auth0 hook code',
    optionGroups: {
        'Hook scaffolding': {
            'type': {
                alias: 't',
                description: 'Hook type, required. One of: ' + extensionTypes.join(', ') + '.',
                choices: extensionTypes,
                required: true,
                dest: 'extensionName',
                metavar: 'TYPE',
                type: 'string'
            },
        }
    },
    handler: (args) => console.log(auth0Extensions[args.extensionName].sample),
});
github auth0 / wt-cli / bin / token / inspect.js View on Github external
var Cli = require('structured-cli');
var Decode = require('jwt-decode');
var PrintTokenDetails = require('../../lib/printTokenDetails');


module.exports = Cli.createCommand('inspect', {
    description: 'Inspect named webtasks and webtask tokens',
    plugins: [
        require('../_plugins/profile'),
    ],
    handler: handleTokenInspect,
    optionGroups: {
        'Inspect options': {
            'decrypt': {
                type: 'boolean',
                description: 'Return the decrypted secrets',
            },
            'fetch-code': {
                type: 'boolean',
                description: 'Return the webtask code',
                dest: 'fetchCode',
            },
github auth0 / wt-cli / bin / profile / migrate.js View on Github external
var Chalk = require('chalk');
var Cli = require('structured-cli');
var ConfigFile = require('../../lib/config');
var PrintProfile = require('../../lib/printProfile');
var _ = require('lodash');
var node4Migration = require('../../lib/node4Migration');
var Async = require('async');
var Sandbox = require('sandboxjs');
var Init = require('./init');



module.exports = Cli.createCommand('migrate', {
    description: 'Migrate Node 4 webtasks to Node 8',
    handler: handleProfileMigrate,
    optionGroups: {
        'Migration options': {
            include: {
                alias: 'i',
                action: 'append',
                defaultValue: [],
                description: 'Webtasks to include in the migration (all if not specified)',
                dest: 'include',
                type: 'string',
            },
            exclude: {
                alias: 'x',
                action: 'append',
                defaultValue: [],
github auth0 / wt-cli / bin / profile / nuke.js View on Github external
var Bluebird = require('bluebird');
var Chalk = require('chalk');
var Cli = require('structured-cli');
var ConfigFile = require('../../lib/config');
var Promptly = Bluebird.promisifyAll(require('promptly'));
var _ = require('lodash');


module.exports = Cli.createCommand('nuke', {
    description: 'Destroy all existing profiles and their secrets',
    handler: handleProfileNuke,
    options: {
        force: {
            alias: 'f',
            description: 'Do not prompt for confirmation',
            type: 'boolean',
        },
        silent: {
            alias: 's',
            description: 'No output',
            type: 'boolean',
        },
    },
});
github auth0 / wt-cli / bin / auth0_toggle.js View on Github external
module.exports = function (action) {
    return Cli.createCommand(action, {
        description: (action === 'enable' ? 'Enable' : 'Disable') + ' a hook',
        plugins: [
            require('./_plugins/profile'),
        ],
        params: {
            'name': {
                description: 'The name of the hook to ' + action + '.',
                type: 'string',
                required: true,
            }
        },
        handler: createHandleUpdate(action),
    });
};
github auth0 / wt-cli / bin / create.js View on Github external
var Chalk = require('chalk');
var Cli = require('structured-cli');
var Logs = require('../lib/logs');
var ValidateCreateArgs = require('../lib/validateCreateArgs');
var WebtaskCreator = require('../lib/webtaskCreator');
var Url = require('url');
var _ = require('lodash');


module.exports = Cli.createCommand('create', {
    description: 'Create and update webtasks',
    plugins: [
        require('./_plugins/profile'),
    ],
    optionGroups: {
        'Output options': {
            output: {
                alias: 'o',
                description: 'Set the output format',
                choices: ['json'],
                type: 'string',
            },
            'show-token': {
                description: 'Show tokens (hidden by default)',
                dest: 'showToken',
                type: 'boolean',
github auth0 / wt-cli / bin / cron / create.js View on Github external
'use strict';

const Cli = require('structured-cli');
const Cron = require('../../lib/cron');
const Logs = require('../../lib/logs');
const PrintCronJob = require('../../lib/printCronJob');
const ValidateCreateArgs = require('../../lib/validateCreateArgs');
const WebtaskCreator = require('../../lib/webtaskCreator');
const _ = require('lodash');

const CRON_AUTH_MIDDLEWARE = '@webtask/cron-auth-middleware';
const CRON_AUTH_MIDDLEWARE_VERSION = '^1.2.1';

const createCommand = require('../create');

module.exports = Cli.createCommand('create', {
    description: 'Create a cron webtask',
    plugins: [require('../_plugins/profile')],
    optionGroups: _.extend({}, createCommand.optionGroups, {
        'Cron options': {
            'no-auth': {
                description: 'Disable cron webtask authentication',
                dest: 'noAuth',
                type: 'boolean',
            },
            schedule: {
                description:
                    'Either a cron-formatted schedule (see: http://crontab.guru/) or an interval of hours ("h") or minutes ("m"). Note that not all intervals are possible.',
                type: 'string',
                required: true,
            },
            state: {
github auth0 / wt-cli / bin / auth0_create.js View on Github external
var Chalk = require('chalk');
var Cli = require('structured-cli');
var CreateWebtask = require('../lib/createWebtask');
var ValidateCreateArgs = require('../lib/validateCreateArgs');
var Crypto = require('crypto');
var auth0Extensions = require('auth0-hooks-templates');
var extensionTypes = Object.keys(auth0Extensions).sort();

module.exports = Cli.createCommand('create', {
    description: 'Create or update Auth0 Hook',
    plugins: [
        require('./_plugins/profile'),
    ],
    optionGroups: {
        'Hook creation': {
            'type': {
                alias: 't',
                description: 'Hook type, required. One of: ' + extensionTypes.join(', ') + '.',
                choices: extensionTypes,
                required: true,
                dest: 'extensionName',
                metavar: 'TYPE',
                type: 'string'
            },
            'secret': {

structured-cli

Easily compose CLI applications from nested commands and categories

MIT
Latest version published 8 years ago

Package Health Score

42 / 100
Full package analysis

Popular structured-cli functions