Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename --default to --yes and no-default to --no in dstack config and dstack server #1709

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/dstack/_internal/cli/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ def _register(self):
self._parser.add_argument("--url", type=str, help="Server url")
self._parser.add_argument("--token", type=str, help="User token")
self._parser.add_argument(
"--default",
"-y",
"--yes",
help="Don't ask for confirmation (e.g. update the config)",
action="store_true",
help="Set the project as default. It will be used when --project is omitted in commands.",
default=False,
)
self._parser.add_argument(
"--remove", action="store_true", help="Delete project configuration"
)
self._parser.add_argument(
"--no-default",
help="Do not prompt to set the project as default",
"-n",
"--no",
help="Don't ask for confirmation (e.g. do not update the config)",
action="store_true",
)

Expand Down Expand Up @@ -71,11 +72,11 @@ def _command(self, args: argparse.Namespace):
):
set_it_as_default = (
(
args.default
args.yes
or not default_project
or confirm_ask(f"Set '{args.project}' as your default project?")
)
if not args.no_default
if not args.no
else False
)
config_manager.configure_project(
Expand Down
14 changes: 8 additions & 6 deletions src/dstack/_internal/cli/commands/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ def _register(self):
default=os.getenv("DSTACK_SERVER_LOG_LEVEL", "INFO"),
)
self._parser.add_argument(
"--default",
help="Update the default project configuration",
"-y",
"--yes",
help="Don't ask for confirmation (e.g. update the config)",
action="store_true",
)
self._parser.add_argument(
"--no-default",
help="Do not update the default project configuration",
"-n",
"--no",
help="Don't ask for confirmation (e.g. do not update the config)",
action="store_true",
)
self._parser.add_argument("--token", type=str, help="The admin user token")
Expand All @@ -52,9 +54,9 @@ def _command(self, args: Namespace):
os.environ["DSTACK_SERVER_HOST"] = args.host
os.environ["DSTACK_SERVER_PORT"] = str(args.port)
os.environ["DSTACK_SERVER_LOG_LEVEL"] = args.log_level
if args.default:
if args.yes:
os.environ["DSTACK_UPDATE_DEFAULT_PROJECT"] = "1"
if args.no_default:
if args.no:
os.environ["DSTACK_DO_NOT_UPDATE_DEFAULT_PROJECT"] = "1"
if args.token:
os.environ["DSTACK_SERVER_ADMIN_TOKEN"] = args.token
Expand Down
8 changes: 3 additions & 5 deletions src/dstack/_internal/core/services/configs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ def dstack_ssh_config_path(self) -> Path:
return self.dstack_ssh_dir / "config"


def update_default_project(
project_name: str, url: str, token: str, default: bool, no_default: bool
):
def update_default_project(project_name: str, url: str, token: str, yes: bool, no: bool):
config_manager = ConfigManager()
default_project = config_manager.get_project_config()
config_dir = str(config_manager.config_filepath).replace(os.path.expanduser("~"), "~", 1)
Expand All @@ -135,12 +133,12 @@ def update_default_project(
set_it_as_default = (
(
default_project is None
or default
or yes
or confirm_ask(
f"Update the [code]{project_name}[/] project in [code]{config_dir}[/]?"
)
)
if not no_default
if not no
else False
)
if set_it_as_default:
Expand Down
5 changes: 3 additions & 2 deletions src/dstack/_internal/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ async def lifespan(app: FastAPI):
project_name=DEFAULT_PROJECT_NAME,
url=SERVER_URL,
token=admin.token.get_plaintext_or_error(),
default=UPDATE_DEFAULT_PROJECT,
no_default=DO_NOT_UPDATE_DEFAULT_PROJECT,
yes=UPDATE_DEFAULT_PROJECT,
no=DO_NOT_UPDATE_DEFAULT_PROJECT,
)
if settings.SERVER_BUCKET is not None:
init_default_storage()
Expand Down Expand Up @@ -240,6 +240,7 @@ async def custom_http_exception_handler(request, exc):
.joinpath("statics/index.html")
.read_text()
)

else:

@app.get("/")
Expand Down