summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug@doughellmann.com>2018-01-17 09:22:29 -0500
committerDean Troyer <dtroyer@gmail.com>2018-01-18 14:53:52 +0000
commit134ebd4a9a5d981f3bccf4f074adc63f1df72f80 (patch)
tree42abe7470c21333bd3830efc952f309db96c1067
parenta114aabbf4c38836ae2694376aa0b097ed1e8c28 (diff)
downloadcliff-134ebd4a9a5d981f3bccf4f074adc63f1df72f80.tar.gz
remove -s alias for --sort-columns2.11.0
Cliff normally uses short option name aliases which are global in to the CLI. We want commands to not use them due to the limited number and ease of collision. However this one was already in use by a well-known plugin so we will not take it. Change-Id: Id348dad450b52716b82d7852d6378ecc48808f26 Closes-Bug: #1743578 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
-rw-r--r--cliff/lister.py2
-rw-r--r--cliff/tests/test_command.py20
2 files changed, 21 insertions, 1 deletions
diff --git a/cliff/lister.py b/cliff/lister.py
index 93a6b86..e0fab01 100644
--- a/cliff/lister.py
+++ b/cliff/lister.py
@@ -50,7 +50,7 @@ class Lister(display.DisplayCommandBase):
parser = super(Lister, self).get_parser(prog_name)
group = self._formatter_group
group.add_argument(
- '-s', '--sort-column',
+ '--sort-column',
action='append',
default=[],
dest='sort_columns',
diff --git a/cliff/tests/test_command.py b/cliff/tests/test_command.py
index 8e1a0f3..6aecff3 100644
--- a/cliff/tests/test_command.py
+++ b/cliff/tests/test_command.py
@@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import argparse
import functools
from cliff import command
@@ -42,6 +43,10 @@ class TestCommand(command.Command):
help="The quick brown fox jumps "
"over the lazy dog.",
)
+ parser.add_argument(
+ '-z',
+ help='used in TestArgumentParser',
+ )
return parser
def take_action(self, parsed_args):
@@ -128,3 +133,18 @@ class TestHelp(base.TestBase):
width=78,
)
self.assertIn(expected_help_message, parser.format_help())
+
+
+class TestArgumentParser(base.TestBase):
+
+ def test_option_name_collision(self):
+ cmd = TestCommand(None, None)
+ parser = cmd.get_parser('NAME')
+ # We should have an exception registering an option with a
+ # name that already exists because we do not want commands to
+ # override global options.
+ self.assertRaises(
+ argparse.ArgumentError,
+ parser.add_argument,
+ '-z',
+ )