commit 59a59921146f1fcc61a9fbdef3014d427f4365ae Author: Niko Abeler Date: Tue Jul 19 20:41:35 2022 +0200 initial commit diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b2c512b --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module h4kor/kiss-social + +go 1.18 diff --git a/main.go b/main.go new file mode 100644 index 0000000..d06bd42 --- /dev/null +++ b/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "os" + "path" +) + +func CreateNewUser(repo string, name string) { + // creates repo folder if it doesn't exist + os.Mkdir(repo, 0755) + + // creates repo/name folder if it doesn't exist + user_dir := path.Join(repo, name) + os.Mkdir(user_dir, 0755) + os.Mkdir(path.Join(user_dir, "meta"), 0755) + os.WriteFile(path.Join(user_dir, "meta", "VERSION"), []byte("0.0.1"), 0644) + os.WriteFile(path.Join(user_dir, "meta", "base.html"), []byte("<{{content}}/body>"), 0644) +} + +func main() { + println("KISS Social") + println("Commands") + println("new - Creates a new user") + + args := os.Args[1:] + if len(args) == 0 { + println("No command given") + return + } + + switch args[0] { + case "new": + if len(args) != 2 { + println("Invalid number of arguments") + return + } + CreateNewUser("users", args[1]) + default: + println("Invalid command") + } +} \ No newline at end of file diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..1e15085 --- /dev/null +++ b/main_test.go @@ -0,0 +1,31 @@ +package main_test + +import ( + "os" + "testing" + "h4kor/kiss-social" +) + +func TestCanCreateANewUser(t *testing.T) { + // Create a new user + main.CreateNewUser("/tmp/test", "testuser") + if _, err := os.Stat("/tmp/test/testuser"); err != nil { + t.Error("User directory not created") + } +} + +func TestCreateUserAddsVersionFile(t *testing.T) { + // Create a new user + main.CreateNewUser("/tmp/test", "testuser") + if _, err := os.Stat("/tmp/test/testuser/meta/VERSION"); err != nil { + t.Error("Version file not created") + } +} + +func TestCreateUserAddsBaseHtmlFile(t *testing.T) { + // Create a new user + main.CreateNewUser("/tmp/test", "testuser") + if _, err := os.Stat("/tmp/test/testuser/meta/base.html"); err != nil { + t.Error("Base html file not created") + } +} \ No newline at end of file