| | | 1 | | import type { CliOptions } from '../../domain/CliOptions.js'; |
| | | 2 | | import { OperationMode } from '../../domain/OperationMode.js'; |
| | | 3 | | |
| | | 4 | | export class DispatchActionCommand { |
| | | 5 | | constructor( |
| | 22 | 6 | | public readonly map?: string, |
| | 22 | 7 | | public readonly envfile?: string, |
| | 22 | 8 | | public readonly key?: string, |
| | 22 | 9 | | public readonly value?: string, |
| | 22 | 10 | | public readonly secretPath?: string, |
| | 22 | 11 | | public readonly profile?: string, |
| | 22 | 12 | | public readonly mode: OperationMode = OperationMode.PULL_SECRETS_TO_ENV, |
| | | 13 | | ) {} |
| | | 14 | | |
| | | 15 | | static fromCliOptions(options: CliOptions): DispatchActionCommand { |
| | 17 | 16 | | const mode = DispatchActionCommand.determineOperationMode(options); |
| | 17 | 17 | | return new DispatchActionCommand( |
| | | 18 | | options.map, |
| | | 19 | | options.envfile, |
| | | 20 | | options.key, |
| | | 21 | | options.value, |
| | | 22 | | options.secretPath, |
| | | 23 | | options.profile, |
| | | 24 | | mode, |
| | | 25 | | ); |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | private static determineOperationMode(options: CliOptions): OperationMode { |
| | 17 | 29 | | if (options.key && options.value && options.secretPath) { |
| | 3 | 30 | | return OperationMode.PUSH_SINGLE; |
| | | 31 | | } |
| | | 32 | | |
| | 14 | 33 | | if (options.push) { |
| | 2 | 34 | | return OperationMode.PUSH_ENV_TO_SECRETS; |
| | | 35 | | } |
| | | 36 | | |
| | 12 | 37 | | return OperationMode.PULL_SECRETS_TO_ENV; |
| | | 38 | | } |
| | | 39 | | } |