feat(cli): add first-run automatic interactive alias prompt for pip installations
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
@@ -454,6 +456,37 @@ def cmd_uninstall(args: List[str]) -> int:
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
def _check_first_run_alias_prompt() -> None:
|
||||||
|
user_home = Path.home()
|
||||||
|
gravitiny_home = user_home / ".gravitiny"
|
||||||
|
config_file = gravitiny_home / "config.json"
|
||||||
|
bin_dir = gravitiny_home / "bin"
|
||||||
|
|
||||||
|
if not config_file.exists():
|
||||||
|
gravitiny_home.mkdir(parents=True, exist_ok=True)
|
||||||
|
bin_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(config_file, "w", encoding="utf-8") as f:
|
||||||
|
json.dump({"first_run": True, "created_at": time.time()}, f, indent=2)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# If interactive terminal, prompt user for custom alias
|
||||||
|
if sys.stdin.isatty():
|
||||||
|
try:
|
||||||
|
shim_gen = ShimGenerator(bin_dir=bin_dir)
|
||||||
|
alias_prompt = input(catalog.get("commands.alias.prompt_ask_alias")).strip().lower()
|
||||||
|
if alias_prompt in ["y", "yes"]:
|
||||||
|
alias_name = input(catalog.get("commands.alias.prompt_enter_alias")).strip().lower()
|
||||||
|
if alias_name:
|
||||||
|
shim_gen.generate_master_shim(alias=alias_name)
|
||||||
|
print(catalog.format("commands.alias.success_gravitiny", alias=alias_name, bin_dir=bin_dir))
|
||||||
|
print()
|
||||||
|
except (KeyboardInterrupt, EOFError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def run_cli(args: Optional[List[str]] = None) -> int:
|
def run_cli(args: Optional[List[str]] = None) -> int:
|
||||||
if hasattr(sys.stdout, "reconfigure"):
|
if hasattr(sys.stdout, "reconfigure"):
|
||||||
try:
|
try:
|
||||||
@@ -462,6 +495,8 @@ def run_cli(args: Optional[List[str]] = None) -> int:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
_check_first_run_alias_prompt()
|
||||||
|
|
||||||
raw_args = args if args is not None else sys.argv[1:]
|
raw_args = args if args is not None else sys.argv[1:]
|
||||||
|
|
||||||
if not raw_args or raw_args[0] in ["-h", "--help", "help"]:
|
if not raw_args or raw_args[0] in ["-h", "--help", "help"]:
|
||||||
|
|||||||
Reference in New Issue
Block a user