Unknown model· unknown
from NVIDIA HelpSteer3 Preference
make golang cli that list all available ansible playbooks on a remote server using grpc…
- User
make golang cli that list all available ansible playbooks on a remote server using grpc and cobra1 / 1
- Assistantgo
package main import ( "context" "fmt" "log" "os" "github.com/spf13/cobra" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" pb "path/to/your/proto/file" // Replace with your actual proto file path ) var ( serverAddr string ) func main() { rootCmd := &cobra.Command{ Use: "ansible-playbook-lister", Short: "List Ansible playbooks on a remote server", Run: func(cmd *cobra.Command, args []string) { conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { log.Fatalf("Failed to connect to server: %v", err) } defer conn.Close() client := pb.NewPlaybookServiceClient(conn) resp, err := client.ListPlaybooks(context.Background(), &pb.ListPlaybooksRequest{}) if err != nil { log.Fatalf("Failed to list playbooks: %v", err) } fmt.Println("Available Playbooks:") for _, playbook := range resp.Playbooks { fmt.Println(playbook) } }, } rootCmd.Flags().StringVarP(&serverAddr, "server", "s", "localhost:50051", "Address of the gRPC server") if err := rootCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) } }Explanation:
-
Import necessary packages:
context: For managing the gRPC context.fmt: For printing output.log: For logging errors.os: For exiting the program on errors.spf13/cobra: For creating the CLI.google.golang.org/grpc: For gRPC communication.google.golang.org/grpc/credentials/insecure: For insecure gRPC connection (replace with secure credentials if needed).
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.