Skip to content
This repository has been archived by the owner on Jan 19, 2018. It is now read-only.

add help when no argument is given #681

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

procrypt
Copy link
Collaborator

@procrypt procrypt commented Apr 7, 2016

fix #668, add check for no arguments passed.

@centos-ci
Copy link
Collaborator

Can one of the admins verify this patch?

3 similar comments
@centos-ci
Copy link
Collaborator

Can one of the admins verify this patch?

@centos-ci
Copy link
Collaborator

Can one of the admins verify this patch?

@centos-ci
Copy link
Collaborator

Can one of the admins verify this patch?

@@ -371,7 +371,8 @@ def create_parser(self):

def run(self):
cmdline = sys.argv[1:] # Grab args from cmdline

if len(cmdline) == 0: # issue 668, add check for no arguments passed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, please remove the issue specific comment and add more generic comment.

@procrypt
Copy link
Collaborator Author

procrypt commented Apr 7, 2016

@surajssd updated.

@cdrage
Copy link
Member

cdrage commented Apr 7, 2016

Works for me 👍 Good work!

LGTM

dropbox/dev/atomicapp  pr_681 ✔                                                                                                                                                                                                                         5h7m  
▶ atomicapp
usage: atomicapp {run,fetch,stop,genanswers} ...

This will fetch and run an Atomic App, a containerized application conforming to the Nulecule Specification

positional arguments:
  {run,fetch,stop,genanswers}

optional arguments:
  -V, --version         Show the version and exit.
  -v, --verbose         Verbose output mode.
  -q, --quiet           Quiet output mode.
  --mode {fetch,run,stop,genanswers}
                        The mode Atomic App is run in. This option has the
                        effect of switching the 'verb' that was passed by the
                        user as the first positional argument. This is useful
                        in cases where a user is not using the Atomic App cli
                        directly, but through another interface such as the
                        Atomic CLI. EX: `atomic run <IMAGE> --mode=genanswers`
  --dry-run             Don't actually call provider. The commands that should
                        be run will be logged but not run.
  --answers-format {ini,json,xml,yaml}
                        The format for the answers.conf.sample file. Default:
                        ini
  --namespace NAMESPACE
                        The namespace to use in the target provider
  --providertlsverify {True,False}
                        Value for providertlsverify answers option.
                        --providertlsverify=False to disable tls verification
  --providerconfig PROVIDERCONFIG
                        Value for providerconfig answers option.
  --providercafile PROVIDERCAFILE
                        Value for providercafile answers option.
  --providerapi PROVIDERAPI
                        Value for providerapi answers option.
  --logtype {cockpit,color,nocolor,none}
                        Override the default logging output. The options are:
                        nocolor: we will only log to stdout; color: log to
                        stdout with color; cockpit: used with cockpit
                        integration; none: atomicapp will disable any logging.
                        If nothing is set and logging to file then 'nocolor'
                        by default. If nothing is set and logging to tty then
                        'color' by default.

dropbox/dev/atomicapp  pr_681 ✔ 

@dustymabe
Copy link
Contributor

hi @abhi1004. this works for me too. do you mind doing a couple of things before we merge:

  • squash your commits down into 1, you currently have 3
  • rebase onto latest master

If you need help with either of those ask us in #nulecule and we can help.

@procrypt procrypt force-pushed the help_completion branch 5 times, most recently from e6dbad9 to adba4cf Compare April 9, 2016 19:53
@surajssd
Copy link
Collaborator

@dustymabe how about showing help on following also?

(atomic) [vagrant@centos7-adb ~]$ atomicapp run
[INFO] - main.py - Action/Mode Selected is: run
Error. Too few arguments. Must provide app_spec.
Run with '--help' for more info
(atomic) [vagrant@centos7-adb ~]$ atomicapp fetch
[INFO] - main.py - Action/Mode Selected is: fetch
Error. Too few arguments. Must provide app_spec.
Run with '--help' for more info
(atomic) [vagrant@centos7-adb ~]$ atomicapp stop
usage: atomicapp stop [-h] [-V] [-v] [-q] [--mode {fetch,run,stop,genanswers}]
                      [--dry-run] [--answers-format {ini,json,xml,yaml}]
                      [--namespace NAMESPACE]
                      [--providertlsverify {True,False}]
                      [--providerconfig PROVIDERCONFIG]
                      [--providercafile PROVIDERCAFILE]
                      [--providerapi PROVIDERAPI]
                      [--logtype {cockpit,color,nocolor,none}]
                      [--provider {docker,kubernetes,openshift,marathon}]
                      app_spec
atomicapp stop: error: too few arguments
(atomic) [vagrant@centos7-adb ~]$ atomicapp genanswers
[INFO] - main.py - Action/Mode Selected is: genanswers
Error. Too few arguments. Must provide app_spec.
Run with '--help' for more info

@Amitgb14
Copy link

@abhi1004 @surajssd , I paste diff here and tested these changes, please make sure that is correct?

--- a/atomicapp/cli/main.py
+++ b/atomicapp/cli/main.py
@@ -337,6 +337,7 @@ class CLI():
             help="The provider to use. Overrides provider value in answerfile.")
         stop_subparser.add_argument(
             "app_spec",
+            nargs='?',
             help=('''
                 Path to the directory where the Atomic App is fetched
                 that is to be stopped.'''))
@@ -395,6 +396,9 @@ class CLI():
         # of the line.
         # NOTE: Also allow "mode" to override 'action' if specified
         args, _ = self.parser.parse_known_args(cmdline)
+
+        if not args.app_spec and not os.environ.get('IMAGE'):
+            args = self.parser.parse_args([args.action, '-h'])
         cmdline.remove(args.action)     # Remove 'action' from the cmdline
         if args.mode:
             args.action = args.mode     # Allow mode to override 'action'
@@ -408,8 +412,8 @@ class CLI():
         # a directory if they want to for "run". For that reason we won't
         # default the RUN label for Atomic App to provide an app_spec argument.
         # In this case pick up app_spec from $IMAGE env var (set by RUN label).
-        if args.app_spec is None:
-            if os.environ.get('IMAGE') is not None:
+        if not args.app_spec:
+            if os.environ.get('IMAGE'):
                 logger.debug("Setting app_spec based on $IMAGE env var")
                 args.app_spec = os.environ['IMAGE']
             else:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

typing only atomicapp should display help
6 participants