blend/blend

500 lines
21 KiB
Text
Raw Normal View History

2023-01-18 11:36:57 -06:00
#!/usr/bin/env python3
2023-02-11 06:03:29 -06:00
# Copyright (C) 2023 Rudra Saraswat
#
# This file is part of blend.
#
# blend is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# blend is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with blend. If not, see <http://www.gnu.org/licenses/>.
import os, sys, getpass, time
2023-01-18 11:36:57 -06:00
import shutil
2023-02-11 06:03:29 -06:00
import socket
import pexpect
2023-01-18 11:36:57 -06:00
import argparse
import subprocess
2023-02-11 06:03:29 -06:00
__version = '2.0.0'
2023-01-18 11:36:57 -06:00
### Colors
class colors:
reset = '\033[0m'
bold = '\033[01m'
disable = '\033[02m'
underline = '\033[04m'
reverse = '\033[07m'
strikethrough = '\033[09m'
invisible = '\033[08m'
class fg:
black = '\033[30m'
red = '\033[31m'
green = '\033[32m'
orange = '\033[33m'
blue = '\033[34m'
purple = '\033[35m'
cyan = '\033[36m'
lightgrey = '\033[37m'
darkgrey = '\033[90m'
lightred = '\033[91m'
lightgreen = '\033[92m'
yellow = '\033[93m'
lightblue = '\033[94m'
pink = '\033[95m'
lightcyan = '\033[96m'
class bg:
black = '\033[40m'
red = '\033[41m'
green = '\033[42m'
orange = '\033[43m'
blue = '\033[44m'
purple = '\033[45m'
cyan = '\033[46m'
lightgrey = '\033[47m'
### END
### Helper functions
def info(msg):
print (colors.bold + colors.fg.cyan + '>> i: ' + colors.reset + colors.bold + msg + colors.reset)
def error(err):
print (colors.bold + colors.fg.red + '>> e: ' + colors.reset + colors.bold + err + colors.reset)
### END
distro_map = {
'arch': 'docker.io/library/archlinux',
2023-02-11 06:03:29 -06:00
'fedora-rawhide': 'docker.io/library/fedora:rawhide',
'ubuntu-22.04': 'docker.io/library/ubuntu:22.04',
'ubuntu-22.10': 'docker.io/library/ubuntu:22.10'
2023-01-18 11:36:57 -06:00
}
default_distro = 'arch'
def get_distro():
try:
return distro_map[args.distro]
except:
error(f"{args.distro} isn't supported by blend.")
exit()
2023-02-11 06:03:29 -06:00
def list_containers():
2023-01-18 11:36:57 -06:00
_list = subprocess.run(['podman', 'ps', '-a', '--no-trunc', '--size', '--format',
'{{.Names}}:{{.Mounts}}'], stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
if len(_list) == 0:
info('No containers. Create one by installing a package (`blend install hello`), or manually create one (`blend create-container arch`).')
2023-01-19 03:01:12 -06:00
else:
info('List of containers:')
2023-02-11 06:03:29 -06:00
for i, container in enumerate(_list.splitlines(keepends=False)):
if 'blend' in container.split(':')[1]:
print(f"{colors.bold}{i}.{colors.reset} {container.split(':')[0]}")
2023-01-18 11:36:57 -06:00
return False
2023-02-11 06:03:29 -06:00
def check_container(name):
2023-01-18 11:36:57 -06:00
_list = subprocess.run(['podman', 'ps', '-a', '--no-trunc', '--size', '--format',
'{{.Names}}:{{.Mounts}}'], stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
for container in _list.splitlines(keepends=False):
2023-02-11 06:03:29 -06:00
if 'blend' in container.split(':')[1] and name.strip() == container.split(':')[0]:
2023-01-18 11:36:57 -06:00
return True
return False
2023-02-11 06:03:29 -06:00
def check_container_status(name):
return host_get_output("podman inspect --type container " + name + " --format \"{{.State.Status}}\"")
def core_start_container(name):
subprocess.call(['podman', 'start', name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
start_time = time.time() - 1000 # workaround
if check_container_status(name) != 'running':
print('')
error('the entry point failed to run; try again later')
info("here are the container's logs:")
subprocess.call(['podman', 'logs', '--since', str(start_time), name])
exit(1)
logproc = pexpect.spawn('podman', args=['logs', '-f', '--since', str(start_time), name], timeout=300)
logproc.logfile_read = sys.stdout.buffer
logproc.expect('Completed container setup')
logproc.terminate()
def core_create_container():
2023-01-18 11:36:57 -06:00
name = args.container_name
distro = args.distro
info(f'creating container {name}, using {distro}')
2023-02-11 06:03:29 -06:00
podman_command = []
# Basic stuff
podman_command.extend(['podman', 'create', '--name', name])
podman_command.extend(['--hostname', name + '.' + socket.gethostname()])
podman_command.extend(['--privileged', '--ipc', 'host'])
podman_command.extend(['--network', 'host'])
podman_command.extend(['--security-opt', 'label=disable'])
podman_command.extend(['--user', 'root:root', '--pid', 'host'])
podman_command.extend(['--label', 'manager=blend']) # identify as blend container
# Env variables
podman_command.extend(['--env', 'HOME=' + os.path.expanduser('~')])
# Volumes
podman_command.extend(['--volume', '/:/run/host:rslave'])
podman_command.extend(['--volume', '/tmp:/tmp:rslave'])
podman_command.extend(['--volume', f"{os.path.expanduser('~')}:{os.path.expanduser('~')}:rslave"])
podman_command.extend(['--volume', f"/run/user/{os.geteuid()}:/run/user/{os.geteuid()}:rslave"])
# Volumes (config files)
podman_command.extend(['--volume', f"/etc/hosts:/etc/hosts:ro"])
podman_command.extend(['--volume', f"/etc/localtime:/etc/localtime:ro"])
podman_command.extend(['--volume', f"/etc/resolv.conf:/etc/resolv.conf:ro"])
# Volumes (files and tools)
podman_command.extend(['--volume', '/usr/bin/init-blend:/usr/bin/init-blend:ro',
'--entrypoint', '/usr/bin/init-blend']) # our entrypoint
podman_command.extend(['--volume', '/usr/bin/host-blend:/usr/bin/host-blend:ro']) # and the tool to run commands on the host
podman_command.extend(['--volume', '/var/log/journal'])
podman_command.extend(['--mount', 'type=devpts,destination=/dev/pts',
'--userns', 'keep-id',
'--annotation', 'run.oci.keep_original_groups=1'])
podman_command.extend([get_distro()])
# User (for init-blend)
podman_command.extend(['--uid', str(os.geteuid())])
podman_command.extend(['--group', str(os.getgid())])
podman_command.extend(['--username', getpass.getuser()])
podman_command.extend(['--home', os.path.expanduser('~')])
ret = subprocess.run(podman_command).returncode
if ret != 0:
if check_container(name):
2023-01-18 11:36:57 -06:00
error(f'container {name} already exists')
exit(1)
error(f'failed to create container {name}')
exit(1)
2023-02-11 06:03:29 -06:00
core_start_container(name)
2023-01-18 11:36:57 -06:00
if distro == 'arch':
2023-02-11 06:03:29 -06:00
core_run_container('sudo pacman -Sy')
core_run_container('sudo pacman --noconfirm -Syu --needed git base-devel')
core_run_container('TEMP_DIR="$(mktemp -d)"; cd "${TEMP_DIR}"; git clone https://aur.archlinux.org/yay.git; cd yay; makepkg --noconfirm -si; rm -rf "${TEMP_DIR}"')
core_get_output = lambda cmd: subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode('UTF-8').strip()
host_get_output = lambda cmd: subprocess.run(['bash', '-c', cmd],
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode('UTF-8').strip()
2023-01-18 11:36:57 -06:00
2023-02-11 06:03:29 -06:00
core_get_retcode = lambda cmd: subprocess.run(['podman', 'exec', '--user', getpass.getuser(), '-it', args.container_name, 'bash', '-c', cmd],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode
2023-01-18 11:36:57 -06:00
2023-02-11 06:03:29 -06:00
def core_run_container(cmd):
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
subprocess.call(['podman', 'exec', '--user', getpass.getuser(), '-w', os.getcwd(), '-it', args.container_name, 'bash', '-c', cmd])
2023-01-18 11:36:57 -06:00
2023-02-11 06:03:29 -06:00
def core_install_pkg(pkg):
2023-01-18 11:36:57 -06:00
if args.distro == 'fedora-rawhide':
if args.noconfirm == True:
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo dnf -y install {pkg}')
2023-01-18 11:36:57 -06:00
else:
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo dnf install {pkg}')
2023-01-18 11:36:57 -06:00
elif args.distro == 'arch':
2023-02-11 06:03:29 -06:00
if core_get_retcode('[ -f /usr/bin/yay ]') != 0:
core_run_container('sudo pacman -Sy')
core_run_container('sudo pacman --noconfirm -Syu --needed git base-devel')
core_run_container('TEMP_DIR="$(mktemp -d)"; cd "${TEMP_DIR}"; git clone https://aur.archlinux.org/yay.git; cd yay; makepkg --noconfirm -si; rm -rf "${TEMP_DIR}"')
core_run_container(f'yay -Sy')
2023-01-18 11:36:57 -06:00
if args.noconfirm == True:
2023-02-11 06:03:29 -06:00
core_run_container(f'yay --noconfirm -Syu {pkg}')
2023-01-18 11:36:57 -06:00
else:
2023-02-11 06:03:29 -06:00
core_run_container(f'yay -Syu {pkg}')
2023-01-18 11:36:57 -06:00
elif args.distro.startswith('ubuntu-'):
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo apt-get update')
2023-01-18 11:36:57 -06:00
if args.noconfirm == True:
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo apt-get install -y {pkg}')
2023-01-18 11:36:57 -06:00
else:
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo apt-get install {pkg}')
2023-01-18 11:36:57 -06:00
2023-02-11 06:03:29 -06:00
def core_remove_pkg(pkg):
2023-01-18 11:36:57 -06:00
if args.distro == 'fedora-rawhide':
if args.noconfirm == True:
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo dnf -y remove {pkg}')
2023-01-18 11:36:57 -06:00
else:
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo dnf remove {pkg}')
2023-01-18 11:36:57 -06:00
elif args.distro == 'arch':
if args.noconfirm == True:
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo pacman --noconfirm -Rcns {pkg}')
2023-01-18 11:36:57 -06:00
else:
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo pacman -Rcns {pkg}')
2023-01-18 11:36:57 -06:00
elif args.distro.startswith('ubuntu-'):
if args.noconfirm == True:
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo apt-get purge -y {pkg}')
2023-01-18 11:36:57 -06:00
else:
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo apt-get purge {pkg}')
core_run_container(f'sudo apt-get autoremove --purge -y {pkg}')
2023-01-18 11:36:57 -06:00
2023-02-11 06:03:29 -06:00
def core_search_pkg(pkg):
2023-01-18 11:36:57 -06:00
if args.distro == 'fedora-rawhide':
2023-02-11 06:03:29 -06:00
core_run_container(f'dnf search {pkg}')
2023-01-18 11:36:57 -06:00
elif args.distro == 'arch':
2023-02-11 06:03:29 -06:00
core_run_container(f'yay -Sy')
core_run_container(f'yay {pkg}')
2023-01-18 11:36:57 -06:00
elif args.distro.startswith('ubuntu-'):
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo apt-get update')
core_run_container(f'apt-cache search {pkg}')
2023-01-18 11:36:57 -06:00
2023-02-11 06:03:29 -06:00
def core_show_pkg(pkg):
2023-01-18 11:36:57 -06:00
if args.distro == 'fedora-rawhide':
2023-02-11 06:03:29 -06:00
core_run_container(f'dnf info {pkg}')
2023-01-18 11:36:57 -06:00
elif args.distro == 'arch':
2023-02-11 06:03:29 -06:00
core_run_container(f'yay -Sy')
core_run_container(f'yay -Si {pkg}')
2023-01-18 11:36:57 -06:00
elif args.distro.startswith('ubuntu-'):
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo apt-get update')
core_run_container(f'apt-cache show {pkg}')
2023-01-18 11:36:57 -06:00
def install_blend():
if len(args.pkg) == 0:
error('no packages to install')
for pkg in args.pkg:
info(f'installing blend {pkg}')
2023-02-11 06:03:29 -06:00
if not check_container(args.container_name):
core_create_container()
core_install_pkg(pkg)
2023-01-18 11:36:57 -06:00
def remove_blend():
if len(args.pkg) == 0:
error('no packages to remove')
for pkg in args.pkg:
info(f'removing blend {pkg}')
2023-02-11 06:03:29 -06:00
if not check_container(args.container_name):
2023-01-18 11:36:57 -06:00
error(f"container {args.container_name} doesn't exist")
2023-02-11 06:03:29 -06:00
core_remove_pkg(pkg)
2023-01-18 11:36:57 -06:00
def search_blend():
if len(args.pkg) == 0:
error('no packages to search for')
for pkg in args.pkg:
2023-02-11 06:03:29 -06:00
if not check_container(args.container_name):
2023-01-18 11:36:57 -06:00
error(f"container {args.container_name} doesn't exist")
2023-02-11 06:03:29 -06:00
core_search_pkg(pkg)
2023-01-18 11:36:57 -06:00
def show_blend():
if len(args.pkg) == 0:
error('no packages to show')
for pkg in args.pkg:
info(f'info about blend {pkg}')
2023-02-11 06:03:29 -06:00
if not check_container(args.container_name):
2023-01-18 11:36:57 -06:00
error(f"container {args.container_name} doesn't exist")
2023-02-11 06:03:29 -06:00
core_show_pkg(pkg)
2023-01-18 11:36:57 -06:00
def sync_blends():
if args.distro == 'fedora-rawhide':
2023-02-11 06:03:29 -06:00
core_run_container(f'dnf makecache')
2023-01-18 11:36:57 -06:00
elif args.distro == 'arch':
2023-02-11 06:03:29 -06:00
core_run_container(f'yay -Syy')
2023-01-18 11:36:57 -06:00
elif args.distro.startswith('ubuntu-'):
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo apt-get update')
2023-01-18 11:36:57 -06:00
def update_blends():
if args.distro == 'fedora-rawhide':
if args.noconfirm == True:
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo dnf -y upgrade')
2023-01-18 11:36:57 -06:00
else:
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo dnf upgrade')
2023-01-18 11:36:57 -06:00
elif args.distro == 'arch':
if args.noconfirm == True:
2023-02-11 06:03:29 -06:00
core_run_container(f'yay --noconfirm')
2023-01-18 11:36:57 -06:00
else:
2023-02-11 06:03:29 -06:00
core_run_container(f'yay')
2023-01-18 11:36:57 -06:00
elif args.distro.startswith('ubuntu-'):
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo apt-get update')
2023-01-18 11:36:57 -06:00
if args.noconfirm == True:
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo apt-get dist-upgrade -y')
2023-01-18 11:36:57 -06:00
else:
2023-02-11 06:03:29 -06:00
core_run_container(f'sudo apt-get dist-upgrade')
2023-01-18 11:36:57 -06:00
else:
error(f'distribution {args.distro} is not supported')
def enter_container():
2023-02-11 06:03:29 -06:00
if os.environ.get('BLEND_NO_CHECK') == None:
if not check_container(args.container_name):
core_create_container()
if check_container_status(args.container_name) != 'running':
core_start_container(args.container_name)
podman_args = []
sudo = []
if os.environ.get('SUDO_USER') == None:
podman_args = ['--user', getpass.getuser()]
else:
sudo = ['sudo', '-u', os.environ.get('SUDO_USER'), f'PATH={os.path.expanduser("~/.local/share/bin/blend_bin")}:/usr/bin']
for name, val in os.environ.items():
if name not in ['LANG', 'LC_CTYPE', 'PATH', 'HOST', 'HOSTNAME', 'SHELL'] and not name.startswith('_'):
podman_args.append('--env')
podman_args.append(name + '=' + val)
2023-01-19 03:01:12 -06:00
if os.environ.get('BLEND_COMMAND') == None or os.environ.get('BLEND_COMMAND') == '':
2023-02-11 06:03:29 -06:00
if args.pkg == []:
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w', os.getcwd(), '-it', args.container_name, 'bash']))
else:
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w', '/run/host' + os.getcwd(), '-it', args.container_name, 'bash']))
else:
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w', os.getcwd(), '-it', args.container_name, *args.pkg]))
else:
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w', '/run/host' + os.getcwd(), '-it', args.container_name, *args.pkg]))
2023-01-19 03:01:12 -06:00
else:
2023-02-11 06:03:29 -06:00
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w', os.getcwd(), '-it', args.container_name, 'bash', '-c', os.environ.get('BLEND_COMMAND')]))
else:
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w', '/run/host' + os.getcwd(), '-it', args.container_name, 'bash']))
2023-01-18 11:36:57 -06:00
def create_container():
for container in args.pkg:
args.container_name = container
2023-01-26 04:18:52 -06:00
if container in distro_map.keys() and distro_input == None:
2023-01-27 08:54:49 -06:00
args.distro = container
2023-02-11 06:03:29 -06:00
core_create_container()
2023-01-18 11:36:57 -06:00
def remove_container():
for container in args.pkg:
info(f'removing container {container}')
2023-01-19 03:01:12 -06:00
subprocess.run(['podman', 'stop', container], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
2023-02-11 06:03:29 -06:00
subprocess.run(['podman', 'rm', '-f', container], stdout=subprocess.DEVNULL)
2023-01-18 11:36:57 -06:00
def start_containers():
_list = subprocess.run(['podman', 'ps', '-a', '--no-trunc', '--size', '--format',
'{{.Names}}:{{.Mounts}}'], stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
if len(_list) == 0:
2023-02-11 06:03:29 -06:00
info('No containers. Create one by installing a package (`blend install hello`), or manually create one (`blend create-container -d arch`).')
2023-01-18 11:36:57 -06:00
for container in _list.splitlines(keepends=False):
container = container.split(':')[0]
info(f'starting container {container}')
2023-02-11 06:03:29 -06:00
subprocess.call(['podman', 'start', container])
2023-01-18 11:36:57 -06:00
2023-02-11 06:03:29 -06:00
if shutil.which('podman') is None:
error("podman isn't installed, which is a hard dep")
2023-01-18 11:36:57 -06:00
exit(1)
2023-02-11 06:03:29 -06:00
if os.geteuid() == 0 and os.environ['BLEND_ALLOW_ROOT'] == None:
2023-01-18 11:36:57 -06:00
error("do not run as root")
exit(1)
description = f'''
{colors.bold}{colors.fg.purple}Usage:{colors.reset}
blend [command] [options] [arguments]
{colors.bold}{colors.fg.purple}Version:{colors.reset} {__version}{colors.bold}
{colors.bold}{colors.bg.purple}blend{colors.reset}{colors.bold} is a package manager for {colors.bg.purple}blendOS{colors.reset}{colors.bold}, which includes support for Arch, Ubuntu and Fedora packages.{colors.reset}
{colors.bold}{colors.fg.purple}default distro{colors.reset}: {colors.bold}{colors.fg.lightblue}arch{colors.reset} (default container's name is the same as that of the default distro)
Here's a list of the supported distros:
{colors.bold}1.{colors.reset} arch
{colors.bold}2.{colors.reset} fedora-rawhide
{colors.bold}3.{colors.reset} ubuntu-22.04
{colors.bold}4.{colors.reset} ubuntu-22.10
(debian support is coming soon)
You can use any of these distros by passing the option {colors.bold}--distro=[NAME OF THE DISTRO]{colors.reset}.
2023-01-18 11:47:47 -06:00
You can even install a supported desktop environment in a blend container (run `blend install-de [DESKTOP ENVIRONMENT NAME]` to install your favorite desktop environment).
2023-01-19 03:01:12 -06:00
However, this feature is still somewhat experimental, and some apps might be buggy.
2023-01-18 11:47:47 -06:00
Here's a list of the supported desktop environments:
{colors.bold}1.{colors.reset} gnome
{colors.bold}2.{colors.reset} mate
(support for many more DEs is coming soon)
2023-01-18 11:36:57 -06:00
{colors.bold}{colors.fg.lightblue}arch{colors.reset} also supports AUR packages, for an extremely large app catalog.
{colors.bold}{colors.fg.purple}available commands{colors.reset}:
{colors.bold}help{colors.reset} Show this help message and exit.
{colors.bold}version{colors.reset} Show version information and exit.
{colors.bold}enter{colors.reset} Enter the container shell.
{colors.bold}install{colors.reset} Install packages inside a container.
{colors.bold}remove{colors.reset} Remove packages inside a managed container.
{colors.bold}create-container{colors.reset} Create a container managed by blend.
{colors.bold}remove-container{colors.reset} Remove a container managed by blend.
{colors.bold}list-containers{colors.reset} List all the containers managed by blend.
{colors.bold}start-containers{colors.reset} Start all the container managed by blend.
{colors.bold}sync{colors.reset} Sync list of available packages from repository.
{colors.bold}search{colors.reset} Search for packages in a managed container.
{colors.bold}show{colors.reset} Show details about a package.
{colors.bold}update{colors.reset} Update all the packages in a managed container.
{colors.bold}{colors.fg.purple}options for commands{colors.reset}:
{colors.bold}-cn CONTAINER NAME, --container-name CONTAINER NAME{colors.reset}
set the container name (the default is the name of the distro)
{colors.bold}-d DISTRO, --distro DISTRO{colors.reset}
set the distro name (supported: arch fedora-rawhide ubuntu-22.04 ubuntu-22.10; default is arch)
{colors.bold}-y, --noconfirm{colors.reset} assume yes for all questions
{colors.bold}-v, --version{colors.reset} show version information and exit
'''
epilog = f'''
{colors.bold}Made with {colors.fg.red}\u2764{colors.reset}{colors.bold} by Rudra Saraswat.{colors.reset}
'''
parser = argparse.ArgumentParser(description=description, usage=argparse.SUPPRESS,
epilog=epilog, formatter_class=argparse.RawTextHelpFormatter)
command_map = { 'install': install_blend,
'remove': remove_blend,
'enter': enter_container,
2023-02-11 06:03:29 -06:00
'create-container': core_create_container,
2023-01-18 11:36:57 -06:00
'remove-container': remove_container,
2023-02-11 06:03:29 -06:00
'list-containers': list_containers,
2023-01-18 11:36:57 -06:00
'start-containers': start_containers,
'sync': sync_blends,
'update': update_blends,
'search': search_blend,
'show': show_blend,
'help': 'help',
'version': 'version' }
parser.add_argument('command', choices=command_map.keys(), help=argparse.SUPPRESS)
parser.add_argument('pkg', action='store', type=str, nargs='*', help=argparse.SUPPRESS)
parser.add_argument('-cn', '--container-name', action='store', nargs=1, metavar='CONTAINER NAME', help=argparse.SUPPRESS)
parser.add_argument('-y', '--noconfirm', action='store_true', help=argparse.SUPPRESS)
parser.add_argument('-d', '--distro', action='store', nargs=1, metavar='DISTRO', help=argparse.SUPPRESS)
parser.add_argument('-v', '--version', action='version', version=f'%(prog)s {__version}', help=argparse.SUPPRESS)
if len(sys.argv) == 1:
parser.print_help()
exit()
args = parser.parse_intermixed_args()
2023-01-19 03:01:12 -06:00
command = command_map[args.command]
2023-01-18 11:36:57 -06:00
distro_input = args.distro
args.distro = default_distro if args.distro == None else args.distro[0]
cn_input = args.container_name
args.container_name = args.distro if args.container_name == None else args.container_name[0]
if command == 'help':
parser.print_help()
elif command == 'version':
parser.parse_args(['--version'])
else:
2023-01-19 03:01:12 -06:00
command()