diff --git a/conda_env/cli/main.py b/conda_env/cli/main.py index d6b86ee..5249853 100644 --- a/conda_env/cli/main.py +++ b/conda_env/cli/main.py @@ -32,9 +32,10 @@ from . import main_create from . import main_export from . import main_list +from . import main_print from . import main_remove -from . import main_upload from . import main_update +from . import main_upload # TODO: This belongs in a helper library somewhere @@ -53,9 +54,10 @@ def create_parser(): main_create.configure_parser(sub_parsers) main_export.configure_parser(sub_parsers) main_list.configure_parser(sub_parsers) + main_print.configure_parser(sub_parsers) main_remove.configure_parser(sub_parsers) - main_upload.configure_parser(sub_parsers) main_update.configure_parser(sub_parsers) + main_upload.configure_parser(sub_parsers) show_help_on_empty_command() return p diff --git a/conda_env/cli/main_print.py b/conda_env/cli/main_print.py new file mode 100644 index 0000000..f6edec7 --- /dev/null +++ b/conda_env/cli/main_print.py @@ -0,0 +1,48 @@ +from __future__ import print_function + +description = """ +Prints content from environment.yml files. + +Handles includes and jinja2 parsing. +""" + +example = """ +examples: + conda env print path/to/environment.yml + conda env print path/to/environment.yml --json +""" + + +def configure_parser(sub_parsers): + from argparse import RawDescriptionHelpFormatter + + p = sub_parsers.add_parser( + 'print', + formatter_class=RawDescriptionHelpFormatter, + description=description, + help=description, + epilog=example, + ) + p.add_argument( + '-f', '--file', + action='store', + help='environment definition file (default: environment.yml)', + default='environment.yml', + ) + + from conda.cli import common + common.add_parser_json(p) + + p.set_defaults(func=execute) + + +def execute(args, parser): + from conda_env.env import from_file + env = from_file(args.file) + + if args.json: + from conda.cli.common import stdout_json + stdout_json(env.to_dict()) + else: + import sys + env.to_yaml(sys.stdout)