|
1 | 1 | import argparse |
2 | | -from pathlib import Path |
3 | 2 |
|
4 | 3 | from argcomplete import FilesCompleter |
5 | 4 |
|
6 | 5 | from dstack._internal.cli.commands import APIBaseCommand |
7 | 6 | from dstack._internal.cli.services.configurators import ( |
| 7 | + APPLY_STDIN_NAME, |
8 | 8 | get_apply_configurator_class, |
9 | 9 | load_apply_configuration, |
10 | 10 | ) |
@@ -40,9 +40,12 @@ def _register(self): |
40 | 40 | self._parser.add_argument( |
41 | 41 | "-f", |
42 | 42 | "--file", |
43 | | - type=Path, |
44 | 43 | metavar="FILE", |
45 | | - help="The path to the configuration file. Defaults to [code]$PWD/.dstack.yml[/]", |
| 44 | + help=( |
| 45 | + "The path to the configuration file." |
| 46 | + " Specify [code]-[/] to read configuration from stdin." |
| 47 | + " Defaults to [code]$PWD/.dstack.yml[/]" |
| 48 | + ), |
46 | 49 | dest="configuration_file", |
47 | 50 | ).completer = FilesCompleter(allowednames=["*.yml", "*.yaml"]) |
48 | 51 | self._parser.add_argument( |
@@ -104,6 +107,10 @@ def _command(self, args: argparse.Namespace): |
104 | 107 | return |
105 | 108 |
|
106 | 109 | super()._command(args) |
| 110 | + if not args.yes and args.configuration_file == APPLY_STDIN_NAME: |
| 111 | + # FIXME: probably does not work since dstack apply can ask questions futher, |
| 112 | + # e.g. whether to terminate a resource on ctrl+c or not |
| 113 | + raise CLIError("Cannot read configuration from stdin if -y/--yes is not specified") |
107 | 114 | if args.repo and args.no_repo: |
108 | 115 | raise CLIError("Either --repo or --no-repo can be specified") |
109 | 116 | repo = None |
|
0 commit comments