# Script to generate contents of https://github.com/Duke-GCB/DukeDSClient/wiki/All-Commands
from ddsc.ddsclient import DDSClient
from ddsc.versioncheck import get_internal_version_str
from argparse import SUPPRESS
import sys

# Fix argparse to have ddsclient instead of generatedocs.py as the command
sys.argv[0] = 'ddsclient'

DO_NOT_EDIT_WARNING = """
<!-- !!!NOTE!!!

This file is generated by running `python ddsc/generatedocs.py`.
DO NOT MANUALLY EDIT.

     !!!NOTE!!! -->
"""


def create_parser():
    return DDSClient()._create_parser().parser


def extract_help(cmd, action):
    description = action.description
    usage_help = action.format_usage()
    action.description = SUPPRESS
    action.usage = SUPPRESS
    return cmd, description, action.format_help(), usage_help


def get_command_help(parser):
    command_help = []
    for group in parser._subparsers._group_actions:
        for cmd, action in group.choices.items():
            command_help.append(extract_help(cmd, action))
    return command_help


def main():
    parser = create_parser()
    print(DO_NOT_EDIT_WARNING)
    version_str = get_internal_version_str()
    print(f"# DukeDSClient\nVersion {version_str}\n\n")
    print(f"## Commands\n")
    for cmd, description, help_text, usage_text in get_command_help(parser):
        print(f"### {cmd}\n{description}\n")
        print(f"```\n{usage_text}\n{help_text}\n```\n\n")


if __name__ == '__main__':
    main()

Add script to generate wiki command documentation
Add script to generate wiki command documentation

Adds ddsc/generatedocs.py to generate the wiki command list.
When command line argument changes are made this script will
generate markdown that should be added to the wiki on the
[All-Commands](https://github.com/Duke-GCB/DukeDSClient/wiki/All-Commands)
page.
