wifui 0.5.0

A lightweight, keyboard-driven Terminal User Interface (TUI) for managing Wi-Fi connections on Windows and Linux.
#!/usr/bin/env python3
import argparse
import re
import subprocess
import sys
from pathlib import Path

TARGETS = ["crates.io", "scoop", "choco", "winget"]


def select_target():
    print("Select publish target:")
    for idx, target in enumerate(TARGETS, 1):
        print(f"[{idx}] {target}", end="   ")
    print("\n")

    choice = input("Enter option (1-4): ").strip()
    if choice.isdigit() and 1 <= int(choice) <= len(TARGETS):
        return TARGETS[int(choice) - 1]

    print("Invalid option. Exiting.")
    sys.exit(1)


def publish_crates_io():
    cargo_file = Path("Cargo.toml")
    if not cargo_file.exists():
        print("Error: Cargo.toml not found in current directory.")
        sys.exit(1)

    content = cargo_file.read_text()

    # Extract current version
    match = re.search(r'^version\s*=\s*"([^"]+)"', content, re.MULTILINE)
    if not match:
        print("Error: Could not locate package version in Cargo.toml.")
        sys.exit(1)

    current_version = match.group(1)

    # Prompt to update version
    update_choice = (
        input(f"Do you want to update the version? [current: {current_version}] (y/N): ")
        .strip()
        .lower()
    )
    if update_choice in ("y", "yes"):
        new_version = input(f"Enter new version [current: {current_version}]: ").strip()
        if new_version:
            new_content = re.sub(
                r'^version\s*=\s*"[^"]+"',
                f'version = "{new_version}"',
                content,
                count=1,
                flags=re.MULTILINE,
            )
            cargo_file.write_text(new_content)
            print(f"Updated Cargo.toml: {current_version} -> {new_version}")

    # Prompt to publish
    publish_choice = input("Do you want to publish to crates.io? (y/N): ").strip().lower()
    if publish_choice in ("y", "yes"):
        try:
            subprocess.run(["cargo", "publish"], check=True)
        except subprocess.CalledProcessError as e:
            print(f"Failed to publish: {e}")
            sys.exit(1)


def publish_scoop():
    print("\nPublishing to Scoop...")
    pass


def publish_choco():
    print("\nPublishing to Chocolatey...")
    pass


def publish_winget():
    print("\nPublishing to WinGet...")
    pass


def main():
    parser = argparse.ArgumentParser(description="Rust package publishing helper.")
    group = parser.add_mutually_exclusive_group()
    group.add_argument("--crates", "--crates-io", action="store_true", help="Publish to crates.io")
    group.add_argument("--scoop", action="store_true", help="Publish to Scoop")
    group.add_argument("--choco", action="store_true", help="Publish to Chocolatey")
    group.add_argument("--winget", action="store_true", help="Publish to WinGet")

    args = parser.parse_args()

    if args.crates:
        target = "crates.io"
    elif args.scoop:
        target = "scoop"
    elif args.choco:
        target = "choco"
    elif args.winget:
        target = "winget"
    else:
        target = select_target()

    print(f"Selected: {target}\n")

    if target == "crates.io":
        publish_crates_io()
    elif target == "scoop":
        publish_scoop()
    elif target == "choco":
        publish_choco()
    elif target == "winget":
        publish_winget()


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print("\nAborted.")
        sys.exit(0)