mirror of
https://github.com/writeas/writeas-cli
synced 2025-07-22 22:08:13 +00:00
Show correct executable name in user messages
This commit is contained in:
parent
5212fa12c8
commit
a53cbb16b5
@ -7,6 +7,7 @@ import (
|
||||
writeas "github.com/writeas/go-writeas/v2"
|
||||
"github.com/writeas/web-core/posts"
|
||||
"github.com/writeas/writeas-cli/config"
|
||||
"github.com/writeas/writeas-cli/executable"
|
||||
"github.com/writeas/writeas-cli/log"
|
||||
cli "gopkg.in/urfave/cli.v1"
|
||||
)
|
||||
@ -39,7 +40,7 @@ func newClient(c *cli.Context, authRequired bool) (*writeas.Client, error) {
|
||||
if u != nil {
|
||||
client.SetToken(u.AccessToken)
|
||||
} else if authRequired {
|
||||
return nil, fmt.Errorf("Not currently logged in. Authenticate with: writeas auth <username>")
|
||||
return nil, fmt.Errorf("Not currently logged in. Authenticate with: " + executable.Name() + " auth <username>")
|
||||
}
|
||||
|
||||
return client, nil
|
||||
@ -136,7 +137,7 @@ func DoPost(c *cli.Context, post []byte, font string, encrypt, code bool) (*writ
|
||||
// Copy URL to clipboard
|
||||
err = clipboard.WriteAll(string(url))
|
||||
if err != nil {
|
||||
log.Errorln("writeas: Didn't copy to clipboard: %s", err)
|
||||
log.Errorln(executable.Name()+": Didn't copy to clipboard: %s", err)
|
||||
} else {
|
||||
log.Info(c, "Copied to clipboard.")
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/howeyc/gopass"
|
||||
"github.com/writeas/writeas-cli/api"
|
||||
"github.com/writeas/writeas-cli/config"
|
||||
"github.com/writeas/writeas-cli/executable"
|
||||
"github.com/writeas/writeas-cli/log"
|
||||
cli "gopkg.in/urfave/cli.v1"
|
||||
)
|
||||
@ -67,7 +68,7 @@ func CmdNew(c *cli.Context) error {
|
||||
func CmdPublish(c *cli.Context) error {
|
||||
filename := c.Args().Get(0)
|
||||
if filename == "" {
|
||||
return cli.NewExitError("usage: writeas publish <filename>", 1)
|
||||
return cli.NewExitError("usage: "+executable.Name()+" publish <filename>", 1)
|
||||
}
|
||||
content, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
@ -92,7 +93,7 @@ func CmdDelete(c *cli.Context) error {
|
||||
friendlyID := c.Args().Get(0)
|
||||
token := c.Args().Get(1)
|
||||
if friendlyID == "" {
|
||||
return cli.NewExitError("usage: writeas delete <postId> [<token>]", 1)
|
||||
return cli.NewExitError("usage: "+executable.Name()+" delete <postId> [<token>]", 1)
|
||||
}
|
||||
|
||||
u, _ := config.LoadUser(c)
|
||||
@ -101,7 +102,7 @@ func CmdDelete(c *cli.Context) error {
|
||||
token = api.TokenFromID(c, friendlyID)
|
||||
if token == "" && u == nil {
|
||||
log.Errorln("Couldn't find an edit token locally. Did you create this post here?")
|
||||
log.ErrorlnQuit("If you have an edit token, use: writeas delete %s <token>", friendlyID)
|
||||
log.ErrorlnQuit("If you have an edit token, use: "+executable.Name()+" delete %s <token>", friendlyID)
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,7 +125,7 @@ func CmdUpdate(c *cli.Context) error {
|
||||
friendlyID := c.Args().Get(0)
|
||||
token := c.Args().Get(1)
|
||||
if friendlyID == "" {
|
||||
return cli.NewExitError("usage: writeas update <postId> [<token>]", 1)
|
||||
return cli.NewExitError("usage: "+executable.Name()+" update <postId> [<token>]", 1)
|
||||
}
|
||||
|
||||
u, _ := config.LoadUser(c)
|
||||
@ -133,7 +134,7 @@ func CmdUpdate(c *cli.Context) error {
|
||||
token = api.TokenFromID(c, friendlyID)
|
||||
if token == "" && u == nil {
|
||||
log.Errorln("Couldn't find an edit token locally. Did you create this post here?")
|
||||
log.ErrorlnQuit("If you have an edit token, use: writeas update %s <token>", friendlyID)
|
||||
log.ErrorlnQuit("If you have an edit token, use: "+executable.Name()+" update %s <token>", friendlyID)
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,7 +156,7 @@ func CmdUpdate(c *cli.Context) error {
|
||||
func CmdGet(c *cli.Context) error {
|
||||
friendlyID := c.Args().Get(0)
|
||||
if friendlyID == "" {
|
||||
return cli.NewExitError("usage: writeas get <postId>", 1)
|
||||
return cli.NewExitError("usage: "+executable.Name()+" get <postId>", 1)
|
||||
}
|
||||
|
||||
if config.IsTor(c) {
|
||||
@ -175,7 +176,7 @@ func CmdAdd(c *cli.Context) error {
|
||||
friendlyID := c.Args().Get(0)
|
||||
token := c.Args().Get(1)
|
||||
if friendlyID == "" || token == "" {
|
||||
return cli.NewExitError("usage: writeas add <postId> <token>", 1)
|
||||
return cli.NewExitError("usage: "+executable.Name()+" add <postId> <token>", 1)
|
||||
}
|
||||
|
||||
err := api.AddPost(c, friendlyID, token)
|
||||
@ -279,7 +280,7 @@ func CmdCollections(c *cli.Context) error {
|
||||
return cli.NewExitError(fmt.Sprintf("couldn't load config: %v", err), 1)
|
||||
}
|
||||
if u == nil {
|
||||
return cli.NewExitError("You must be authenticated to view collections.\nLog in first with: writeas auth <username>", 1)
|
||||
return cli.NewExitError("You must be authenticated to view collections.\nLog in first with: "+executable.Name()+" auth <username>", 1)
|
||||
}
|
||||
if config.IsTor(c) {
|
||||
log.Info(c, "Getting blogs via hidden service...")
|
||||
@ -314,7 +315,7 @@ func CmdClaim(c *cli.Context) error {
|
||||
return cli.NewExitError(fmt.Sprintf("couldn't load config: %v", err), 1)
|
||||
}
|
||||
if u == nil {
|
||||
return cli.NewExitError("You must be authenticated to claim local posts.\nLog in first with: writeas auth <username>", 1)
|
||||
return cli.NewExitError("You must be authenticated to claim local posts.\nLog in first with: "+executable.Name()+" auth <username>", 1)
|
||||
}
|
||||
|
||||
localPosts := api.GetPosts(c)
|
||||
@ -362,14 +363,14 @@ func CmdAuth(c *cli.Context) error {
|
||||
return cli.NewExitError(fmt.Sprintf("couldn't load config: %v", err), 1)
|
||||
}
|
||||
if u != nil && u.AccessToken != "" {
|
||||
return cli.NewExitError("You're already authenticated as "+u.User.Username+". Log out with: writeas logout", 1)
|
||||
return cli.NewExitError("You're already authenticated as "+u.User.Username+". Log out with: "+executable.Name()+" logout", 1)
|
||||
}
|
||||
|
||||
// Validate arguments and get password
|
||||
// TODO: after global config, check for default user
|
||||
username := c.Args().Get(0)
|
||||
if username == "" {
|
||||
return cli.NewExitError("usage: writeas auth <username>", 1)
|
||||
return cli.NewExitError("usage: "+executable.Name()+" auth <username>", 1)
|
||||
}
|
||||
|
||||
fmt.Print("Password: ")
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"os/exec"
|
||||
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
"github.com/writeas/writeas-cli/executable"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -39,5 +40,5 @@ func EditPostCmd(fname string) *exec.Cmd {
|
||||
}
|
||||
|
||||
func MessageRetryCompose(fname string) string {
|
||||
return fmt.Sprintf("To retry this post, run:\n cat %s | writeas", fname)
|
||||
return fmt.Sprintf("To retry this post, run:\n cat %s | %s", fname, executable.Name())
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"github.com/writeas/writeas-cli/executable"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -22,5 +24,5 @@ func EditPostCmd(fname string) *exec.Cmd {
|
||||
}
|
||||
|
||||
func MessageRetryCompose(fname string) string {
|
||||
return fmt.Sprintf("To retry this post, run:\n type %s | writeas.exe", fname)
|
||||
return fmt.Sprintf("To retry this post, run:\n type %s | %s", fname, executable.Name())
|
||||
}
|
||||
|
13
executable/executable.go
Normal file
13
executable/executable.go
Normal file
@ -0,0 +1,13 @@
|
||||
// Package executable holds utility functions that assist both CLI executables,
|
||||
// writeas and wf.
|
||||
package executable
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
func Name() string {
|
||||
n := os.Args[0]
|
||||
return path.Base(n)
|
||||
}
|
Loading…
Reference in New Issue
Block a user