package tooter
import (
+ "fmt"
+
"git.vexingworkshop.com/signal9/dead-tooter/pkg/mastodon"
"github.com/spf13/cobra"
)
app, err = mastodon.Create(host, client)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Failed to create client: %s\n", err.Error())
}
err = app.Save()
if err != nil {
- panic(err.Error())
+ fmt.Printf("Failed to store client info: %s\n", err.Error())
}
}
code := account.Authorize(host, app)
token, err = account.RequestToken(host, app, code)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Failed to acquire request token: %s\n", err.Error())
}
err = token.Save()
if err != nil {
- panic(err.Error())
+ fmt.Printf("Failed to store access token: %s\n", err.Error())
}
err = account.VerifyCredentials(host, token)
if err != nil {
- panic(err.Error())
+ fmt.Printf("Failed to verify credentials: %s\n", err.Error())
}
}
rootCmd.PersistentFlags().StringVarP(&host,
"host", "H", "", "Mastodon host where your account lives.")
rootCmd.MarkFlagRequired("host")
+
}
var rootCmd = &cobra.Command{
Use: "dead-tooter",
Short: "A CLI for Mastodon hate scripts",
Long: `Provides a collection of capabilities that may or may not
- be present in the Mastodon web UI`,
+be present in the Mastodon web UI.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
var err error
}
},
- Run: func(cmd *cobra.Command, args []string) {
- fmt.Println("d34d-t00t3r")
- },
-
PersistentPostRun: func(cmd *cobra.Command, args []string) {
err := token.Save()
if err != nil {
err := exec.Command("xdg-open", u.String()).Start()
if err != nil {
- panic(err.Error())
+ return
}
fmt.Print("Enter returned code: ")
_, err = fmt.Scanln(&code)
if err != nil {
- panic(err.Error())
+ return
}
return
"path/filepath"
)
-// ConfigDir points to the default location of serialized files,
-// such as application info and tokens
-const ConfigDir = ".dead-tooter"
-
// RedirectUris when passed to the redirect_uris parameter, will
// show return the authorization code instead of redirecting the client.
const RedirectUris = "urn:ietf:wg:oauth:2.0:oob"
}
configdir = filepath.Join(configdir, "dead-tooter")
- err = os.Mkdir(ConfigDir, 0750)
+ err = os.Mkdir(configdir, 0750)
if err != nil && !os.IsExist(err) {
return
}
if err != nil {
return
}
-
tokenfile := filepath.Join(configdir, "dead-tooter", "token")
+
err = os.WriteFile(tokenfile, data, 0666)
if err != nil {
return