How to use the cli-ux.prompt function in cli-ux

To help you get started, we’ve selected a few cli-ux 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 SakkuCloud / sakku-cli / src / commands / login.ts View on Github external
let user: { username: string, password: string } = { username: '', password: '' };

    const question = {
      name: 'way',
      message: 'There are two ways you can login:',
      type: 'list',
      choices: [{ name: 'Login by Username & Password' }, { name: 'Login by Browser' }]
    };

    const maxRepeat: number = 30;    // for login with browser
    const waitTime: number = 5000;   // for login with browser
    const code = makeId();           // for login with browser
    const answer: { way: string } = await inquirer.prompt([question]);

    if (answer.way === question.choices[0].name) { // login with username & password
      user.username = await cli.prompt(messages.username_req, { required: true });
      user.password = await cli.prompt(messages.password_req, { required: true, type: 'hide' });
      try {
        let data = (await authService.login(user)).data;   // sends user credentials to the server
        await writeToken(this, { token: data.result });    // write the access token in the file
        let value = await authService.overview(this);      // sends request the get the user's config
        let overview = JSON.stringify(value.data.result);
        await writeOverview(this, overview)                // write the user's config to the file
        console.log(color.green(messages.loggedin));
      }
      catch (e) {
        common.logError(e);
      }
    }
    else { // login with browser
      try {
        await opn(`${auth_url}${code}`, { wait: false });
github SakkuCloud / sakku-cli / src / commands / app / add.ts View on Github external
while (await cli.confirm(messages.labels)) {
      let param: string = await cli.prompt(messages.enter_your_label_key_msg);
      labels[param] = await cli.prompt(messages.enter_your_label_value_msg);
    }

    // while (await cli.confirm('Is there any/more links (y or n)')) {
    //   Add.link.name = await cli.prompt(enter_your_link_name_msg);
    //   Add.link.alias = await cli.prompt(enter_your_link_alias_msg);
    //   links.push(Add.link);
    // }

    while (await cli.confirm(messages.health_check)) {
      let tempObj: { endpoint: string, response: string, scheme: string } = { endpoint: '', response: '', scheme: '' };
      tempObj.endpoint = (await cli.prompt(messages.enter_your_check_point, { required: false })) || '/ping'
      tempObj.response = await cli.prompt(messages.enter_your_response, { required: true });
      tempObj.scheme = (await cli.prompt(messages.enter_your_scheme, { required: false })) || 'http';
      healthChecks.push(tempObj);
    }

    deployType = await inquirer.prompt<{ name: string }>({
      name: 'name',
      message: 'choose your deploy type:',
      type: 'list',
      choices: [
        { name: 'DOCKER_IMAGE' },
        { name: 'CODE' }
        // {name: 'APP'},
        // {name: 'DOCKER_FILE'}
      ]
    })
      .then(value => value.name);
github SakkuCloud / sakku-cli / src / commands / app / add.ts View on Github external
let scalingMode = await inquirer.prompt<{ name: string }>({
      name: 'name',
      message: 'choose scaling mode :',
      type: 'list',
      choices: [
        { name: 'CPU' },
        { name: 'MEM' },
        { name: 'AND' },
        { name: 'OR' },
        { name: 'OFF' }]
    })
      .then(value => value.name);

    while (await cli.confirm(messages.environment_vars)) {
      let param: string = await cli.prompt(messages.enter_your_environment_key_msg);
      environments[param] = await cli.prompt(messages.enter_your_environment_value_msg);
    }

    while (await cli.confirm(messages.labels)) {
      let param: string = await cli.prompt(messages.enter_your_label_key_msg);
      labels[param] = await cli.prompt(messages.enter_your_label_value_msg);
    }

    // while (await cli.confirm('Is there any/more links (y or n)')) {
    //   Add.link.name = await cli.prompt(enter_your_link_name_msg);
    //   Add.link.alias = await cli.prompt(enter_your_link_alias_msg);
    //   links.push(Add.link);
    // }

    while (await cli.confirm(messages.health_check)) {
      let tempObj: { endpoint: string, response: string, scheme: string } = { endpoint: '', response: '', scheme: '' };
      tempObj.endpoint = (await cli.prompt(messages.enter_your_check_point, { required: false })) || '/ping'
github SakkuCloud / sakku-cli / src / commands / app / scale.ts View on Github external
function getInstanceValue(message: string, minInstances: number, maxInstances: number) {
      let newMessage = message + ' (min:' + minInstances + ' ,max: ' + maxInstances + ')';
      return cli.prompt(newMessage, { required: true })
        .then(function (answer) {
          if (!(parseInt(answer) >= minInstances && parseInt(answer) <= maxInstances)) {
            return getInstanceValue(message, minInstances, maxInstances);
          }
          else {
            return answer;
          }
        });
    }
github nordcloud / cognitocurl / src / cognito / clibased.ts View on Github external
const GetTokenFromInput = async (poolData: any): Promise => {
  const username = await cli.prompt("Username");
  const password = await cli.prompt("Password", { type: "hide" });
  const authenticationData = {
    Username: username,
    Password: password
  };
  const authenticationDetails = new AuthenticationDetails(authenticationData);
  const userPool = new CognitoUserPool(poolData);
  const userData = {
    Username: username,
    Pool: userPool
  };
  const cognitoUser = new CognitoUser(userData);

  return new Promise((resolve, reject) => {
    cognitoUser.authenticateUser(authenticationDetails, {
      onSuccess: function(result: any) {
        const idToken: string = result.idToken.jwtToken;
github SakkuCloud / sakku-cli / src / commands / catalog.ts View on Github external
.then(function (result) {
          appDataObj.disk = parseFloat(result);
          return cli.prompt(messages.enter_your_app_name_msg, { required: true });
        })
        .then(function (result) {
github taneliheikkinen / heroku-wp-environment-sync / src / lib / Apps / RemoteApp.ts View on Github external
async handleMultipleEnvs () {
        ux.warn(`There is multiple db env variables defined (${this.constructEnvList(this.db_envs)}), which one is it?`)

        while(!this.db_env_name.length) {
            const db_env_name = await ux.prompt(`The db env variable name`) as string

            if(!this.hasAppEnv(db_env_name)) {
                ux.warn(`That env variable name (${Colors.env(db_env_name)}) doesn't exist in app (${Colors.app(this.name)})`);

                if(!(await ux.confirm("Want to to try again?"))) {
                    ux.error(`Ok, cannot resolve the db env variable name, so quitting.`)
                }
            } else {
                this.db_env_name = db_env_name
            }
        }

        return true
    }
github heroku / cli / packages / auth / src / commands / auth / 2fa / generate-recovery-codes.ts View on Github external
async run() {
    const password = await ux.prompt('Password', {type: 'hide'})
    const headers = {'Heroku-Password': password}
    const {body: codes} = await this.heroku.post('/account/recovery-codes', {headers})
    for (let code of codes) {
      ux.log(code)
    }
  }
}
github feinoujc / gh-search-cli / src / hooks / init / auth-questions.ts View on Github external
	username: () => cli.prompt('What is your github username?'),
	password: () =>