# HG changeset patch # User Mikael Berthe # Date 1494109564 -7200 # Node ID bca27c55be9fa47001840a251e6945256b2c0a01 # Parent b40bc3a8b5727ca897b34e1b5bc664af49a7741e Add default visibility setting diff -r b40bc3a8b572 -r bca27c55be9f README.md --- a/README.md Sat May 06 20:26:12 2017 +0200 +++ b/README.md Sun May 07 00:26:04 2017 +0200 @@ -48,6 +48,8 @@ If you only provide the Mastodon instance, it will generate a configuration file with an application ID/secret for this instance and you will have to add the user credentials. +Note that every variable from the configration file can also be set with an environment variable (e.g. `export MADONCTL_INSTANCE='https://mamot.fr'`). + ### Usage The complete list of commands is available in the online help (`madonctl help`, `madonctl command --help`...) @@ -66,6 +68,9 @@ % madonctl toot --visibility private --spoiler CW "The answer was 42" % madonctl post --file image.jpg Selfie # Send a media file ``` +Note: The default toot visibility can be set in the configuration file with +the `default_visibility` setting or with the environment variable (example +`export MADONCTL_DEFAULT_VISIBILITY=unlisted`). Send (text) file content as new message: ``` diff -r b40bc3a8b572 -r bca27c55be9f cmd/status.go --- a/cmd/status.go Sat May 06 20:26:12 2017 +0200 +++ b/cmd/status.go Sun May 07 00:26:04 2017 +0200 @@ -166,7 +166,10 @@ madonctl status toot --sensitive --file image.jpg Image madonctl status post --media-ids ID1,ID2,ID3 Image madonctl status toot --text-file message.txt - echo "Hello from #madonctl" | madonctl status toot --stdin`, + echo "Hello from #madonctl" | madonctl status toot --stdin + +The default visibility can be set in the configuration file with the option +'default_visibility' (or with an environmnent variable).`, RunE: func(cmd *cobra.Command, args []string) error { return statusSubcommandRunE(cmd.Name(), args) }, diff -r b40bc3a8b572 -r bca27c55be9f cmd/toot.go --- a/cmd/toot.go Sat May 06 20:26:12 2017 +0200 +++ b/cmd/toot.go Sun May 07 00:26:04 2017 +0200 @@ -8,6 +8,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/spf13/viper" "github.com/McKael/madon" ) @@ -42,7 +43,10 @@ madonctl status post --media-ids ID1,ID2 "Here are the photos" madonctl post --sensitive --file image.jpg Image madonctl toot --text-file message.txt - echo "Hello from #madonctl" | madonctl toot --visibility unlisted --stdin`, + echo "Hello from #madonctl" | madonctl toot --visibility unlisted --stdin + +The default visibility can be set in the configuration file with the option +'default_visibility' (or with an environmnent variable).`, RunE: func(cmd *cobra.Command, args []string) error { if err := madonInit(true); err != nil { return err @@ -54,11 +58,18 @@ func toot(tootText string) (*madon.Status, error) { opt := statusOpts + // Get default visibility from configuration + if opt.visibility == "" { + if v := viper.GetString("default_visibility"); v != "" { + opt.visibility = v + } + } + switch opt.visibility { case "", "direct", "private", "unlisted", "public": // OK default: - return nil, errors.New("invalid visibility argument value") + return nil, errors.Errorf("invalid visibility argument value '%s'", opt.visibility) } if opt.inReplyToID < 0 {