Skip to content

Commit

Permalink
added --default flag to ck install package to select 0 when multiple …
Browse files Browse the repository at this point in the history
…packages and variations available.
  • Loading branch information
gfursin committed Apr 18, 2021
1 parent 341b714 commit 658ab2b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* V1.55.7
* added --default flag to ck install package to select 0
when multiple packages and variations available.

* V1.55.6
* extended module:package to ask a user to select a variation
for a given package when there are multiple versions available.
Expand Down
2 changes: 1 addition & 1 deletion ck/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


# We use 3 digits for the main (released) version and 4th digit for development revision
__version__ = "1.55.6"
__version__ = "1.55.7"
# Do not use characters (to detect outdated version)!

# Import packages that are global for the whole kernel
Expand Down
30 changes: 19 additions & 11 deletions ck/repo/module/misc/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,14 @@ def prepare_entry_template(i):
def select_string(i):
"""
Input: {
options - an ordered list of strings to select from
(question) - the question to ask
(default) - default selection
(no_autoselect) - if "yes", enforce the interactive choice even if there is only 1 option
(no_autoretry) - if "yes", bail out on any unsuitable input, do not offer to retry
(no_skip_line) - if "yes", do not skip a line after each option
(first_match) - if "yes", take the first match in case there are multiple
options - an ordered list of strings to select from
(question) - the question to ask
(default) - default selection
(no_autoselect) - if "yes", enforce the interactive choice even if there is only 1 option
(no_autoretry) - if "yes", bail out on any unsuitable input, do not offer to retry
(no_skip_line) - if "yes", do not skip a line after each option
(first_match) - if "yes", take the first match in case there are multiple
(select_default) - if "yes", select 0
}
Output: {
Expand All @@ -533,6 +534,8 @@ def select_string(i):

import copy

select_default=i.get('select_default','').strip().lower()

question = i.get('question', 'Please select from the options above')
options = copy.deepcopy( i.get('options') )
default = i.get('default', None)
Expand Down Expand Up @@ -567,11 +570,16 @@ def select_string(i):

while num_matches!=1:

r = ck.inp({'text': "{}{}: ".format(question, ' [ hit return for "{}" ]'.format(default) if default!=None and len(default) else '')})
response = r['string']
if select_default != 'yes':
r = ck.inp({'text': "{}{}: ".format(question, ' [ hit return for "{}" ]'.format(default) if default!=None and len(default) else '')})
response = r['string']

if response=='' and default!=None:
response = default
else:
ck.out('Selected 0 (default)')

if response=='' and default!=None:
response = default
response = '0'

try: # try to convert into int() and see if it works
error_message = None
Expand Down
32 changes: 21 additions & 11 deletions ck/repo/module/package/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def install(i):
(ask_version) - ask for the version of the package the user wants to install
(debug) - if 'yes', open shell before installing but with all resolved deps
(default) - if 'yes', install default package (answer 0 to selection questions)
}
Output: {
Expand All @@ -141,6 +143,8 @@ def install(i):

ask=i.get('ask','')

default=i.get('default','').strip().lower()

xtags=i.get('tags','')
xor_tags=i.get('or_tags','')
xno_tags=i.get('no_tags','')
Expand Down Expand Up @@ -362,11 +366,12 @@ def install(i):
ver_options.append( skip_display_line )

select_adict = ck.access({'action': 'select_string',
'module_uoa': 'misc',
'options': ver_options,
'default': '0',
'no_skip_line': 'yes',
'question': 'Please select the package to install',
'module_uoa': 'misc',
'options': ver_options,
'default': '0',
'select_default': default,
'no_skip_line': 'yes',
'question': 'Please select the package to install',
})
if select_adict['return']>0: return select_adict

Expand Down Expand Up @@ -495,14 +500,19 @@ def install(i):
j+=1

ck.out('')
x=input('Please select a variation or press Enter for the default one (0): ')

x=x.strip()
if x=='': x='0'
if default!='yes':
x=input('Please select a variation or press Enter for the default one (0): ')

ix=int(x)
if ix<0 or ix>=j:
return {'return':1, 'error':'variation number is not recognized'}
x=x.strip()
if x=='': x='0'

ix=int(x)
if ix<0 or ix>=j:
return {'return':1, 'error':'variation number is not recognized'}
else:
ck.out('Selected 0 (default)')
ix=0

required_variations=[key_variation[ix]]

Expand Down

0 comments on commit 658ab2b

Please sign in to comment.