Skip to content

Commit

Permalink
enhance scripts/activate-global-python-argcomplete (#461)
Browse files Browse the repository at this point in the history
* automatically answer yes for all questions

* avoid repeatedly appending to configuration files
  • Loading branch information
zoumingzhe authored Dec 2, 2023
1 parent cb5fc38 commit efaeb21
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scripts/activate-global-python-argcomplete
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ def install_to_destination(dest):


def get_consent():
try:
if args.yes is True:
return True
except NameError:
pass
while True:
res = input("OK to proceed? [y/n] ")
if res.lower() not in {"y", "n", "yes", "no"}:
Expand All @@ -93,6 +98,10 @@ def get_consent():

def append_to_config_file(path, shellcode):
if os.path.exists(path):
with open(path, 'r') as fh:
if shellcode in fh.read():
print(f"The code already exists in the file {path}.", file=sys.stderr)
return
print(f"argcomplete needs to append to the file {path}. The following code will be appended:", file=sys.stderr)
for line in shellcode.splitlines():
print(">", line, file=sys.stderr)
Expand All @@ -115,6 +124,7 @@ def link_user_rcfiles():


parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("-y", "--yes", help="automatically answer yes for all questions", action="store_true")
parser.add_argument("--dest", help='Specify the shell completion modules directory to install into, or "-" for stdout')
parser.add_argument("--user", help="Install into user directory", action="store_true")
argcomplete.autocomplete(parser)
Expand Down

0 comments on commit efaeb21

Please sign in to comment.