menu method

Future<bool> menu()

Implementation

Future<bool> menu() async {
  // clear console
  clear();
  var version = await readVersion();
  print('Users CLI ' + version);

  // print the response of last operation
  print(_response);

  // controls the loop of the main menu
  var loop = true;

  // the main menu options
  var options = [
    'Create user',
    'Authenticate',
    'Create and authenticate',
    'Recover password',
    'Update e-mail',
    'Update password',
    'Delete user',
    'Configure',
    'Exit'
  ];

  var cli = prompts.choose('Menu', options, defaultsTo: options[0]);

  // printing the menu
  print(cli);

  try {
    // executing actions according the options
    if (cli == options[0]) {
      await optionCreateUser();
    } else if (cli == options[1]) {
      await optionAuthenticate();
    } else if (cli == options[2]) {
      await optionCreateAuthenticate();
    } else if (cli == options[3]) {
      await optionRecoverPassword();
    } else if (cli == options[4]) {
      await optionUpdateEmail();
    } else if (cli == options[5]) {
      await optionUpdatePassword();
    } else if (cli == options[6]) {
      await optionDeleteUser();
    } else if (cli == options[7]) {
      optionConfigure();
    } else if (cli == options[8]) {
      loop = false;
      clear();
    }
  } catch (e) {
    print(e);
  }

  return Future.value(loop);
}