Skip to content

Commit 037c46a

Browse files
author
Pierre Houston
committed
change selent to quiet, expand readme example
1 parent 78b1f9c commit 037c46a

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

README.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ It exports a struct `RenameOptions` conforming to the `ParsableArguments` protoc
66

77
`runRename()` takes a function argument with a inout `name` parameter, you provide this function which changes `name` as desired. This is called for every file passed on the command line, with the file extension omitted if any, and the file gets renamed accordingly.
88

9-
`RenameOptions` defines arguments `verbose`, `silent`, `dry-run`.
9+
`RenameOptions` defines arguments `verbose`, `quiet`, `dry-run`.
1010

11-
It works well with `swift-sh`, also the `Regex` package at http://github.com/sharplet/Regex which it extends with a convenience function for case insensitive matching.
11+
It works well with `swift-sh`, also the `Regex` package at http://github.com/sharplet/Regex which `RenameCommand` extends with an overload of its `replace` functions added to `String` allowing you to more conveniently specify case insensitive.
1212

13-
For example:
13+
For example, this simple Swift "script" source file "myrename" (no ".swift" extension needed):
1414

1515
```swift
1616
#!/usr/bin/swift sh
@@ -25,12 +25,41 @@ struct RenameMoviesCommand: ParsableCommand {
2525
func run() throws {
2626
try options.runRename() { name in
2727
name.replaceAll(matching: #"\."#, with: " ")
28-
name.replaceFirst(matchingIgnoringCase: " 720p", with: "")
29-
name.replaceFirst(matchingIgnoringCase: " 1080p", with: "")
28+
name.replaceFirst(matching: " 720p", .ignoreCase, with: "")
29+
name.replaceFirst(matching: " 1080p", .ignoreCase, with: "")
3030
name.replaceFirst(matching: " ([0-9][0-9][0-9][0-9])$", with: " ($1)")
3131
}
3232
}
3333
}
3434

3535
RenameMoviesCommand.main()
3636
```
37+
38+
after `chmod a+x myrename` and moving it to somewhere in the shell command path like `/usr/local/bin`, can then do:
39+
40+
```bash
41+
$ myrename --help
42+
OVERVIEW: Renames my ripped movies from their old name format to how I prefer them now.
43+
44+
USAGE: myrename [<files> ...] [--quiet] [--verbose] [--dry-run]
45+
46+
ARGUMENTS:
47+
<files> Files to rename.
48+
49+
OPTIONS:
50+
-q, --quiet Suppress non-error output.
51+
-v, --verbose Verbose output (overrides "--quiet").
52+
--dry-run Show what would be renamed (no files are changed).
53+
-h, --help Show help information.
54+
55+
$ myrename ~/Movies/Die.Hard.1988.720p.mp4
56+
'Die.Hard.1988.720p.mp4' renamed to 'Die Hard (1988).mp4'
57+
```
58+
59+
## See Also
60+
61+
- [ArgumentParser](https://github.com/apple/swift-argument-parser)
62+
- [swift-sh](https://github.com/mxcl/swift-sh)
63+
- [Regex](http://github.com/sharplet/Regex)
64+
- [Files](https://github.com/JohnSundell/Files)
65+

Sources/RenameCommand/RenameCommand.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ public struct RenameOptions: ParsableArguments {
1414
@Argument(help: "Files to rename.")
1515
public var files: [String]
1616

17-
@Flag(name: .shortAndLong, help: "Silent output.")
18-
public var silent: Bool
17+
@Flag(name: .shortAndLong, help: "Suppress non-error output.")
18+
public var quiet: Bool
1919

20-
@Flag(name: .shortAndLong, help: "Verbose output (overrides \"--silent\").")
20+
@Flag(name: .shortAndLong, help: "Verbose output (overrides \"--quiet\").")
2121
public var verbose: Bool
2222

23-
@Flag(name: .customLong("dry-run"), help: "Don't perform rename just output the result.")
23+
@Flag(name: .customLong("dry-run"), help: "Show what would be renamed (no files are changed).")
2424
public var dryRun: Bool
2525

2626
public init() { } // swift complains if this not present
@@ -57,11 +57,11 @@ public struct RenameOptions: ParsableArguments {
5757
}
5858

5959
if verbose { print("\(String(repeating: " ", count: "\(i)".count)) renamed to \(replacementName)") }
60-
else if !silent { print("'\(fileName)' renamed to '\(replacementName)'") }
60+
else if !quiet { print("'\(fileName)' renamed to '\(replacementName)'") }
6161
nrenamed += 1
6262
} else {
6363
if verbose { print("\(String(repeating: " ", count: "\(i)".count)) not renamed") }
64-
else if !silent && dryRun { print("'\(fileName)' not renamed") }
64+
else if !quiet && dryRun { print("'\(fileName)' not renamed") }
6565
}
6666
}
6767
return nrenamed

0 commit comments

Comments
 (0)