main.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package main
  2. import (
  3. "os"
  4. "strings"
  5. "gopkg.in/alecthomas/kingpin.v2"
  6. )
  7. var (
  8. app = kingpin.New("chat", "A command-line chat application.")
  9. debug = app.Flag("debug", "Enable debug mode.").Bool()
  10. serverIP = app.Flag("server", "Server address.").Default("127.0.0.1").IP()
  11. register = app.Command("register", "Register a new user.")
  12. registerNick = register.Arg("nick", "Nickname for user.").Required().String()
  13. registerName = register.Arg("name", "Name of user.").Required().String()
  14. post = app.Command("post", "Post a message to a channel.")
  15. postImage = post.Flag("image", "Image to post.").File()
  16. postChannel = post.Arg("channel", "Channel to post to.").Required().String()
  17. postText = post.Arg("text", "Text to post.").Strings()
  18. )
  19. func main() {
  20. switch kingpin.MustParse(app.Parse(os.Args[1:])) {
  21. // Register user
  22. case register.FullCommand():
  23. println(*registerNick)
  24. // Post message
  25. case post.FullCommand():
  26. if *postImage != nil {
  27. }
  28. text := strings.Join(*postText, " ")
  29. println("Post:", text)
  30. }
  31. }