Command line client for Write.as https://write.as/apps/cli
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.3 KiB

  1. package config
  2. import (
  3. "github.com/cloudfoundry/jibber_jabber"
  4. "github.com/writeas/writeas-cli/log"
  5. cli "gopkg.in/urfave/cli.v1"
  6. )
  7. // Application constants.
  8. const (
  9. Version = "2.0"
  10. defaultUserAgent = "writeas-cli v" + Version
  11. // Defaults for posts on Write.as.
  12. DefaultFont = PostFontMono
  13. WriteasBaseURL = "https://write.as"
  14. DevBaseURL = "https://development.write.as"
  15. TorBaseURL = "http://writeas7pm7rcdqg.onion"
  16. torPort = 9150
  17. )
  18. func UserAgent(c *cli.Context) string {
  19. ua := c.String("user-agent")
  20. if ua == "" {
  21. return defaultUserAgent
  22. }
  23. return ua + " (" + defaultUserAgent + ")"
  24. }
  25. func IsTor(c *cli.Context) bool {
  26. return c.Bool("tor") || c.Bool("t")
  27. }
  28. func TorPort(c *cli.Context) int {
  29. if c.IsSet("tor-port") && c.Int("tor-port") != 0 {
  30. return c.Int("tor-port")
  31. }
  32. return torPort
  33. }
  34. func Language(c *cli.Context, auto bool) string {
  35. if l := c.String("lang"); l != "" {
  36. return l
  37. }
  38. if !auto {
  39. return ""
  40. }
  41. // Automatically detect language
  42. l, err := jibber_jabber.DetectLanguage()
  43. if err != nil {
  44. log.Info(c, "Language detection failed: %s", err)
  45. return ""
  46. }
  47. return l
  48. }
  49. func Collection(c *cli.Context) string {
  50. if coll := c.String("c"); coll != "" {
  51. return coll
  52. }
  53. if coll := c.String("b"); coll != "" {
  54. return coll
  55. }
  56. return ""
  57. }