feat: Add CLI command to edit NormalSub subpath
- Added `edit_normalsub_subpath` function to `cli_api.py` to
interact with the `normalsub.sh edit_subpath` command, including
input validation for the new subpath.
- Updated the `normal-sub` command in `cli.py`:
- Added 'edit_subpath' as a valid action.
- Introduced a '--subpath' option for specifying the new path.
- Modified the command logic to call the new API function when
the 'edit_subpath' action is selected.
This commit is contained in:
16
core/cli.py
16
core/cli.py
@ -421,10 +421,13 @@ def singbox(action: str, domain: str, port: int):
|
|||||||
|
|
||||||
|
|
||||||
@cli.command('normal-sub')
|
@cli.command('normal-sub')
|
||||||
@click.option('--action', '-a', required=True, help='Action to perform: start or stop', type=click.Choice(['start', 'stop'], case_sensitive=False))
|
@click.option('--action', '-a', required=True,
|
||||||
@click.option('--domain', '-d', required=False, help='Domain name for SSL', type=str)
|
type=click.Choice(['start', 'stop', 'edit_subpath'], case_sensitive=False),
|
||||||
@click.option('--port', '-p', required=False, help='Port number for NormalSub service', type=int)
|
help='Action to perform: start, stop, or edit_subpath')
|
||||||
def normalsub(action: str, domain: str, port: int):
|
@click.option('--domain', '-d', required=False, help='Domain name for SSL (for start action)', type=str)
|
||||||
|
@click.option('--port', '-p', required=False, help='Port number for NormalSub service (for start action)', type=int)
|
||||||
|
@click.option('--subpath', '-sp', required=False, help='New subpath (alphanumeric, for edit_subpath action)', type=str)
|
||||||
|
def normalsub(action: str, domain: str, port: int, subpath: str):
|
||||||
try:
|
try:
|
||||||
if action == 'start':
|
if action == 'start':
|
||||||
if not domain or not port:
|
if not domain or not port:
|
||||||
@ -434,6 +437,11 @@ def normalsub(action: str, domain: str, port: int):
|
|||||||
elif action == 'stop':
|
elif action == 'stop':
|
||||||
cli_api.stop_normalsub()
|
cli_api.stop_normalsub()
|
||||||
click.echo(f'NormalSub stopped successfully.')
|
click.echo(f'NormalSub stopped successfully.')
|
||||||
|
elif action == 'edit_subpath':
|
||||||
|
if not subpath:
|
||||||
|
raise click.UsageError('Error: --subpath is required for the edit_subpath action.')
|
||||||
|
cli_api.edit_normalsub_subpath(subpath)
|
||||||
|
click.echo(f'NormalSub subpath updated to {subpath} successfully.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
click.echo(f'{e}', err=True)
|
click.echo(f'{e}', err=True)
|
||||||
|
|
||||||
|
|||||||
@ -510,6 +510,14 @@ def start_normalsub(domain: str, port: int):
|
|||||||
raise InvalidInputError('Error: Both --domain and --port are required for the start action.')
|
raise InvalidInputError('Error: Both --domain and --port are required for the start action.')
|
||||||
run_cmd(['bash', Command.INSTALL_NORMALSUB.value, 'start', domain, str(port)])
|
run_cmd(['bash', Command.INSTALL_NORMALSUB.value, 'start', domain, str(port)])
|
||||||
|
|
||||||
|
def edit_normalsub_subpath(new_subpath: str):
|
||||||
|
'''Edits the subpath for NormalSub service.'''
|
||||||
|
if not new_subpath:
|
||||||
|
raise InvalidInputError('Error: New subpath cannot be empty.')
|
||||||
|
if not new_subpath.isalnum():
|
||||||
|
raise InvalidInputError('Error: New subpath must contain only alphanumeric characters (a-z, A-Z, 0-9).')
|
||||||
|
|
||||||
|
run_cmd(['bash', Command.INSTALL_NORMALSUB.value, 'edit_subpath', new_subpath])
|
||||||
|
|
||||||
def stop_normalsub():
|
def stop_normalsub():
|
||||||
'''Stops NormalSub.'''
|
'''Stops NormalSub.'''
|
||||||
|
|||||||
Reference in New Issue
Block a user