Ejemplo n.º 1
0
def main():
    import sys
    from Naked.commandline import Command

    #------------------------------------------------------------------------------------------
    # [ Instantiate command line object ]
    #   used for all subsequent conditional logic in the CLI application
    #------------------------------------------------------------------------------------------
    c = Command(sys.argv[0], sys.argv[1:])
    #------------------------------------------------------------------------------------------
    # [ Command Suite Validation ] - early validation of appropriate command syntax
    # Test that user entered at least one argument to the executable, print usage if not
    #------------------------------------------------------------------------------------------
    if not c.app_validates_args():
        from helpy.settings import usage as helpy_usage
        print(helpy_usage)
        sys.exit(1)
    #------------------------------------------------------------------------------------------
    # [ NAKED FRAMEWORK COMMANDS ]
    # Naked framework provides default help, usage, and version commands for all applications
    #   --> settings for user messages are assigned in the lib/pyh/settings.py file
    #------------------------------------------------------------------------------------------
    if c.help():  # User requested pyh help information
        from helpy.settings import help as helpy_help
        print(helpy_help)
        sys.exit(0)
    elif c.usage():  # User requested pyh usage information
        from helpy.settings import usage as helpy_usage
        print(helpy_usage)
        sys.exit(0)
    elif c.version():  # User requested pyh version information
        from helpy.settings import app_name, major_version, minor_version, patch_version
        version_display_string = app_name + ' ' + major_version + '.' + minor_version + '.' + patch_version
        print(version_display_string)
        sys.exit(0)
    #------------------------------------------------------------------------------------------
    # [ PRIMARY COMMAND LOGIC ]
    #   Enter your command line parsing logic below
    #------------------------------------------------------------------------------------------

    if c.argc > 1:
        from helpy.settings import usage as helpy_usage
        print(helpy_usage)
        sys.exit(1)
    elif c.argc == 1:
        from helpy.commands.pyhelp import print_help_for
        print_help_for(c.first)

    #------------------------------------------------------------------------------------------
    # [ DEFAULT MESSAGE FOR MATCH FAILURE ]
    #  Message to provide to the user when all above conditional logic fails to meet a true condition
    #------------------------------------------------------------------------------------------
    else:
        print(
            "Could not complete the command that you entered.  Please try again."
        )
        sys.exit(1)  #exit
Ejemplo n.º 2
0
def main():
    import sys
    from Naked.commandline import Command

    #------------------------------------------------------------------------------------------
    # [ Instantiate command line object ]
    #   used for all subsequent conditional logic in the CLI application
    #------------------------------------------------------------------------------------------
    c = Command(sys.argv[0], sys.argv[1:])
    #------------------------------------------------------------------------------------------
    # [ Command Suite Validation ] - early validation of appropriate command syntax
    # Test that user entered at least one argument to the executable, print usage if not
    #------------------------------------------------------------------------------------------
    if not c.app_validates_args():
        from helpy.settings import usage as helpy_usage
        print(helpy_usage)
        sys.exit(1)
    #------------------------------------------------------------------------------------------
    # [ NAKED FRAMEWORK COMMANDS ]
    # Naked framework provides default help, usage, and version commands for all applications
    #   --> settings for user messages are assigned in the lib/pyh/settings.py file
    #------------------------------------------------------------------------------------------
    if c.help():      # User requested pyh help information
        from helpy.settings import help as helpy_help
        print(helpy_help)
        sys.exit(0)
    elif c.usage():   # User requested pyh usage information
        from helpy.settings import usage as helpy_usage
        print(helpy_usage)
        sys.exit(0)
    elif c.version(): # User requested pyh version information
        from helpy.settings import app_name, major_version, minor_version, patch_version
        version_display_string = app_name + ' ' + major_version + '.' + minor_version + '.' + patch_version
        print(version_display_string)
        sys.exit(0)
    #------------------------------------------------------------------------------------------
    # [ PRIMARY COMMAND LOGIC ]
    #   Enter your command line parsing logic below
    #------------------------------------------------------------------------------------------

    if c.argc > 1:
        from helpy.settings import usage as helpy_usage
        print(helpy_usage)
        sys.exit(1)
    elif c.argc == 1:
        from helpy.commands.pyhelp import print_help_for
        print_help_for(c.first)

    #------------------------------------------------------------------------------------------
    # [ DEFAULT MESSAGE FOR MATCH FAILURE ]
    #  Message to provide to the user when all above conditional logic fails to meet a true condition
    #------------------------------------------------------------------------------------------
    else:
        print("Could not complete the command that you entered.  Please try again.")
        sys.exit(1) #exit