@oclif/command#flags TypeScript Examples

The following examples show how to use @oclif/command#flags. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: bundle.ts    From luabundler with MIT License 6 votes vote down vote up
async run() {
		const {args, flags} = this.parse(BundleCommand)
		const options: BundleOptions = {
			luaVersion: flags.lua,
			isolate: flags.isolate,
			expressionHandler: (module: Module, expression: Expression) => {
				const start = expression.loc!.start
				console.warn(`WARNING: Non-literal require found in '${module.name}' at ${start.line}:${start.column}`)
			},
		}

		if (flags.path.length > 0) {
			options.paths = flags.path
		}

		let content

		if (!args.file || args.file === '-') {
			content = bundleString(await readStdin(), options)
		} else {
			content = bundle(args.file, options)
		}

		if (flags.output) {
			const resolvedPath = resolvePath(flags.output)
			const resolvedDir = dirname(resolvedPath)

			if (!existsSync(resolvedDir)) {
				mkdirSync(resolvedDir, {recursive: true})
			}

			writeFileSync(flags.output, content)
		} else {
			console.log(content)
		}
	}
Example #2
Source File: commit.ts    From amplication with Apache License 2.0 6 votes vote down vote up
async command() {
    const { flags } = this.parse(AppsCommit);

    const appId = flags.app;
    if (!appId) {
      this.error(`Missing required flag: -a, --app`);
    } else {
      const message = flags.message;

      cli.action.start(`Committing changes`);
      const data = await commitChanges(this.client, appId, message);

      cli.action.stop();
      this.output(data, flags, COMMIT_COLUMNS);
    }
  }
Example #3
Source File: conserve.ts    From aws-cost-saver with MIT License 6 votes vote down vote up
private getEnabledTricks(flags: Record<string, any>): TrickInterface<any>[] {
    const tricksRegistry = TrickRegistry.initialize();
    const tricks = tricksRegistry.all();

    let enabledTricks: string[] = flags['no-default-tricks']
      ? []
      : ([] as string[]).concat(...Conserve.tricksEnabledByDefault);

    if (flags['use-trick'] && flags['use-trick'].length > 0) {
      enabledTricks.push(...flags['use-trick']);
    }

    if (flags['ignore-trick'] && flags['ignore-trick'].length > 0) {
      enabledTricks = enabledTricks.filter(
        trickName => !flags['ignore-trick'].includes(trickName),
      );
    }

    return enabledTricks.map(trickName => {
      const trick = tricks.find(trick => trick.getMachineName() === trickName);

      if (!trick) {
        this.log(`could not find a trick named ${chalk.yellow(trickName)}`);
        this.log(
          `run ${chalk.yellow(
            'aws-cost-saver conserve --help',
          )} to get a list of available tricks.\n`,
        );
        throw new Error('TrickNotFound');
      }

      return trick;
    });
  }
Example #4
Source File: typeorm-uml.class.ts    From typeorm-uml with MIT License 6 votes vote down vote up
/**
	 * Executes this command.
	 *
	 * @async
	 * @public
	 */
	public async run(): Promise<any> {
		try {
			const { args, flags } = this.parse( TypeormUmlCommand );

			const typeormUml = new TypeormUml();
			const colors = new Map<keyof Colors, string>();

			if ( Array.isArray( flags.color ) ) {
				flags.color.forEach( ( color ) => {
					if ( Array.isArray( color ) && color.length === 2 ) {
						colors.set( color[0], color[1] );
					}
				} );
			}

			typeormUml.build(
				args.configName,
				{
					...flags,
					colors,
					echo: true,
				}
			);
		} catch ( e ) {
			this.error( e.message );
		}
	}
Example #5
Source File: AbstractCommand.ts    From elasticsearch-index-migrate with MIT License 6 votes vote down vote up
async createHistoryIndex(): Promise<void> {
        const { flags } = this.parse() as any;
        const elasticsearchClient = getElasticsearchClient(this.migrationConfig.elasticsearch);
        const exists = await elasticsearchClient.exists({ index: MAPPING_HISTORY_INDEX_NAME });
        const { init } = flags as any;
        const number_of_shards = flags['number-of-shards'];
        const number_of_replicas = flags['number-of-replicas'];
        if (init && !exists) {
            cli.info('migrate_history index does not exist.');
            cli.info('Create a migrate_history index for the first time.');
            await createHistoryIndex(
                elasticsearchClient,
                usedEsVersion(this.migrationConfig.elasticsearch.version),
                number_of_shards,
                number_of_replicas
            );
            cli.info('The creation of the index has been completed.');
        } else if (!exists) {
            cli.error(
                'Migration environment is not ready. Execute the init command. Or, run the command with "--init"'
            );
            cli.exit(1);
        }
    }
Example #6
Source File: base-command.ts    From harness-cli with Apache License 2.0 6 votes vote down vote up
log(message: any) {
        if (this.context?.flags.silent) {
            return
        }

        if (_.isObject(message) && this.context?.flags.select) {
            message = _.get(message, this.context.flags.select, message)
        }
        
        if (_.isObject(message)) {
            console.log(JSON.stringify(message, undefined, 4))
        } else {
            console.log(message)
        }
    }
Example #7
Source File: index.ts    From google-photos-exif with MIT License 6 votes vote down vote up
async run() {
    const { args, flags} = this.parse(GooglePhotosExif);
    const { inputDir, outputDir, errorDir } = flags;

    try {
      const directories = this.determineDirectoryPaths(inputDir, outputDir, errorDir);
      await this.prepareDirectories(directories);
      await this.processMediaFiles(directories);
    } catch (error) {
      this.error(error);
      this.exit(1);
    }

    this.log('Done ?');
    this.exit(0);
  }
Example #8
Source File: open.ts    From relate with GNU General Public License v3.0 6 votes vote down vote up
static flags = {
        ...FLAGS.ENVIRONMENT,
        dbmsId: flags.string({
            char: 'D',
            description: 'The DBMS to automatically connect to',
            required: false,
        }),
        log: flags.boolean({
            char: 'L',
            description: 'If set, log the path instead',
            required: false,
        }),
        user: flags.string({
            char: 'u',
            description: 'The Neo4j DBMS user to automatically connect with, assuming an access token exists',
            required: false,
        }),
        project: flags.string({
            char: 'p',
            description: 'Name of a project context to connect with',
            required: false,
        }),
    };
Example #9
Source File: load.ts    From flan with MIT License 6 votes vote down vote up
static flags = {
    ...FlanCommand.flags,
    "drop-db": flags.boolean({
      default: false,
      description: "Drops and re-creates the DB before restoring it's data",
    }),
    quiet: flags.boolean({
      default: false,
      description: "Supress errors from pg_restore",
    }),
  };
Example #10
Source File: scaffold.ts    From loopback4-microservice-catalog with MIT License 6 votes vote down vote up
async run() {
    const input = this.parse(Scaffold);
    await super.generate('scaffold', {
      name: input.args.name,
      help: input.flags.help,
      cwd: input.flags.cwd,
      issuePrefix: input.flags.issuePrefix,
    });
  }
Example #11
Source File: log.ts    From tempomat with MIT License 6 votes vote down vote up
async run() {
        const { args, flags } = this.parse(Log)
        globalFlags.debug = flags.debug
        await tempo.addWorklog({
            issueKeyOrAlias: args.issue_key_or_alias,
            durationOrInterval: args.duration_or_interval,
            when: args.when,
            description: flags.description,
            startTime: flags.start,
            remainingEstimate: flags['remaining-estimate']
        })
    }
Example #12
Source File: login.ts    From zcli with Apache License 2.0 6 votes vote down vote up
async run () {
    const secureStore = new SecureStore()
    const keytar = await secureStore.loadKeytar()
    if (!keytar) {
      console.log(chalk.yellow('Failed to load secure credentials store: use environment variables to log in.'), HELP_ENV_VARS)
      return
    }

    const { flags } = this.parse(Login)
    const { interactive, subdomain } = flags

    if (interactive) {
      const auth = new Auth({ secureStore })
      const success = await auth.loginInteractively({ subdomain })
      if (success) {
        console.log(chalk.green('Successfully logged in.'))
      } else {
        console.log(chalk.red(`Failed to log in to your account: ${subdomain}.`))
      }
    } else {
      console.log('Browser login coming soon, use `zcli login -i` for interactive logins.')
    }
  }
Example #13
Source File: bundle.ts    From luabundler with MIT License 5 votes vote down vote up
static flags = {
		help: flags.help({char: 'h'}),
		isolate: flags.boolean({char: 'i', description: 'Disables require() fallback at runtime for modules not found in the bundle.', default: false}),
		lua: flags.enum<LuaVersion>({char: 'l', description: 'Lua syntax version', options: luaVersions, default: '5.3'}),
		output: flags.string({char: 'o', description: 'Bundle output path'}),
		path: flags.string({char: 'p', description: 'Add a require path pattern', multiple: true, required: true}),
		version: flags.version({char: 'v'}),
	}