Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
silkaj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
silkaj
Commits
feba342d
Commit
feba342d
authored
5 years ago
by
Moul
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#235
: Add CLI mutually exclusive option class
-
https://gist.github.com/jacobtolar/fb80d5552a9a9dfc32b12a829fa21c0c
parent
0e7b5429
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
silkaj/cli_tools.py
+40
-0
40 additions, 0 deletions
silkaj/cli_tools.py
with
40 additions
and
0 deletions
silkaj/cli_tools.py
0 → 100644
+
40
−
0
View file @
feba342d
"""
Copyright 2016-2019 Maël Azimi <m.a@moul.re>
Silkaj is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Silkaj is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
"""
from
click
import
Option
,
UsageError
class
MutuallyExclusiveOption
(
Option
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
mutually_exclusive
=
set
(
kwargs
.
pop
(
"
mutually_exclusive
"
,
[]))
help
=
kwargs
.
get
(
"
help
"
,
""
)
if
self
.
mutually_exclusive
:
ex_str
=
"
,
"
.
join
(
self
.
mutually_exclusive
)
kwargs
[
"
help
"
]
=
help
+
(
"
NOTE: This argument is mutually exclusive with
"
"
arguments: [
"
+
ex_str
+
"
].
"
)
super
(
MutuallyExclusiveOption
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
handle_parse_result
(
self
,
ctx
,
opts
,
args
):
if
self
.
mutually_exclusive
.
intersection
(
opts
)
and
self
.
name
in
opts
:
raise
UsageError
(
"
Usage: `{}` is mutually exclusive with
"
"
arguments `{}`.
"
.
format
(
self
.
name
,
"
,
"
.
join
(
self
.
mutually_exclusive
))
)
return
super
(
MutuallyExclusiveOption
,
self
).
handle_parse_result
(
ctx
,
opts
,
args
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment