~ianmjones/snippetpixie

de53e4c615595fbe404d6830e00ebebf9877f011 — Ian M. Jones 4 hours ago b8d5c17 trunk
Let legacy --export CLI flag accept positional argument for file name
2 files changed, 12 insertions(+), 0 deletions(-)

M cmd/snippetpixie/config.go
M cmd/snippetpixie/config_test.go
M cmd/snippetpixie/config.go => cmd/snippetpixie/config.go +11 -0
@@ 94,6 94,17 @@ func (c *config) initDefaultFlagset(appName string, args []string, out io.Writer
		c.Cmd = "Status"

	case flags.Changed("export"):
		exportFile = strings.TrimSpace(exportFile)

		// Override Flag.NoOptDefVal requiring "=" for flag not to use default.
		if exportFile == exportDefaultFile && flags.NArg() == 1 {
			exportFile = strings.TrimSpace(flags.Arg(0))
		}

		if len(exportFile) == 0 {
			exportFile = exportDefaultFile
		}

		c.Cmd = "Export"
		c.Args = map[string]interface{}{
			"filename": exportFile,

M cmd/snippetpixie/config_test.go => cmd/snippetpixie/config_test.go +1 -0
@@ 59,6 59,7 @@ func TestConfig_Init(t *testing.T) {
		{[]string{"snippetpixie", "export", "--filename=wibble.json", "--version=101"}, "Export", map[string]interface{}{"filename": "wibble.json", "version": 101}, ""},
		{[]string{"snippetpixie", "export", "-f=wibble.json", "-v=101"}, "Export", map[string]interface{}{"filename": "wibble.json", "version": 101}, ""},
		{[]string{"snippetpixie", "--export"}, "Export", map[string]interface{}{"filename": exportDefaultFile}, ""},
		{[]string{"snippetpixie", "--export", "wibble.json"}, "Export", map[string]interface{}{"filename": "wibble.json"}, ""},
		{[]string{"snippetpixie", "--export=wibble.json"}, "Export", map[string]interface{}{"filename": "wibble.json"}, ""},
		{[]string{"snippetpixie", "-e=wibble.json"}, "Export", map[string]interface{}{"filename": "wibble.json"}, ""},
		{[]string{"snippetpixie", "help", "add"}, "", nil, "Usage: snippetpixie add abbreviation body"},