-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use subcommands for lock,release,check #21
base: master
Are you sure you want to change the base?
Conversation
Part of red-hat-storage#19 made use of [argparse.subparser](https://docs.python.org/3/library/argparse.html#sub-commands) to implement subcommands. ie: `rlock lock [args]` instead of `rlock --lock --arg1 --arg2` Arguments that are required by certain things (signoff, search string, etc) are now positional args This makes it easy to determine if they've been specified and error out if not. Eliminating common user issues. Server args `--server-url` form, but that should change if we start using a config file or something. Added defaults for `--interval` and `--attempts` based on the ones in `ResourceLocker` class Added short form for most common params (`-s`, `-t`, etc)
@LNST-project Please review as well if you can. |
Could you add some additional description of what SIGN_OFF actually means? Is it an arbitrary string that is used in release after locking a resource? The current description that it is required is obvious, since it's mandatory parameter. |
Yeah i kinda just copied what was there before. I tryed to come up with one but they where all too long. @jimdevops19 Do you have a short phrase to describe what the signoff is. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just providing some comments from a quick look...
"--resume-on-connection-error", help="Use this argument in case you don't want to break queue execution" | ||
" in the middle of waiting for queue status being FINISHED", action="store_true" | ||
|
||
# Parent of all sub commands that take a signoff string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment is doubled and both times in the incorrect place, i think you wanted to say that the parser
is the parent of all subcommands, but the comment is located at the search_parser
and at the signoff_parser
instead.
|
||
Returns: | ||
object: Parsed arguments - returned from parser.parse_args() | ||
""" | ||
server_args_parser = ArgumentParser(add_help=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think these arguments since they're shared by all of the sub-commands and relate to the generic configuration of the server, they should just be added to the parser
instead of sharing them via parents
to all the individual sub-parsers.
I think that results in the difference of:
./my_cli --server-opt ACTION --action-opt
vs.
./my_cli ACTION --server-opt --action-opt
but i'm not sure... i haven't really used this pattern before. Based on the linked stackoverflow questions I think the parents
way of sharing options is meant for sub-commands where some share the options and some don't, these options however look like they're always optional for all sub-commands...
though i guess that's personal preference...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I went back and forth a few times on this, I think i ran into an issue adding them to parser
and decided to switch back to the way it is now. It might be possible I just didn't have a chance to fully debug it and wanted to get something out.
I my opinion though things like --server
and --token
really should be coming from some sort of config file so you dont have to type them everytime. We still want them to be options but I think it gets kinda unwieldy having them be part of the command line all the time.
parser.add_argument( | ||
# TODO These really should be config file things, | ||
server_args_parser.add_argument( | ||
"-s", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit concerned about having one letter shortcut for possibly two reasons (maybe su could be a better option):
1 ) Maybe we might want to save the -s
for shortening the signoff
which is already a mandatory argument
2 ) Maybe some other arguments in the future that will be single-worded and start with an s
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would -u
for url be better?
Also I think it might be okay to not shorten it, but i do think we should add support for some sort of config file so you dont need to enter it (and the token, etc) all the time. then we could just have it be --server
I was curious does your team commonly deal with multiple resource locker instances in production?
Part of #19
made use of argparse.subparser to implement subcommands. Also various related changed detailed below.
So locking a resource
aws-resource-1
with signoffptest1
and priortity3
now looks like this :my hope is in the future we can get rid of requiring
-s
and-t
with some sort of config file.Details
Arguments that are required by certain things (signoff, search string, etc) are now positional args
This makes it easy to determine if they've been specified and error out if not. Eliminating common
user issues. Server args
--server-url
form, but that should change if we start using a config file or something.Added defaults for
--interval
and--attempts
based on the ones inResourceLocker
classAdded short form for most common params (
-s
,-t
, etc)Here is what
--help
looks like:@jimdevops19 let me know what you think