How to use @twilio/cli-core - 10 common examples

To help you get started, we’ve selected a few @twilio/cli-core 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 twilio / twilio-cli / src / services / twilio-api / api-command-runner.js View on Github external
/* eslint no-warning-comments: "off" */
// TODO: Remove the above eslint directive when this file
// is free of TODO's.

const { doesObjectHaveProperty } = require('@twilio/cli-core').services.JSUtils;
const { TwilioCliError } = require('@twilio/cli-core').services.error;
const { logger } = require('@twilio/cli-core').services.logging;
const { TwilioApiFlags } = require('@twilio/cli-core').services.TwilioApi;
const { validateSchema } = require('../api-schema/schema-validator');
const { getFlagConfig } = require('./get-flag-config');

class ApiCommandRunner {
  constructor(twilioClient, actionDefinition, flagDefinitions, flagValues) {
    this.twilioClient = twilioClient;
    this.actionDefinition = actionDefinition;
    this.flagDefinitions = flagDefinitions;
    this.flagValues = flagValues;
  }

  async run() {
    this.validateFlags();

    return this.execute();
  }
github twilio / twilio-cli / src / services / twilio-api / get-flag-config.js View on Github external
const { kebabCase } = require('@twilio/cli-core').services.namingConventions;
const { TOPIC_SEPARATOR, BASE_TOPIC_NAME, CORE_TOPIC_NAME } = require('./get-topic-name');

// AccountSid is a special snowflake
const ACCOUNT_SID_FLAG = 'AccountSid';

const UPDATE_PHONE_NUMBER_COMMAND = [
  BASE_TOPIC_NAME,
  CORE_TOPIC_NAME,
  'incoming-phone-numbers',
  'update'
].join(TOPIC_SEPARATOR);

const getFlagName = paramName => {
  return kebabCase(
    paramName
      .replace('<', 'Before')
github twilio / twilio-cli / src / services / twilio-api / api-command-runner.js View on Github external
/* eslint no-warning-comments: "off" */
// TODO: Remove the above eslint directive when this file
// is free of TODO's.

const { doesObjectHaveProperty } = require('@twilio/cli-core').services.JSUtils;
const { TwilioCliError } = require('@twilio/cli-core').services.error;
const { logger } = require('@twilio/cli-core').services.logging;
const { TwilioApiFlags } = require('@twilio/cli-core').services.TwilioApi;
const { validateSchema } = require('../api-schema/schema-validator');
const { getFlagConfig } = require('./get-flag-config');

class ApiCommandRunner {
  constructor(twilioClient, actionDefinition, flagDefinitions, flagValues) {
    this.twilioClient = twilioClient;
    this.actionDefinition = actionDefinition;
    this.flagDefinitions = flagDefinitions;
    this.flagValues = flagValues;
  }

  async run() {
    this.validateFlags();

    return this.execute();
github twilio / twilio-cli / src / hooks / init / plugin-verification.js View on Github external
const { logger } = require('@twilio/cli-core').services.logging;
const { splitArray } = require('@twilio/cli-core').services.JSUtils;

const MessageTemplates = require('../../services/messaging/templates');

const checkCommandConflicts = (corePlugins, installedPlugins) => {
  const commandSet = new Set();

  const collisionCheck = (plugin, command) => {
    // If there's a collision or conflict, issue a stern warning.
    if (commandSet.has(command)) {
      logger.warn(MessageTemplates.commandConflict({ plugin: plugin.name, command: command }));
    }
    commandSet.add(command);
  };

  // Add every command and alias from the our core plugins to the unique collection.
github twilio / twilio-cli / src / base-commands / twilio-api-command.js View on Github external
/* eslint no-warning-comments: "off" */
// TODO: Remove the above eslint directive when this file
// is free of TODO's.

const { flags } = require('@oclif/command');
const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
const { doesObjectHaveProperty } = require('@twilio/cli-core').services.JSUtils;
const { logger } = require('@twilio/cli-core').services.logging;
const { camelCase } = require('@twilio/cli-core').services.namingConventions;
const { ApiCommandRunner, getActionDescription, getFlagConfig } = require('../services/twilio-api');

// Open API type to oclif flag type mapping. For numerical types, we'll do validation elsewhere.
const typeMap = {
  array: flags.string,
  boolean: flags.boolean,
  integer: flags.string,
  number: flags.string,
  string: flags.string,
  object: flags.string,
  undefined: flags.string // TODO: Handle "anyOf" case more explicitly
};
github twilio / twilio-cli / src / commands / profiles / list.js View on Github external
const chalk = require('chalk');
const { BaseCommand } = require('@twilio/cli-core').baseCommands;

class ProfilesList extends BaseCommand {
  async run() {
    await super.run();
    if (this.userConfig.profiles.length > 0) {
      // If none of the profiles have a region, delete it from all of them so it doesn't show up in the output.
      if (!this.userConfig.profiles.some(p => p.region)) {
        this.userConfig.profiles.forEach(p => delete p.region);
      }
      const activeProfile = this.userConfig.getActiveProfile();
      this.userConfig.profiles.forEach(p => {
        if (p.id === activeProfile.id) {
          p.active = true;
        }
      });
      this.output(this.userConfig.profiles);
github twilio / twilio-cli / src / base-commands / twilio-api-command.js View on Github external
logger.info(response ? 'The resource was deleted successfully' : 'Failed to delete the resource');
      return;
    }

    this.output(response, this.flags.properties);
  }
}

TwilioApiCommand.flags = Object.assign(
  {
    'skip-parameter-validation': flags.boolean({
      default: false,
      hidden: true
    })
  },
  TwilioClientCommand.flags
);

// A static function to help us add the other static
// fields required by oclif on our dynamically created
// command class.
TwilioApiCommand.setUpNewCommandClass = NewCommandClass => {
  const resource = NewCommandClass.actionDefinition.resource;
  const action = NewCommandClass.actionDefinition.action;
  const commandId = NewCommandClass.actionDefinition.topicName + ':' + NewCommandClass.actionDefinition.commandName;

  // Parameters
  let cmdFlags = {};
  (action.parameters || []).forEach(param => {
    const flagConfig = getFlagConfig(param, NewCommandClass.actionDefinition);
    const flagType = typeMap[param.schema.type];
github twilio / twilio-cli / src / commands / profiles / create.js View on Github external
ProfilesCreate.description = 'create a new profile to store Twilio Project credentials and configuration';

ProfilesCreate.flags = Object.assign(
  {
    'auth-token': flags.string({
      description: 'Your Twilio Auth Token for your Twilio Project.'
    }),
    force: flags.boolean({
      char: 'f',
      description: 'Force overwriting existing profile credentials.'
    }),
    region: flags.string({
      hidden: true
    })
  },
  TwilioClientCommand.flags // Yes! We _do_ want the same flags as TwilioClientCommand
);

ProfilesCreate.args = [
  {
    name: 'account-sid',
    description: 'The Account SID for your Twilio Project.'
  }
];

module.exports = ProfilesCreate;
github twilio / twilio-cli / src / base-commands / twilio-api-command.js View on Github external
});

  // 'remove' commands have no response body and thus do not need display properties.
  if (NewCommandClass.actionDefinition.commandName !== 'remove') {
    const defaultProperties = (resource && resource.defaultOutputProperties) || [];

    cmdFlags.properties = flags.string({
      // Camel-cased, CSV of the provided property list. Or just the SID.
      default: defaultProperties.map(prop => camelCase(prop)).join(',') || 'sid',
      description: 'The properties you would like to display (JSON output always shows all properties).'
    });
  }

  // 'list' commands get limit flags for specifying the result set size.
  if (NewCommandClass.actionDefinition.commandName === 'list') {
    cmdFlags = Object.assign(cmdFlags, TwilioClientCommand.limitFlags);
  }

  // Class statics
  NewCommandClass.id = commandId;
  NewCommandClass.args = [];
  NewCommandClass.flags = Object.assign(cmdFlags, TwilioApiCommand.flags);
  NewCommandClass.description = getActionDescription(NewCommandClass.actionDefinition);
  NewCommandClass.load = () => NewCommandClass;

  return NewCommandClass;
};
github twilio / twilio-cli / src / commands / profiles / remove.js View on Github external
const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
const { TwilioCliError } = require('@twilio/cli-core').services.error;

class ProfilesRemove extends TwilioClientCommand {
  async run() {
    await super.run();

    const deleteProfile = this.userConfig.getProfileById(this.args.profile);
    this.removeProfileStatus(deleteProfile, this.args.profile);
    const verdict = await this.confirmRemoveProfile();
    if (verdict === true) {
      const keyVerdict = await this.confirmRemoveKey();
      const credentials = await this.deleteLocalKey(deleteProfile);
      await this.deleteRemoteKey(deleteProfile, keyVerdict, credentials);
      this.logger.info('Deleted ' + deleteProfile.id + ' profile.');
      this.userConfig.removeProfile(deleteProfile);
    } else {
      throw new TwilioCliError('Cancelled');