diff --git a/cli/cli.go b/cli/cli.go index 71fabd4..f58f3c5 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -31,7 +31,7 @@ import ( // Basic utility info const ( APP = "path" - VER = "1.0.3" + VER = "1.1.0" DESC = "Dead simple tool for working with paths" ) @@ -70,6 +70,7 @@ const ( CMD_ADD_SUFFIX = "add-suffix" CMD_DEL_SUFFIX = "del-suffix" CMD_EXCLUDE = "exclude" + CMD_STRIP_EXT = "strip-ext" CMD_IS_ABS = "is-abs" CMD_IS_LOCAL = "is-local" @@ -200,6 +201,8 @@ func process(args options.Arguments) (error, bool) { return cmdDelSuffix(cmdArgs) case CMD_EXCLUDE: return cmdExclude(cmdArgs) + case CMD_STRIP_EXT: + return cmdStripExt(cmdArgs) case CMD_IS_ABS: return cmdIsAbs(cmdArgs) @@ -268,6 +271,7 @@ func genUsage() *usage.Info { info.AddCommand(CMD_ADD_SUFFIX, "Add the substring at the end", "suffix", "?path") info.AddCommand(CMD_DEL_SUFFIX, "Remove the substring at the end", "suffix", "?path") info.AddCommand(CMD_EXCLUDE, "Exclude part of the string", "substr", "?path") + info.AddCommand(CMD_STRIP_EXT, "Remove file extension", "?path") info.AddCommand(CMD_IS_ABS, "Check if given path is absolute", "?path") info.AddCommand(CMD_IS_LOCAL, "Check if given path is local", "?path") diff --git a/cli/commands.go b/cli/commands.go index d59714c..08da849 100644 --- a/cli/commands.go +++ b/cli/commands.go @@ -435,6 +435,35 @@ func cmdExclude(args options.Arguments) (error, bool) { return nil, true } +// cmdStripExt is handler for "strip-ext" command +func cmdStripExt(args options.Arguments) (error, bool) { + var result []string + + input, err := getInputData(args) + + if err != nil { + return err, false + } + + for _, item := range input { + ext := path.Ext(item) + + if ext != "" { + result = append(result, strings.TrimSuffix(item, ext)) + } else { + result = append(result, item) + } + } + + if len(result) == 0 { + return err, false + } + + fmt.Println(strings.Join(result, getSeparator())) + + return nil, true +} + // cmdIsAbs is handler for "is-abs" command func cmdIsAbs(args options.Arguments) (error, bool) { input, err := getInputData(args)