@click.command()
@click.option('--get', '-g', 'action', flag_value='get_credential',
              help='retrieve a credential from keyring storage')
@click.option('--set', '-s', 'action', flag_value='set_credential',
              help='store a credential in keyring storage',)
@click.argument('environment', nargs=1)
@click.argument('parameter', nargs=1)
@click.pass_context
def run_supernova_keyring(ctx, action, environment, parameter):
    """
    Sets or retrieves credentials stored in your system's keyring using the
    python-keyring module.

    Global credentials can be shared between multiple configuration sections:

    \b
        [prod]
        OS_PASSWORD=USE_KEYRING['sso_password']
        ...

    \b
        [staging]
        OS_PASSWORD=USE_KEYRING['my sso_password']
        ...

    You could retrieve or set the global credential using these commands:

    \b
        supernova -g global sso_password     <= get the credential
        supernova -s global sso_password     <= set the credential

    Local credentials are intended for use with only one configuration section:

    \b
        [prod]
        OS_PASSWORD=USE_KEYRING
        ...

    \b
        [staging]
        OS_PASSWORD=USE_KEYRING
        ...

    You could retrieve or set the local credential using these commands:

    \b
        supernova -g prod OS_PASSWORD     <= get the credential for prod
        supernova -s prod OS_PASSWORD     <= set the credential for prod

    \b
        supernova -g staging OS_PASSWORD  <= get the credential for staging
        supernova -s staging OS_PASSWORD  <= set the credential for staging

    Full documentation:

    \b
        http://supernova.readthedocs.org/en/latest/configuring/

    """
    if action == 'get_credential':
        result = credentials.get_user_password(env=environment,
                                               param=parameter)
        if not result:
            click.echo("\nUnable to find a credential matching the data "
                       "provided.")
            ctx.exit(1)
        else:
            click.echo("\nFound credential for {0}: {1}".format(*result))
            ctx.exit()

    elif action == 'set_credential':
        msg = """
Preparing to set a credential in the keyring for:

  - Environment  : {0}
  - Parameter    : {1}

If this is correct, enter the corresponding credential to store in your keyring
or press CTRL-C to abort""".format(environment, parameter)
        credential = click.prompt(text=msg, hide_input=True)

        result = credentials.set_user_password(environment=environment,
                                               parameter=parameter,
                                               password=credential)

        if result:
            click.echo("\nSuccessfully stored.")
            ctx.exit()
        else:
            click.echo("\nUnable to store your credential.")
            ctx.exit(1)
    else:
        click.secho("ERROR: must specify --get or --set", bold=True)
        click.echo(ctx.get_help())
        ctx.exit()
dataset/ETHPy150Open major/supernova/supernova/executable.py/run_supernova_keyring/original