"""
Command line entry point.
"""
from argparse import ArgumentParser
from os import environ
from pipes import quote
from sys import argv

from awsenv.cache import CachedSession, DEFAULT_SESSION_DURATION
from awsenv.profile import AWSProfile


def get_profile_name():
    """
    Get the profile name forom the environment.
    """
    return environ.get("AWS_PROFILE", environ.get("AWS_DEFAULT_PROFILE", "default"))


def parse_args(args):
    """
    Select the AWS profile to use.

    Defaults to the value of the `AWS_PROFILE` environment variable but
    allows overriding by command line arguments.
    """
    parser = ArgumentParser()
    parser.add_argument(
        "profile",
        nargs="?",
    )
    parser.add_argument(
        "--session-duration",
        type=int,
        default=DEFAULT_SESSION_DURATION,
    )
    args = parser.parse_args(args)
    return args


def to_environment(variables):
    """
    Print environment variables for a profile.
    """
    return "\n".join(
        "unset {};".format(key) if value is None else "export {}={}".format(key, quote(value))
        for key, value in variables.items()
    )


def get_profile(profile=None, session_duration=DEFAULT_SESSION_DURATION):
    """
    Construct an AWS Profile.

    :param profile: the name of the profile to use; resolves via environment
           variables if not set
    :param session_duration: the session duration (in seconds), defafults to
           one hour, which is also the maximum
    """
    # choose the profile name if necessary
    if profile is None:
        profile = get_profile_name()

    # look for a cached session in the environment
    cached_session = CachedSession.from_environment(
        session_duration=session_duration,
    )

    # then load the profile, updating credentials based on the cached session and/or assumed role
    aws_profile = AWSProfile(
        profile=profile,
        session_duration=session_duration,
        cached_session=cached_session,
    )
    aws_profile.update_credentials()

    return aws_profile


def main():
    args = parse_args(argv[1:])
    profile = get_profile(args.profile, args.session_duration)
    print to_environment(profile.to_envvars())  # noqa

@@ -1214,19 +1214,37 @@
 DURATION
+, assume_role=True
 ):%0A
-
     %22%22%22%0A
@@ -1507,16 +1507,164 @@
 maximum%0A
+    :param assume_role: control whether the given profile's role will be assumed;%0A           if not, the default profile's credentials will be used%0A
     %22%22%22%0A
@@ -1920,16 +1920,41 @@
 n,%0A    )
+ if assume_role else None
 %0A%0A    # 
@@ -2184,24 +2184,48 @@
 sion,%0A    )%0A
+    if assume_role:%0A    
     aws_prof

Allow non-assumption of roles