afegeix --create-default-config
This commit is contained in:
+27
-1
@@ -72,6 +72,21 @@ class RepoEntry:
|
|||||||
|
|
||||||
# --- config -----------------------------------------------------------------
|
# --- config -----------------------------------------------------------------
|
||||||
|
|
||||||
|
def create_default_config() -> int:
|
||||||
|
if CONFIG_PATH.exists():
|
||||||
|
console.print(f"[yellow]Ya existe[/yellow] [bold]{CONFIG_PATH}[/bold] — no se sobreescribe.")
|
||||||
|
return 1
|
||||||
|
try:
|
||||||
|
CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
CONFIG_PATH.write_text(CONFIG_EXAMPLE)
|
||||||
|
except OSError as e:
|
||||||
|
console.print(f"[red]No se pudo escribir {CONFIG_PATH}: {e}[/red]")
|
||||||
|
return 1
|
||||||
|
console.print(f"[green]Config creada en[/green] [bold]{CONFIG_PATH}[/bold]")
|
||||||
|
console.print("[dim]Edítala y descomenta token / default_owner / clone_protocol si los necesitas.[/dim]")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def load_config() -> Config:
|
def load_config() -> Config:
|
||||||
if not CONFIG_PATH.exists():
|
if not CONFIG_PATH.exists():
|
||||||
console.print(f"[red]No se ha encontrado la configuración en[/red] [bold]{CONFIG_PATH}[/bold]")
|
console.print(f"[red]No se ha encontrado la configuración en[/red] [bold]{CONFIG_PATH}[/bold]")
|
||||||
@@ -421,10 +436,21 @@ def main() -> int:
|
|||||||
description="Lista repos en un servidor Gitea y clona los que faltan en local.",
|
description="Lista repos en un servidor Gitea y clona los que faltan en local.",
|
||||||
)
|
)
|
||||||
parser.add_argument("-v", "--version", action="version", version=f"repoman v{__version__}")
|
parser.add_argument("-v", "--version", action="version", version=f"repoman v{__version__}")
|
||||||
parser.add_argument("path", type=Path, help="Carpeta local donde se clonarán los repos")
|
parser.add_argument(
|
||||||
|
"--create-default-config",
|
||||||
|
action="store_true",
|
||||||
|
help=f"Crea un fichero de config por defecto en {CONFIG_PATH} y sale",
|
||||||
|
)
|
||||||
|
parser.add_argument("path", type=Path, nargs="?", help="Carpeta local donde se clonarán los repos")
|
||||||
parser.add_argument("owner", nargs="?", help="Usuario u organización en Gitea (opcional si default_owner está en la config)")
|
parser.add_argument("owner", nargs="?", help="Usuario u organización en Gitea (opcional si default_owner está en la config)")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.create_default_config:
|
||||||
|
return create_default_config()
|
||||||
|
|
||||||
|
if args.path is None:
|
||||||
|
parser.error("falta el argumento path")
|
||||||
|
|
||||||
if shutil.which("git") is None:
|
if shutil.which("git") is None:
|
||||||
console.print("[red]git no está instalado o no se encuentra en el PATH[/red]")
|
console.print("[red]git no está instalado o no se encuentra en el PATH[/red]")
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
Reference in New Issue
Block a user