def command_convert(args):

    try:
        configfile = args.config
    except exc.TmuxpException:
        print('Please enter a config')

    file_user = os.path.join(config_dir, configfile)
    file_cwd = os.path.join(cwd_dir, configfile)
    if os.path.exists(file_cwd) and os.path.isfile(file_cwd):
        fullfile = os.path.normpath(file_cwd)
        filename, ext = os.path.splitext(file_cwd)
    elif os.path.exists(file_user) and os.path.isfile(file_user):

        fullfile = os.path.normpath(file_user)
        filename, ext = os.path.splitext(file_user)
    else:
        logger.error('%s not found.' % configfile)
        return

    if 'json' in ext:
        if args.answer_yes or prompt_yes_no(
            'convert to <%s> to yaml?' % (fullfile)
        ):
            configparser = kaptan.Kaptan()
            configparser.import_config(configfile)
            newfile = fullfile.replace(ext, '.yaml')
            newconfig = configparser.export(
                'yaml', indent=2, default_flow_style=False
            )
            if args.answer_yes or prompt_yes_no(
                'Save config to %s?' % (newfile)
            ):
                buf = open(newfile, 'w')
                buf.write(newconfig)
                buf.close()
                print('New config saved to %s' % (newfile))
    elif 'yaml' in ext:
        if args.answer_yes or prompt_yes_no(
            'convert to <%s> to json?' % (fullfile)
        ):
            configparser = kaptan.Kaptan()
            configparser.import_config(configfile)
            newfile = fullfile.replace(ext, '.json')
            newconfig = configparser.export('json', indent=2)
            print(newconfig)
            if args.answer_yes or prompt_yes_no(
                'Save config to <%s>?' % (newfile)
            ):
                buf = open(newfile, 'w')
                buf.write(newconfig)
                buf.close()
                print('New config saved to <%s>.' % (newfile))
Convert tmuxp config to and from JSON and YAML.
dataset/ETHPy150Open tony/tmuxp/tmuxp/cli.py/command_convert