Skip to content

Feature/gh73 implement bash completion#74

Open
TB-1993 wants to merge 1 commit into
developfrom
feature/gh73_implement_bash_completion
Open

Feature/gh73 implement bash completion#74
TB-1993 wants to merge 1 commit into
developfrom
feature/gh73_implement_bash_completion

Conversation

@TB-1993

@TB-1993 TB-1993 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

closes #73

  • Implemented tab completion for bash shells.
  • Added installation of the bash completion to the xts-install command

- Implemented tab completion (bash only) for the xts CLI
- Added tab completion to the install command
Copilot AI review requested due to automatic review settings June 25, 2026 12:51
@TB-1993 TB-1993 requested a review from a team as a code owner June 25, 2026 12:51
@github-actions

Copy link
Copy Markdown


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


1 out of 2 committers have signed the CLA.
TB-1993
zghp
zghp seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@TB-1993 TB-1993 requested a review from zghp June 25, 2026 12:51
@TB-1993 TB-1993 changed the base branch from master to develop June 25, 2026 12:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds bash tab-completion support to the xts CLI and updates installation to deploy the completion script automatically for bash users, alongside some CLI parsing/help-formatting changes to better surface aliases and subcommands.

Changes:

  • Added bash completion plumbing (_XTS_COMPLETE) and completion installation via xts-install.
  • Introduced a custom Rich help formatter to render aliases and subcommands in separate help sections.
  • Updated argparse wiring (including alias management parsing) and packaging metadata to ship the completion script.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
src/xts_core/xts.py Adds completion entrypoint logic and refactors top-level parsing to model aliases/subcommands.
src/xts_core/xts_rich_help_formatter.py New formatter to split help output into “Subcommands” vs “Aliases”.
src/xts_core/xts_arg_parser.py Allows passing a formatter class and uses raise SystemExit in error().
src/xts_core/xts_alias.py Refactors alias CLI parsing into a subcommand-style parser setup.
src/xts_core/plugins/xts_allocator_client.py Replaces sys.exit(1) with raise SystemExit(1) for consistency.
src/xts_core/install.py Installs bash completion script and appends PATH/source lines to bash rc files.
src/xts_core/data/xts_bash_completion.sh New bash completion script that invokes xts in completion mode.
pyproject.toml Updates dependencies and config to include shipped completion script.
.github/instructions/*.md, .github/copilot-instructions.md Adds repository contribution/instruction documents (non-runtime).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/xts_core/xts.py
Comment on lines 210 to +214
except Exception as e:
error(
'An unrecognised command caused an error\n\n'
f'Command Args: [{" ".join(args)}]\n\n'
f'{str(e)}'
)
error(
'An unrecognised command caused an error\n\n'
f'Command Args: [{" ".join(arguments)}]\n\n'
f'{str(e)}')
Comment thread src/xts_core/xts.py
Comment on lines +217 to +229
os.environ['_ARGPARSE_COMPLETE'] = os.getenv('_XTS_COMPLETE')
completion = argparse_completion.get_completion(arg_parser)
if 'alias_name' in completion:
completion.remove('alias_name')
if len(completion) == 0 and (comp_words:=(os.getenv('COMP_WORDS').split()))[1] in xts_alias.load_aliases().keys():
os.environ['_YAML_RUNNER_COMPLETE'] = os.getenv('_XTS_COMPLETE')
alias = comp_words[1]
comp_words.remove('xts')
comp_words.remove(alias)
os.environ['COMP_WORDS'] = " ".join(comp_words)
self._run_yaml_runner(alias, comp_words)
else:
print('\n'.join(completion))
Comment thread src/xts_core/xts.py
case 'alias':
alias_name_subparser = list(filter(lambda x: x.dest == 'alias_name',parser._actions))[0]
alias_subparser = alias_name_subparser.choices.get('alias')
xts_alias.run_alias_builtin(alias_subparser)
Comment thread src/xts_core/xts.py
Comment on lines 169 to 176
@@ -174,63 +176,85 @@ def _parse_first_arg(self):
list[str]: Remaining args starting with the command name, e.g. ["run", ...].
Comment on lines +33 to +34
choice_action = list(filter(lambda x: parser.prog == f'xts {x.dest}', action._choices_actions))[0]
choice_tuple = (choice, choice_action)
Comment thread src/xts_core/install.py
Comment on lines +95 to +109
def _install_bash(user_home: Path):
if (bashrc:=user_home.joinpath(Path('.bashrc'))).exists():
with open(user_home.joinpath(Path('.bashrc')), 'a') as f:
f.write('\n# XTS PATH\n')
f.write(f'export PATH="{user_home.joinpath(Path(".xts/bin"))}:$PATH"\n')
_install_bash_completion(bashrc)
elif (bash_profile:=user_home.joinpath(Path('.bash_profile'))).exists():
with open(user_home.joinpath(Path('.bash_profile')), 'a') as f:
f.write('\n# XTS PATH\n')
f.write(f'export PATH="{user_home.joinpath(Path(".xts/bin"))}:$PATH"\n')
_install_bash_completion(bash_profile)
else:
warning('Could not find .bashrc or .bash_profile to add xts to PATH. Please add the following line to your shell config file:\n' +
f'export PATH="{user_home.joinpath(Path(".xts/bin"))}:$PATH"\n')

Comment thread src/xts_core/install.py
Comment on lines +119 to +121
with open(rc_file, 'a') as f:
f.write('\n# XTS bash completion\n')
f.write(f'source {bash_completion_dir}/xts_bash_completion.sh\n')
Comment thread pyproject.toml
Comment on lines +31 to +34
# This ensures data/ is included in sdist/wheel
[tool.setuptools.data-files]
# Installs data into a shared location in site-packages
"xts_core_data" = ["data/**/*"]
Comment thread src/xts_core/xts.py


def _parse_first_arg(self):
def _setup_first_parser(self):
Comment thread src/xts_core/xts.py
Comment on lines +190 to +192
alias_parser = first_arg_subparsers.add_parser('alias',
help='Manage aliases (add, list, remove)')
xts_alias.setup_alias_parser(alias_parser)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add tab completion

2 participants