func execCmd(ctx *cli.Context) error {
	profile, cfg, err := resolveConfig(ctx, guessNArgs(ctx.NArg()))
	if err != nil {
		return err
	}
	if !ctx.Args().Present() && len(profile) < 1 {
		log.Errorln("nothing to do!")
		cli.ShowAppHelpAndExit(ctx, 1)
	}
	var c client.AwsClient
	c, err = clientFactory.Get(cfg)
	if err != nil {
		return err
	}
	if ctx.Bool(refreshFlag.Name) {
		refreshCreds(c)
	}
	var creds *credentials.Credentials
	creds, err = c.Credentials()
	if err != nil {
		return err
	}
	if strings.EqualFold(ctx.String(fmtFlag.Name), "json") {
		var out []byte
		out, err = creds.CredentialsProcess()
		if err != nil {
			return err
		}
		fmt.Printf("%s\n", out)
		return nil
	}
	if ctx.Bool(expFlag.Name) {
		printCredExpiration(creds)
	}
	if ctx.Bool(whoamiFlag.Name) {
		if err = printCredIdentity(sts.NewFromConfig(c.ConfigProvider())); err != nil {
			return err
		}
	}
	cmd := ctx.Args().Slice()
	if ctx.Args().First() == profile {
		cmd = ctx.Args().Tail()
	}
	env := buildEnv(cfg.Region, creds)
	if len(cmd) > 0 {
		if ctx.Bool(envFlag.Name) {
			for k, v := range env {
				_ = os.Setenv(k, v)
			}
		} else {
			var ch <-chan bool
			ch, err = runEcsSvc(c, cfg)
			if err != nil {
				return err
			}
			<-ch
			log.Debugf("ECS endpoint ready")
		}
		wrapped := wrapCmd(cmd)
		c := exec.Command(wrapped[0], wrapped[1:]...)  
		c.Stdin = os.Stdin
		c.Stdout = os.Stdout
		c.Stderr = os.Stderr
		installSignalHandler()
		if err = c.Run(); err != nil {
			log.Debug("Error running command")
			return err
		}
	} else {
		printCreds(env)
	}
	return nil
}
nolint:funlen,gocognit,gocyclo // he's just a long boi ... you should have seen the older versions!
package cli
import (
	"fmt"
	"github.com/aws/aws-sdk-go-v2/service/sts"
	"github.com/aws/smithy-go/logging"
	"github.com/mmmorris1975/aws-runas/client"
	"github.com/mmmorris1975/aws-runas/config"
	"github.com/mmmorris1975/aws-runas/credentials"
	"github.com/mmmorris1975/aws-runas/metadata"
	"github.com/mmmorris1975/simple-logger/logger"
	"github.com/urfave/cli/v2"
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"strings"
)
var (
	log           = logger.StdLogger
	opts          = client.DefaultOptions
	clientFactory = client.NewClientFactory(configResolver, opts)
	cmdlineCfg    = new(config.AwsConfig)
	cmdlineCreds  = new(config.AwsCredentials)
	configResolver config.Resolver = config.DefaultResolver.WithLogger(log)
)
var App = &cli.App{
	Usage:     "Create an environment for interacting with the AWS API using an assumed role",
	UsageText: fmt.Sprintf("%s [global options] [subcommand] profile [arguments...]", filepath.Base(os.Args[0])),
	Commands:  []*cli.Command{listCmd, serveCmd, ssmCmd, ecrCmd, passwordCmd, diagCmd, updateCmd},
	Flags:     append(configFlags, append(otherFlags, shortcutFlags...)...),
	UseShortOptionHandling: true,
	EnableBashCompletion:   true,
	BashComplete: func(ctx *cli.Context) {
		if ctx.Bool(mfaFlag.Name) {
			mfaCmd.BashComplete(ctx)
			return
		}
		if ctx.Bool(rolesFlag.Name) {
			rolesCmd.BashComplete(ctx)
			return
		}
		if ctx.Bool(diagFlag.Name) {
			diagCmd.BashComplete(ctx)
			return
		}
		cli.DefaultAppComplete(ctx)
		bashCompleteProfile(ctx)
	},
	Before: func(ctx *cli.Context) error {
		opts.Logger = log
		if verbose, ok := ctx.Value(vFlag.Name).([]bool); ok {
			if len(verbose) > 0 {
				log.SetLevel(logger.DEBUG)
				if len(verbose) > 1 {
					opts.AwsLogLevel = logging.Debug
				}
			}
		}
		username := ctx.String(usernameFlag.Name)
		provider := ctx.String(providerFlag.Name)
		cmdlineCfg.SamlUsername = username
		cmdlineCfg.SamlProvider = provider
		cmdlineCfg.WebIdentityUsername = username
		cmdlineCfg.WebIdentityProvider = provider
		password := ctx.String(passwordFlag.Name)
		cmdlineCreds.SamlPassword = password
		cmdlineCreds.WebIdentityPassword = password
		opts.CommandCredentials = cmdlineCreds
		return nil
	},
	Metadata: map[string]interface{}{
		"url": "https://github.com/mmmorris1975/aws-runas",
	},
	Action: func(ctx *cli.Context) error {
		if ctx.Bool(mfaFlag.Name) {
			return mfaCmd.Run(ctx)
		}
		if ctx.Bool(rolesFlag.Name) {
			return rolesCmd.Run(ctx)
		}
		if ctx.Bool(updateFlag.Name) {
			return updateCmd.Run(ctx)
		}
		if ctx.Bool(diagFlag.Name) {
			return diagCmd.Run(ctx)
		}
		return execCmd(ctx)
	},
}
func init() {
	cli.VersionFlag = &cli.BoolFlag{
		Name:    "version",
		Aliases: []string{"V"},
		Usage:   "print the version",
	}
}