run method

  1. @override
Future<int> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<int> run() async {
  try {
    final password = argResults!['password'] as String;
    final input = argResults!.rest.isNotEmpty ? argResults!.rest[0] : '.env';
    final output = argResults!.rest.length > 1
        ? argResults!.rest[1]
        : '$input.encrypted';

    await EnvCrypto.encryptFile(input, output, password);
    CliLogger.success('Encryption completed successfully');
    return 0;
  } catch (e) {
    CliLogger.error('Encryption failed: $e');
    return 64;
  }
}