Created
May 10, 2019 13:13
-
-
Save kyriediculous/efa0a044af59a7fd960f6ec2af077117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var updateCmd = &cobra.Command{ | |
Use: "update", | |
Short: "Find a Blog post by its ID", | |
Long: `Find a blog post by it's mongoDB Unique identifier. | |
If no blog post is found for the ID it will return a 'Not Found' error`, | |
RunE: func(cmd *cobra.Command, args []string) error { | |
// Get the flags from CLI | |
id, err := cmd.Flags().GetString("id") | |
author, err := cmd.Flags().GetString("author") | |
title, err := cmd.Flags().GetString("title") | |
content, err := cmd.Flags().GetString("content") | |
// Create an UpdateBlogRequest | |
req := &blogpb.UpdateBlogReq{ | |
&blogpb.Blog{ | |
Id: id, | |
AuthorId: author, | |
Title: title, | |
Content: content, | |
}, | |
} | |
res, err := client.UpdateBlog(context.Background(), req) | |
if err != nil { | |
return err | |
} | |
fmt.Println(res) | |
return nil | |
}, | |
} | |
func init() { | |
updateCmd.Flags().StringP("id", "i", "", "The id of the blog") | |
updateCmd.Flags().StringP("author", "a", "", "Add an author") | |
updateCmd.Flags().StringP("title", "t", "", "A title for the blog") | |
updateCmd.Flags().StringP("content", "c", "", "The content for the blog") | |
updateCmd.MarkFlagRequired("id") | |
rootCmd.AddCommand(updateCmd) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment