Sending Webmentions #10

Merged
h4kor merged 18 commits from webmention into master 2022-09-06 19:49:00 +00:00
2 changed files with 1 additions and 74 deletions
Showing only changes of commit 57d6a93014 - Show all commits

View File

@ -1,71 +0,0 @@
package main
import (
"h4kor/owl-blogs"
"os"
)
func main() {
println("owl blogs")
println("Commands")
println("init <repo> - Creates a new repository")
println("<repo> new-user <name> - Creates a new user")
println("<repo> new-post <user> <title> - Creates a new post")
if len(os.Args) < 3 {
println("Please specify a repository and command")
os.Exit(1)
}
if os.Args[1] == "init" {
repoName := os.Args[2]
_, err := owl.CreateRepository(repoName)
if err != nil {
println("Error creating repository: ", err.Error())
}
println("Repository created: ", repoName)
os.Exit(0)
}
repoName := os.Args[1]
repo, err := owl.OpenRepository(repoName)
if err != nil {
println("Error opening repository: ", err.Error())
os.Exit(1)
}
switch os.Args[2] {
case "new-user":
if len(os.Args) < 4 {
println("Please specify a user name")
os.Exit(1)
}
userName := os.Args[3]
user, err := repo.CreateUser(userName)
if err != nil {
println("Error creating user: ", err.Error())
os.Exit(1)
}
println("User created: ", user.Name())
case "new-post":
if len(os.Args) < 5 {
println("Please specify a user name and a title")
os.Exit(1)
}
userName := os.Args[3]
user, err := repo.GetUser(userName)
if err != nil {
println("Error finding user: ", err.Error())
os.Exit(1)
}
title := os.Args[4]
post, err := user.CreateNewPost(title)
if err != nil {
println("Error creating post: ", err.Error())
os.Exit(1)
}
println("Post created: ", post.Title())
default:
println("Unknown command: ", os.Args[2])
os.Exit(1)
}
}

View File

@ -11,8 +11,6 @@ var repoPath string
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "owl", Use: "owl",
Short: "Owl Blogs is a not so static blog generator", Short: "Owl Blogs is a not so static blog generator",
// Run: func(cmd *cobra.Command, args []string) {
// },
} }
func Execute() { func Execute() {
@ -25,7 +23,7 @@ func Execute() {
func init() { func init() {
rootCmd.PersistentFlags().StringVar(&repoPath, "repo", ".", "Path to the repository to use.") rootCmd.PersistentFlags().StringVar(&repoPath, "repo", ".", "Path to the repository to use.")
rootCmd.PersistentFlags().StringVar(&user, "user", "", "Username") rootCmd.PersistentFlags().StringVar(&user, "user", "", "Username. Required for some commands.")
} }