|
10 | 10 | from connect.cli.core.config import pass_config |
11 | 11 | from connect.cli.core.terminal import console |
12 | 12 | from connect.cli.plugins.commerce.utils import ( |
| 13 | + clone_stream, |
13 | 14 | display_streams_table, |
14 | 15 | export_stream, |
| 16 | + get_destination_account, |
| 17 | + print_results, |
15 | 18 | ) |
16 | 19 |
|
17 | 20 |
|
@@ -102,5 +105,65 @@ def cmd_export_stream(config, stream_id, output_file, output_path): |
102 | 105 | ) |
103 | 106 |
|
104 | 107 |
|
| 108 | +@grp_commerce_streams.command( |
| 109 | + name='clone', |
| 110 | + short_help='Create a clone of a stream.', |
| 111 | +) |
| 112 | +@click.argument('source_stream_id', metavar='stream_id', nargs=1, required=True) # noqa: E304 |
| 113 | +@click.option( |
| 114 | + '--destination_account', |
| 115 | + '-d', |
| 116 | + 'destination_account', |
| 117 | + help='Destination account ID', |
| 118 | +) |
| 119 | +@click.option( |
| 120 | + '--new-stream-name', |
| 121 | + '-n', |
| 122 | + 'name', |
| 123 | + help='Cloned stream name', |
| 124 | +) |
| 125 | +@click.option( |
| 126 | + '--validate', |
| 127 | + '-v', |
| 128 | + is_flag=True, |
| 129 | + help='Executes the validate action after the clone.', |
| 130 | + default=False, |
| 131 | +) |
| 132 | +@pass_config |
| 133 | +def cmd_clone_stream( |
| 134 | + config, |
| 135 | + source_stream_id, |
| 136 | + destination_account, |
| 137 | + name, |
| 138 | + validate, |
| 139 | +): |
| 140 | + destination_account_instance = get_destination_account(config, destination_account) |
| 141 | + |
| 142 | + console.confirm( |
| 143 | + 'Are you sure you want to Clone ' f'the stream {source_stream_id} ?', |
| 144 | + abort=True, |
| 145 | + ) |
| 146 | + console.echo('') |
| 147 | + |
| 148 | + stream_id, results = clone_stream( |
| 149 | + origin_account=config.active, |
| 150 | + stream_id=source_stream_id, |
| 151 | + destination_account=destination_account_instance, |
| 152 | + stream_name=name, |
| 153 | + validate=validate, |
| 154 | + ) |
| 155 | + |
| 156 | + console.echo('') |
| 157 | + |
| 158 | + console.secho( |
| 159 | + f'Stream {source_stream_id} cloned properly to {stream_id}.', |
| 160 | + fg='green', |
| 161 | + ) |
| 162 | + |
| 163 | + console.echo('') |
| 164 | + |
| 165 | + print_results(results) |
| 166 | + |
| 167 | + |
105 | 168 | def get_group(): |
106 | 169 | return grp_commerce |
0 commit comments