feat: Add shorthand flag
This commit is contained in:
parent
f7792fef66
commit
e705b91d8e
2 changed files with 12 additions and 5 deletions
14
main.go
14
main.go
|
|
@ -10,9 +10,15 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var ignoreExt bool
|
||||
|
||||
func init() {
|
||||
const ignoreExtDesc = "Ignore file extensions when renaming"
|
||||
flag.BoolVar(&ignoreExt, "ignore-ext", false, ignoreExtDesc)
|
||||
flag.BoolVar(&ignoreExt, "i", false, ignoreExtDesc+" (shorthand)")
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Add flag for ignoring extensions
|
||||
ignoreExt := flag.Bool("ignore-ext", false, "Ignore file extensions when renaming")
|
||||
flag.Parse()
|
||||
|
||||
// Check command line arguments
|
||||
|
|
@ -62,7 +68,7 @@ func main() {
|
|||
fileNames = append(fileNames, fileName)
|
||||
|
||||
// If ignoring extensions, split filename and extension
|
||||
if *ignoreExt {
|
||||
if ignoreExt {
|
||||
baseName := fileName
|
||||
ext := ""
|
||||
|
||||
|
|
@ -141,7 +147,7 @@ func main() {
|
|||
for i, oldName := range fileNames {
|
||||
// Re-add extension if we were ignoring it
|
||||
newName := newFileNames[i]
|
||||
if *ignoreExt {
|
||||
if ignoreExt {
|
||||
newName = newName + fileExts[i]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ renamedit /path/to/directory
|
|||
|
||||
Ignore file extensions (useful for batch renaming while preserving extensions):
|
||||
```bash
|
||||
renamedit -ignore-ext /path/to/directory
|
||||
renamedit -i /path/to/directory
|
||||
renamedit --ignore-ext /path/to/directory
|
||||
```
|
||||
|
||||
## How It Works
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue