agent/app/run.go
func Run(arguments []string) int {
	defer log.Flush()

	parsedArgs, err := args.New(arguments)
	if err != nil {
		return exitcodes.ExitTerminal
	}

	if *parsedArgs.License {
		return printLicense()
	} else if *parsedArgs.Version {
		return version.PrintVersion()
	}

	logger.SetLevel(*parsedArgs.LogLevel)

	// Create an Agent object
	agent, err := newAgent(context.Background(),
		aws.BoolValue(parsedArgs.BlackholeEC2Metadata),
		parsedArgs.AcceptInsecureCert)
	if err != nil {
		// Failure to initialize either the docker client or the EC2 metadata
		// service client are non terminal errors as they could be transient
		return exitcodes.ExitError
	}

	switch {
	case *parsedArgs.ECSAttributes:
		// Print agent's ecs attributes based on its environment and exit
		return agent.printECSAttributes()
	case *parsedArgs.WindowsService:
		// Enable Windows Service
		return agent.startWindowsService()
	default:
		// Start the agent
		return agent.start()
	}
}
func Run(arguments []string) int {
	defer log.Flush()

	parsedArgs, err := args.New(arguments)
	if err != nil {
		return exitcodes.ExitTerminal
	}

	if *parsedArgs.License {
		return printLicense()
	} else if *parsedArgs.Version {
		return version.PrintVersion()
	}

	logger.SetLevel(*parsedArgs.LogLevel)

	// Create an Agent object
	agent, err := newAgent(context.Background(),
		aws.BoolValue(parsedArgs.BlackholeEC2Metadata),
		parsedArgs.AcceptInsecureCert)
	if err != nil {
		// Failure to initialize either the docker client or the EC2 metadata
		// service client are non terminal errors as they could be transient
		return exitcodes.ExitError
	}

	switch {
	case *parsedArgs.ECSAttributes:
		// Print agent's ecs attributes based on its environment and exit
		return agent.printECSAttributes()
	case *parsedArgs.WindowsService:
		// Enable Windows Service
		return agent.startWindowsService()
	default:
		// Start the agent
		return agent.start()
	}
}
// Run runs the ECS Agent App. It returns an exit code, which is used by
// main() to set the status code for the program