package subcmd import ( "flag" "fmt" "os" ) func SubCmd() { agentCmd := flag.NewFlagSet("agent", flag.ExitOnError) agentLevel := agentCmd.Uint64("level", 1, "Level of the agent from 1-5") agentName := agentCmd.String("name", "", "Name of the agent") missionCmd := flag.NewFlagSet("mission", flag.ExitOnError) missionName := missionCmd.String("codename", "classified", "Codename of the mission") missionImpossible := missionCmd.Bool("impossible", false, "Is the mission impossible?") if len(os.Args) < 2 { fmt.Fprintln(os.Stderr, "A subcommand must be provided ('mission', 'agent')") os.Exit(2) } switch os.Args[1] { case "agent": agentCmd.Parse(os.Args[2:]) fmt.Println("Agent level:", *agentLevel) fmt.Println("Agent name:", *agentName) case "mission": missionCmd.Parse(os.Args[2:]) fmt.Println("Mission codename:", *missionName) fmt.Println("Mission impossible?", *missionImpossible) default: fmt.Fprintln(os.Stderr, "Invalid subcommand. Only valid subcommands are 'mission' and 'agent'") os.Exit(2) } }