func NewRootCommand()

in cmd/rootCmd.go [58:122]


func NewRootCommand() *cobra.Command {

	rootCmd := &cobra.Command{
		Use:   "azmpf",
		Short: "Find minimum permissions required for Azure deployments",
		Long: `Find minimum permissions required for Azure deployments including ARM and Terraform based deployments. For example:
		
		This CLI allows you to find the minimum permissions required for Azure deployments including ARM and Terraform based deployments. 
		A Service Principal is required to run this CLI. All permissions associated with the Service principal are initially wiped by this command:`,
		Example: `azmpf arm --subscriptionID <subscriptionID> --tenantID <tenantID> --spClientID <spClientID> --spObjectID <spObjectID> --spClientSecret <spClientSecret>
		az-mpm terraform --subscriptionID <subscriptionID> --tenantID <tenantID> --spClientID <spClientID> --spObjectID <spObjectID> --spClientSecret <spClientSecret> --executablePath <executablePath> --workingDir <workingDir> --varFilePath <varFilePath>
		`,
		PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
			return initializeConfig(cmd)
		},
		Run: func(cmd *cobra.Command, args []string) {

		},
	}

	// Define cobra flags, the default value has the lowest (least significant) precedence
	rootCmd.PersistentFlags().StringVarP(&flgSubscriptionID, "subscriptionID", "s", "", "Azure Subscription ID")
	rootCmd.PersistentFlags().StringVarP(&flgTenantID, "tenantID", "", "", "Azure Tenant ID")
	rootCmd.PersistentFlags().StringVarP(&flgSPClientID, "spClientID", "", "", "Service Principal Client ID")
	rootCmd.PersistentFlags().StringVarP(&flgSPObjectID, "spObjectID", "", "", "Service Principal Object ID")
	rootCmd.PersistentFlags().StringVarP(&flgSPClientSecret, "spClientSecret", "", "", "Service Principal Client Secret")
	rootCmd.PersistentFlags().BoolVarP(&flgShowDetailedOutput, "showDetailedOutput", "", false, "Show detailed output")
	rootCmd.PersistentFlags().BoolVarP(&flgJSONOutput, "jsonOutput", "", false, "Output in JSON format")
	rootCmd.PersistentFlags().BoolVarP(&flgVerbose, "verbose", "v", false, "verbose output")
	rootCmd.PersistentFlags().BoolVarP(&flgDebug, "debug", "d", false, "debug output")

	err := rootCmd.MarkPersistentFlagRequired("subscriptionID")
	if err != nil {
		log.Errorf("Error marking flag required for subscription ID: %v\n", err)
	}

	err = rootCmd.MarkPersistentFlagRequired("tenantID")
	if err != nil {
		log.Errorf("Error marking flag required for tenant ID: %v\n", err)
	}

	err = rootCmd.MarkPersistentFlagRequired("spClientID")
	if err != nil {
		log.Errorf("Error marking flag required for SP client ID: %v\n", err)
	}

	err = rootCmd.MarkPersistentFlagRequired("spObjectID")
	if err != nil {
		log.Errorf("Error marking flag required for SP object ID: %v\n", err)
	}

	err = rootCmd.MarkPersistentFlagRequired("spClientSecret")
	if err != nil {
		log.Errorf("Error marking flag required for SP client secret: %v\n", err)
	}

	rootCmd.MarkFlagsMutuallyExclusive("showDetailedOutput", "jsonOutput")

	// Add subcommands
	rootCmd.AddCommand(NewARMCommand())
	rootCmd.AddCommand(NewBicepCommand())
	rootCmd.AddCommand(NewTerraformCommand())

	return rootCmd
}