runWithConfig method

  1. @override
Future<void> runWithConfig(
  1. Configuration<PasswordSetCommandConfig> commandConfig
)
override

Runs this command with prepared configuration (options). Subclasses should override this method.

Implementation

@override
Future<void> runWithConfig(
  final Configuration<PasswordSetCommandConfig> commandConfig,
) async {
  final projectId = commandConfig.value(PasswordSetCommandConfig.projectId);
  final name = commandConfig.value(PasswordSetCommandConfig.name);
  final value = commandConfig.optionalValue(PasswordSetCommandConfig.value);
  final valueFile = commandConfig.optionalValue(
    PasswordSetCommandConfig.valueFile,
  );

  String valueToSet;
  if (value != null) {
    valueToSet = value;
  } else if (valueFile != null) {
    valueToSet = valueFile.readAsStringSync();
  } else {
    throw ErrorExitException(
      'Either a value or --from-file must be provided.',
    );
  }

  await PasswordCommands.setPassword(
    runner.serviceProvider.cloudApiClient,
    logger: logger,
    projectId: projectId,
    name: name,
    value: valueToSet,
  );
}