labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1606397 - in /labs/panopticon/pan-commands: bin/ src/asf/ src/asf/cli/ src/asf/cli/resources/ src/asf/cli/resources/moderator/
Date Sat, 28 Jun 2014 21:42:59 GMT
Author: adc
Date: Sat Jun 28 21:42:59 2014
New Revision: 1606397

URL: http://svn.apache.org/r1606397
Log:
Commands can provide completion scripts

Added:
    labs/panopticon/pan-commands/src/asf/cli/
    labs/panopticon/pan-commands/src/asf/cli/__init__.py
      - copied, changed from r1605091, labs/panopticon/pan-commands/src/asf/cli.py
    labs/panopticon/pan-commands/src/asf/cli/resources/
    labs/panopticon/pan-commands/src/asf/cli/resources/__init__.py
    labs/panopticon/pan-commands/src/asf/cli/resources/moderator/
    labs/panopticon/pan-commands/src/asf/cli/resources/moderator/__init__.py
    labs/panopticon/pan-commands/src/asf/cli/resources/moderator/bash.completion
    labs/panopticon/pan-commands/src/asf/cli/resources/moderator/zsh.completion
Removed:
    labs/panopticon/pan-commands/src/asf/cli.py
Modified:
    labs/panopticon/pan-commands/bin/moderator

Modified: labs/panopticon/pan-commands/bin/moderator
URL: http://svn.apache.org/viewvc/labs/panopticon/pan-commands/bin/moderator?rev=1606397&r1=1606396&r2=1606397&view=diff
==============================================================================
--- labs/panopticon/pan-commands/bin/moderator (original)
+++ labs/panopticon/pan-commands/bin/moderator Sat Jun 28 21:42:59 2014
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+# !/usr/bin/env python
 #
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
@@ -20,6 +20,9 @@
 """
 Mailing list moderator tool used to manage mailing lists from the command line.
 """
+import argparse
+import sys
+
 from asf.cli import entrypoint
 from asf.data.aliases import get_mail_aliases
 from asf.utils.committers import get_committer

Copied: labs/panopticon/pan-commands/src/asf/cli/__init__.py (from r1605091, labs/panopticon/pan-commands/src/asf/cli.py)
URL: http://svn.apache.org/viewvc/labs/panopticon/pan-commands/src/asf/cli/__init__.py?p2=labs/panopticon/pan-commands/src/asf/cli/__init__.py&p1=labs/panopticon/pan-commands/src/asf/cli.py&r1=1605091&r2=1606397&rev=1606397&view=diff
==============================================================================
--- labs/panopticon/pan-commands/src/asf/cli.py (original)
+++ labs/panopticon/pan-commands/src/asf/cli/__init__.py Sat Jun 28 21:42:59 2014
@@ -25,6 +25,7 @@ import os
 import sys
 
 import argparse
+import pkg_resources
 
 from asf.utils.auth import get_username, get_password, AUTH_SECTION, save_password, AUTH_SECTIONS,
remove_password
 from asf.utils.config import load_config
@@ -64,6 +65,21 @@ def entrypoint(method, depth=1, cls=None
     return method
 
 
+SUPPORTED_COMPLETION_SHELLS = ['bash', 'zsh']
+
+
+class _CompletionAction(argparse.Action):
+    def __init__(self, option_strings, dest=argparse.SUPPRESS, default=argparse.SUPPRESS,
help=None, choices=None):
+        choices = choices or SUPPORTED_COMPLETION_SHELLS
+        super(_CompletionAction, self).__init__(
+            option_strings, dest, default=default, nargs=1, help=help, type=str, choices=choices,
metavar='SHELL'
+        )
+
+    def __call__(self, parser, namespace, values, option_string=None):
+        print pkg_resources.resource_string('asf.cli.resources.%s' % parser.name, '%s.completion'
% values[0])
+        parser.exit()
+
+
 class CLI(object):
     """
         Initialize a command line helper instance.
@@ -124,6 +140,22 @@ class CLI(object):
 
         #: :mod:`argparse` replaces optparse in Python 2.7, it is installable as a stand-alone
module.
         self.argparser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter)
+        self.argparser.name = name
+
+        # add --completion option if completion scripts are available
+        try:
+            pkg_resources.resource_listdir('asf.cli.resources.%s' % name, '')
+            help_string = None
+            for shell in SUPPORTED_COMPLETION_SHELLS:
+                if pkg_resources.resource_exists('asf.cli.resources.%s' % name, '%s.completion'
% shell):
+                    if help_string:
+                        help_string += ', ' + shell
+                    else:
+                        help_string = 'Print out shell completion script: ' + shell
+            self.argparser.register('action', 'completion', _CompletionAction)
+            self.argparser.add_argument('--completion', action='completion', help=help_string)
+        except ImportError:
+            pass
 
         self.argparser.add_argument(
             '--debug', action='store_true', default=False, help='Turn on debug mode / logging.'

Added: labs/panopticon/pan-commands/src/asf/cli/resources/__init__.py
URL: http://svn.apache.org/viewvc/labs/panopticon/pan-commands/src/asf/cli/resources/__init__.py?rev=1606397&view=auto
==============================================================================
--- labs/panopticon/pan-commands/src/asf/cli/resources/__init__.py (added)
+++ labs/panopticon/pan-commands/src/asf/cli/resources/__init__.py Sat Jun 28 21:42:59 2014
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#

Added: labs/panopticon/pan-commands/src/asf/cli/resources/moderator/__init__.py
URL: http://svn.apache.org/viewvc/labs/panopticon/pan-commands/src/asf/cli/resources/moderator/__init__.py?rev=1606397&view=auto
==============================================================================
--- labs/panopticon/pan-commands/src/asf/cli/resources/moderator/__init__.py (added)
+++ labs/panopticon/pan-commands/src/asf/cli/resources/moderator/__init__.py Sat Jun 28 21:42:59
2014
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#

Added: labs/panopticon/pan-commands/src/asf/cli/resources/moderator/bash.completion
URL: http://svn.apache.org/viewvc/labs/panopticon/pan-commands/src/asf/cli/resources/moderator/bash.completion?rev=1606397&view=auto
==============================================================================
--- labs/panopticon/pan-commands/src/asf/cli/resources/moderator/bash.completion (added)
+++ labs/panopticon/pan-commands/src/asf/cli/resources/moderator/bash.completion Sat Jun 28
21:42:59 2014
@@ -0,0 +1,42 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+__moderator_completion() {
+    local cur prev opts
+    local lists="$(moderator list)"
+    COMPREPLY=()
+    cur="${COMP_WORDS[COMP_CWORD]}"
+    prev="${COMP_WORDS[COMP_CWORD-1]}"
+    opts="list add lookup remove"
+
+    case "${prev}" in
+        list)
+            COMPREPLY=( $(compgen -W "${lists}" -- ${cur}) );;
+        add)
+            COMPREPLY=( $(compgen -W "${lists}" -- ${cur}) );;
+        remove)
+            COMPREPLY=( $(compgen -W "${lists}" -- ${cur}) );;
+        moderator)
+            COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) );;
+    esac
+
+    return 0
+}
+
+complete -F __moderator_completion moderator

Added: labs/panopticon/pan-commands/src/asf/cli/resources/moderator/zsh.completion
URL: http://svn.apache.org/viewvc/labs/panopticon/pan-commands/src/asf/cli/resources/moderator/zsh.completion?rev=1606397&view=auto
==============================================================================
--- labs/panopticon/pan-commands/src/asf/cli/resources/moderator/zsh.completion (added)
+++ labs/panopticon/pan-commands/src/asf/cli/resources/moderator/zsh.completion Sat Jun 28
21:42:59 2014
@@ -0,0 +1,19 @@
+#compdef moderator
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message