Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aerth committed Sep 16, 2016
1 parent 01eea4d commit 44cb825
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 149 deletions.
4 changes: 2 additions & 2 deletions cmd/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func main() {

if len(os.Args) == 2 && os.Args[1] == "home" {
q := qw.NewAuth()
q := qw.NewSocial()
q.Username = "obviouslychangethis"
q.Password = "nopassword?"
q.Node = "gnusocial.de"
Expand All @@ -29,7 +29,7 @@ func main() {
}

if len(os.Args) == 2 && os.Args[1] == "public" {
q2 := qw.NewAuth()
q2 := qw.NewSocial()
q2.Node = "gnusocial.de"
quips, err := q2.GetPublic(true)
if err != nil {
Expand Down
101 changes: 101 additions & 0 deletions cmd/go-quitter/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package main

import (
"fmt"
"os"
"strings"

"github.com/aerth/seconf"
)

func runConfig() {
if seconf.Detect(gnusocialpath) == false {
bar()
fmt.Println("Creating config file. You will be asked for your user, node, and password.")
fmt.Println("Your password will not echo.")
seconf.Create(gnusocialpath, "GNU Social", "GNU Social username", "Which GNU Social node? Example: gnusocial.de", "password: will not echo")
} else {
bar()
fmt.Println("Config file already exists.\nIf you want to create a new config file, move or delete the existing one.\nYou can also set the GNUSOCIALPATH env to use multiple config files. \nExample: GNUSOCIALPATH=gnusocial.de go-quitter config")
fmt.Println("\nConfig exists:", returnHomeDir()+"/."+gnusocialpath)
os.Exit(1)
}
}

func dontNeedConfig() {
//fmt.Println("Config file detected, but this command doesn't need to login.\nWould you like to select the GNU Social node using the config?\nType YES or NO (y/n)")
//if AskForConfirmation() == true {
// only use gnusocial node from config
configdecoded, err := seconf.Read(gnusocialpath)
if err != nil {
fmt.Println("error:")
fmt.Println(err)
os.Exit(1)
}
configarray := strings.Split(configdecoded, "::::")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if len(configarray) != 3 {
fmt.Println("Broken config file. Create a new one.")
os.Exit(1)
}
gnusocialnode = string(configarray[1])
//fmt.Println(gnusocialnode)
gnusocialnode = strings.Replace(gnusocialnode, "http://", "", -1)
gnusocialnode = strings.Replace(gnusocialnode, "https://", "", -1)
// gnusocialnode = strings.TrimLeft(gnusocialnode, "https://")
// gnusocialnode = strings.TrimLeft(gnusocialnode, "http://")
q.Node = gnusocialnode

}

func needConfig() {

if seconf.Detect(gnusocialpath) == true {
configdecoded, err := seconf.Read(gnusocialpath)
if err != nil {
fmt.Println("error:")
fmt.Println(err)
os.Exit(1)
}
//configstrings := string(configdecoded)
// fmt.Println("config strings:")
// fmt.Println(configdecoded)
configarray := strings.Split(configdecoded, "::::")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if len(configarray) != 3 {
fmt.Println("Broken config file. Create a new one. :(")
os.Exit(1)
}
username = string(configarray[0])
gnusocialnode = string(configarray[1])
gnusocialnode = strings.Replace(gnusocialnode, "http://", "", -1)
gnusocialnode = strings.Replace(gnusocialnode, "https://", "", -1)
password = string(configarray[2])

q.Username = username
q.Password = password
q.Node = gnusocialnode
if os.Getenv("GNUSOCIALUSER") != "" {
q.Username = os.Getenv("GNUSOCIALUSER")
}
if os.Getenv("GNUSOCIALPASS") != "" {
q.Password = os.Getenv("GNUSOCIALPASS")
}
if os.Getenv("GNUSOCIALNODE") != "" {
q.Node = os.Getenv("GNUSOCIALNODE")
}
if q.Username == username {
fmt.Println("Welcome back, " + q.Username + "@" + q.Node)
} else {
fmt.Println("Welcome, " + q.Username + "@" + q.Node)
}
} else {
fmt.Println("No config file detected.")
}
}
128 changes: 21 additions & 107 deletions cmd/go-quitter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var goquitter = "go-quitter v0.0.8"
var username = os.Getenv("GNUSOCIALUSER")
var password = os.Getenv("GNUSOCIALPASS")
var gnusocialnode = os.Getenv("GNUSOCIALNODE")
var fast bool = false

var apipath string = "https://" + gnusocialnode + "/api/statuses/home_timeline.json"
var gnusocialpath = "go-quitter"
var configuser = ""
Expand Down Expand Up @@ -83,8 +83,12 @@ func bar() {
// fmt.Println(versionbar)
}

var q *qw.Social

func main() {
q := qw.NewAuth()

q = qw.NewSocial()

if containsString(os.Args, "-debug") {
q.Scheme = "http://"
}
Expand All @@ -100,9 +104,10 @@ func main() {

// command: go-quitter
if len(os.Args) < 2 {
fmt.Println(usage)

fmt.Println("Current list of commands:")
fmt.Println(allCommands)
fmt.Printf("Run '%s -help' for more information.\n", os.Args[0])
fmt.Println(hashbar)
os.Exit(1)
}
Expand All @@ -117,17 +122,8 @@ func main() {

// command: go-quitter create
if os.Args[1] == "config" {
if seconf.Detect(gnusocialpath) == false {
bar()
fmt.Println("Creating config file. You will be asked for your user, node, and password.")
fmt.Println("Your password will not echo.")
seconf.Create(gnusocialpath, "GNU Social", "GNU Social username", "Which GNU Social node? Example: gnusocial.de", "password: will not echo")
} else {
bar()
fmt.Println("Config file already exists.\nIf you want to create a new config file, move or delete the existing one.\nYou can also set the GNUSOCIALPATH env to use multiple config files. \nExample: GNUSOCIALPATH=gnusocial.de go-quitter config")
fmt.Println("\nConfig exists:", returnHomeDir()+"/."+gnusocialpath)
os.Exit(1)
}
runConfig()
os.Exit(1)
}

// command: go-quitter help
Expand All @@ -150,85 +146,11 @@ func main() {
// command requires login credentials
needLogin := []string{"home", "follow", "unfollow", "post", "mentions", "mygroups", "join", "leave", "mention", "replies", "direct", "inbox", "sent"}
if containsString(needLogin, os.Args[1]) {
if seconf.Detect(gnusocialpath) == true {
configdecoded, err := seconf.Read(gnusocialpath)
if err != nil {
fmt.Println("error:")
fmt.Println(err)
os.Exit(1)
}
//configstrings := string(configdecoded)
// fmt.Println("config strings:")
// fmt.Println(configdecoded)
configarray := strings.Split(configdecoded, "::::")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if len(configarray) != 3 {
fmt.Println("Broken config file. Create a new one. :(")
os.Exit(1)
}
username = string(configarray[0])
gnusocialnode = string(configarray[1])
gnusocialnode = strings.Replace(gnusocialnode, "http://", "", -1)
gnusocialnode = strings.Replace(gnusocialnode, "https://", "", -1)
password = string(configarray[2])

q.Username = username
q.Password = password
q.Node = gnusocialnode
if os.Getenv("GNUSOCIALUSER") != "" {
q.Username = os.Getenv("GNUSOCIALUSER")
}
if os.Getenv("GNUSOCIALPASS") != "" {
q.Password = os.Getenv("GNUSOCIALPASS")
}
if os.Getenv("GNUSOCIALNODE") != "" {
q.Node = os.Getenv("GNUSOCIALNODE")
}
if q.Username == username {
fmt.Println("Welcome back, " + q.Username + "@" + q.Node)
} else {
fmt.Println("Welcome, " + q.Username + "@" + q.Node)
}
} else {
fmt.Println("No config file detected.")
}
// command doesn't need login
} else {
if seconf.Detect(gnusocialpath) == true {
//fmt.Println("Config file detected, but this command doesn't need to login.\nWould you like to select the GNU Social node using the config?\nType YES or NO (y/n)")
//if AskForConfirmation() == true {
// only use gnusocial node from config
configdecoded, err := seconf.Read(gnusocialpath)
if err != nil {
fmt.Println("error:")
fmt.Println(err)
os.Exit(1)
}
configarray := strings.Split(configdecoded, "::::")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if len(configarray) != 3 {
fmt.Println("Broken config file. Create a new one.")
os.Exit(1)
}
gnusocialnode = string(configarray[1])
//fmt.Println(gnusocialnode)
gnusocialnode = strings.Replace(gnusocialnode, "http://", "", -1)
gnusocialnode = strings.Replace(gnusocialnode, "https://", "", -1)
// gnusocialnode = strings.TrimLeft(gnusocialnode, "https://")
// gnusocialnode = strings.TrimLeft(gnusocialnode, "http://")
q.Node = gnusocialnode

//}
} else {
// We are relying on environmental vars or default node.
needConfig()
} else { // command doesn't need login
if seconf.Detect(gnusocialpath) {
dontNeedConfig()
}

}
// user environmental credentials if they exist
if os.Getenv("GNUSOCIALUSER") != "" {
Expand All @@ -241,18 +163,10 @@ func main() {
q.Node = os.Getenv("GNUSOCIALNODE")
}

// Set speed default slow
speed := false
lastvar := len(os.Args) - 1

if os.Args[lastvar] == "fast" || os.Getenv("GNUSOCIALFAST") == "true" {
speed = true
}

switch os.Args[1] {
// command: go-quitter read
case "read":
PrintQuips(q.GetPublic(speed))
PrintQuips(q.GetPublic())
os.Exit(0)

// command: go-quitter search _____
Expand All @@ -264,14 +178,14 @@ func main() {
if searchstr == "" {
searchstr = getTypin()
}
PrintQuips(q.DoSearch(searchstr, speed))
PrintQuips(q.DoSearch(searchstr))
os.Exit(0)

// command: go-quitter user aerth
case "user":
if len(os.Args) > 2 && os.Args[2] != "" {
userlookup := os.Args[2]
PrintQuips(q.GetUserTimeline(userlookup, speed))
PrintQuips(q.GetUserTimeline(userlookup))

os.Exit(0)
}
Expand All @@ -280,7 +194,7 @@ func main() {

// command: go-quitter mentions
case "mentions", "replies", "mention":
PrintQuips(q.GetMentions(speed))
PrintQuips(q.GetMentions())
os.Exit(0)

// command: go-quitter follow
Expand Down Expand Up @@ -315,17 +229,17 @@ func main() {

// command: go-quitter home
case "home":
PrintQuips(q.GetHome(speed))
PrintQuips(q.GetHome())
os.Exit(0)

// command: go-quitter groups
case "groups":
PrintGroups(q.ListAllGroups(speed))
PrintGroups(q.ListAllGroups())
os.Exit(0)

// command: go-quitter mygroups
case "mygroups":
PrintGroups(q.ListMyGroups(speed))
PrintGroups(q.ListMyGroups())
os.Exit(0)

// command: go-quitter join
Expand Down
4 changes: 2 additions & 2 deletions methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/url"
)

func (a Auth) FireGET(path string) ([]byte, error) {
func (a Social) FireGET(path string) ([]byte, error) {
if path == "" {
return nil, errors.New("No path")
}
Expand Down Expand Up @@ -38,7 +38,7 @@ func (a Auth) FireGET(path string) ([]byte, error) {

return body, nil
}
func (a Auth) FirePOST(path string, v url.Values) ([]byte, error) {
func (a Social) FirePOST(path string, v url.Values) ([]byte, error) {
if path == "" {
return nil, errors.New("No path")
}
Expand Down
Loading

0 comments on commit 44cb825

Please sign in to comment.