Skip to content

Commit

Permalink
main: support --bash-completion
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Gatto <matthias.gatto@outscale.com>
  • Loading branch information
outscale-mgo authored and jerome-jutteau committed Aug 16, 2022
1 parent 8e2e5a7 commit 7da12d2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include osc_sdk/osc-cli-completion.bash
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ pypi-upload: .venv/ok
pkg/osc-cli-completion.bash:
make -C pkg/ osc-cli-completion.bash

osc-cli-completion.bash: pkg/osc-cli-completion.bash
cp pkg/osc-cli-completion.bash .
osc_sdk/osc-cli-completion.bash: pkg/osc-cli-completion.bash
cp pkg/osc-cli-completion.bash osc_sdk/

.venv/ok:
@./tests/setup_venv.sh
Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions osc_sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import hmac
import json
import logging
import os
import re
import sys
import urllib.parse
from dataclasses import InitVar, dataclass, field
from pathlib import Path
Expand Down Expand Up @@ -71,6 +73,9 @@
},
}

dir_path = os.path.join(os.path.dirname(__file__))
BASH_COMPLETION_PATH = os.path.abspath("{}/osc-cli-completion.bash".format(dir_path))


class Configuration(TypedDict):
method: str
Expand Down Expand Up @@ -741,8 +746,10 @@ def api_connect(
login: Optional[str] = None,
password: Optional[str] = None,
authentication_method: Optional[str] = None,
bash_completion: bool = False,
**kwargs: CallParameters,
):

calls = {
"api": OSCCall,
"directlink": DirectLinkCall,
Expand All @@ -762,6 +769,18 @@ def api_connect(


def main():
argc = len(sys.argv)
argv = sys.argv

if argc > 1:
for i in range(1, argc):
a = argv[i]
if a == "--bash_completion":
f = open(BASH_COMPLETION_PATH, "r")
print(f.read())
sys.exit()
return 0

logging.basicConfig(level=logging.ERROR)
fire.Fire(api_connect)

Expand Down

0 comments on commit 7da12d2

Please sign in to comment.