-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
219 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.