Skip to content

Commit

Permalink
bump version, merge pull request #43 from iterative/preamble
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Jul 20, 2021
2 parents b3f8d79 + 2a2dadd commit 4731037
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test
on: [push, pull_request]
jobs:
check:
if: github.event_name != 'pull_request' || github.head_ref != 'devel'
if: startsWith(github.ref, 'refs/tags') || github.event_name == 'pull_request' || github.repository_owner != 'iterative'
name: Check
runs-on: ubuntu-latest
steps:
Expand All @@ -24,7 +24,7 @@ jobs:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: pre-commit run -a --show-diff-on-failure
test:
if: github.event_name != 'pull_request' || github.head_ref != 'devel'
if: startsWith(github.ref, 'refs/tags') || github.event_name == 'pull_request' || github.repository_owner != 'iterative'
name: Test py${{ matrix.python }}
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -55,15 +55,19 @@ jobs:
requirements: twine setuptools wheel setuptools_scm[toml]
build: true
password: ${{ secrets.PYPI_TOKEN }}
upload: ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') }}
upload: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
- name: Changelog
run: git log --pretty='format:%d%n- %s%n%b---' $(git tag --sort=v:refname | tail -n2 | head -n1)..HEAD > _CHANGES.md
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
- id: meta
name: Metadata
run: |
echo "::set-output name=tag::${GITHUB_REF#refs/tags/}"
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
name: shtab ${{ github.ref }} beta
name: shtab ${{ steps.meta.outputs.tag }} beta
body_path: _CHANGES.md
draft: true
files: |
Expand Down
4 changes: 3 additions & 1 deletion examples/customcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def get_main_parser():
subparsers.dest = "subcommand"

parser = subparsers.add_parser("completion")
shtab.add_argument_to(parser, "shell", parent=main_parser) # magic!
shtab.add_argument_to(
parser, "shell", parent=main_parser, preamble=PREAMBLE
) # magic!

parser = subparsers.add_parser("process")
# `*.txt` file tab completion
Expand Down
7 changes: 4 additions & 3 deletions shtab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,10 @@ def complete(
)


def completion_action(parent=None):
def completion_action(parent=None, preamble=""):
class PrintCompletionAction(Action):
def __call__(self, parser, namespace, values, option_string=None):
print(complete(parent or parser, values))
print(complete(parent or parser, values, preamble=preamble))
parser.exit(0)

return PrintCompletionAction
Expand All @@ -589,6 +589,7 @@ def add_argument_to(
option_string="--print-completion",
help="print shell completion script",
parent=None,
preamble="",
):
"""
parser : argparse.ArgumentParser
Expand All @@ -605,7 +606,7 @@ def add_argument_to(
"choices": SUPPORTED_SHELLS,
"default": None,
"help": help,
"action": completion_action(parent),
"action": completion_action(parent, preamble),
}
if option_string[0][0] != "-": # subparser mode
kwargs.update(default=SUPPORTED_SHELLS[0], nargs="?")
Expand Down

0 comments on commit 4731037

Please sign in to comment.