parent
e9ee59d2ec
commit
0766101ff6
@ -0,0 +1,50 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"h4kor/owl-blogs" |
||||
|
||||
"github.com/spf13/cobra" |
||||
) |
||||
|
||||
var postTitle string |
||||
|
||||
func init() { |
||||
rootCmd.AddCommand(newPostCmd) |
||||
newPostCmd.PersistentFlags().StringVar(&postTitle, "title", "", "Post title") |
||||
} |
||||
|
||||
var newPostCmd = &cobra.Command{ |
||||
Use: "new-post", |
||||
Short: "Creates a new post", |
||||
Long: `Creates a new post`, |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
if user == "" { |
||||
println("Username is required") |
||||
return |
||||
} |
||||
|
||||
if postTitle == "" { |
||||
println("Post title is required") |
||||
return |
||||
} |
||||
|
||||
repo, err := owl.OpenRepository(repoPath) |
||||
if err != nil { |
||||
println("Error opening repository: ", err.Error()) |
||||
return |
||||
} |
||||
|
||||
user, err := repo.GetUser(user) |
||||
if err != nil { |
||||
println("Error getting user: ", err.Error()) |
||||
return |
||||
} |
||||
|
||||
_, err = user.CreateNewPost(postTitle) |
||||
if err != nil { |
||||
println("Error creating post: ", err.Error()) |
||||
} else { |
||||
println("Post created: ", postTitle) |
||||
} |
||||
}, |
||||
} |
@ -0,0 +1,38 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"h4kor/owl-blogs" |
||||
|
||||
"github.com/spf13/cobra" |
||||
) |
||||
|
||||
var user string |
||||
|
||||
func init() { |
||||
rootCmd.AddCommand(newUserCmd) |
||||
} |
||||
|
||||
var newUserCmd = &cobra.Command{ |
||||
Use: "new-user", |
||||
Short: "Creates a new user", |
||||
Long: `Creates a new user`, |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
if user == "" { |
||||
println("Username is required") |
||||
return |
||||
} |
||||
|
||||
repo, err := owl.OpenRepository(repoPath) |
||||
if err != nil { |
||||
println("Error opening repository: ", err.Error()) |
||||
return |
||||
} |
||||
|
||||
_, err = repo.CreateUser(user) |
||||
if err != nil { |
||||
println("Error creating user: ", err.Error()) |
||||
} else { |
||||
println("User created: ", user) |
||||
} |
||||
}, |
||||
} |
Loading…
Reference in new issue