Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Reject surplus positional arguments instead of silently discarding them, using Commander 0.3.0 for strict command validation.

- Keep numeric reminder indexes stable across reordered EventKit fetches by breaking equal due-date/title sort ties with the reminder ID.
- Reject impossible ISO dates, malformed offsets, and trailing date text; select explicit field order so day-first inputs cannot silently become another date while retaining unambiguous legacy spellings.
- Handle CRLF as a complete newline when removing managed URL notes and exporting CSV, preventing stale URL mirrors, split CSV records, and missed formula prefixes.
Expand Down
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let package = Package(
.executable(name: "remindctl", targets: ["remindctl"]),
],
dependencies: [
.package(url: "https://github.com/steipete/Commander.git", from: "0.2.0"),
.package(url: "https://github.com/steipete/Commander.git", from: "0.3.0"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Indexes such as `1` come from the default reminder listing. Most commands also a
| `remindctl status` | Show Reminders permission status |
| `remindctl authorize` | Request Reminders permission when macOS allows it |

Run `remindctl <command> --help` for the full option list.
Run `remindctl <command> --help` for the full option list. Unexpected extra arguments are rejected; quote multi-word titles and list names.

## Showing Reminders

Expand Down
12 changes: 2 additions & 10 deletions Sources/remindctl/CommandRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ struct CommandRouter {
}

func run(argv: [String]) async -> Int32 {
var argv = normalizeArguments(argv)
argv = applyAliases(argv)
var argv = applyAliases(argv)
let controlArguments = argv.prefix { $0 != "--" }

if controlArguments.contains("--version") || controlArguments.contains("-V") {
Expand All @@ -62,7 +61,7 @@ struct CommandRouter {
argv = rewriteImplicitShow(argv)

do {
let invocation = try program.resolve(argv: argv)
let invocation = try program.resolve(arguments: [rootName] + argv.dropFirst())
guard let commandName = invocation.path.last,
let spec = specs.first(where: { $0.name == commandName })
else {
Expand Down Expand Up @@ -91,13 +90,6 @@ struct CommandRouter {
}
}

private func normalizeArguments(_ argv: [String]) -> [String] {
guard !argv.isEmpty else { return argv }
var copy = argv
copy[0] = rootName
return copy
}

private func applyAliases(_ argv: [String]) -> [String] {
guard argv.count >= 2 else { return argv }
var copy = argv
Expand Down
2 changes: 1 addition & 1 deletion Sources/remindctl/Commands/CompleteCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum CompleteCommand {
signature: CommandSignatures.withRuntimeFlags(
CommandSignature(
arguments: [
.make(label: "ids", help: "Indexes or ID prefixes", isOptional: true)
.make(label: "ids", help: "Indexes or ID prefixes", isOptional: true, parsing: .remaining)
],
flags: [
.make(label: "dryRun", names: [.short("n"), .long("dry-run")], help: "Preview without changes")
Expand Down
2 changes: 1 addition & 1 deletion Sources/remindctl/Commands/DeleteCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum DeleteCommand {
signature: CommandSignatures.withRuntimeFlags(
CommandSignature(
arguments: [
.make(label: "ids", help: "Indexes or ID prefixes", isOptional: true)
.make(label: "ids", help: "Indexes or ID prefixes", isOptional: true, parsing: .remaining)
],
flags: [
.make(label: "dryRun", names: [.short("n"), .long("dry-run")], help: "Preview without changes"),
Expand Down
2 changes: 1 addition & 1 deletion Sources/remindctl/Commands/ListCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum ListCommand {
signature: CommandSignatures.withRuntimeFlags(
CommandSignature(
arguments: [
.make(label: "name", help: "List name(s)", isOptional: true)
.make(label: "name", help: "List name(s)", isOptional: true, parsing: .remaining)
],
options: [
.make(
Expand Down
23 changes: 23 additions & 0 deletions Tests/remindctlTests/CommandRouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ import Testing
@testable import remindctl

struct CommandRouterTests {
@Test("Surplus command arguments are rejected")
func surplusArguments() async {
let code = await CommandRouter().run(argv: ["remindctl", "completion", "bash", "unexpected"])
#expect(code == 1)
}

@Test("Bulk commands preserve all positional values", arguments: ["list", "complete", "delete"])
func bulkArguments(_ command: String) throws {
let invocation = try CommandRouter().program.resolve(arguments: [
"remindctl", command, "First", "Second", "--plain",
])
#expect(invocation.parsedValues.positional == ["First", "Second"])
#expect(invocation.parsedValues.flags.contains("plainOutput"))
}

@Test(
"Single-target commands reject extra positionals", arguments: ["add", "edit", "search", "info", "link", "open"])
func singleTargetArguments(_ command: String) {
#expect(throws: (any Error).self) {
try CommandRouter().program.resolve(arguments: ["remindctl", command, "First", "Second"])
}
}

@Test("A renamed executable resolves the canonical command")
func renamedExecutable() async {
let code = await CommandRouter().run(argv: ["/tmp/custom-reminders", "completion", "bash"])
Expand Down
2 changes: 1 addition & 1 deletion Tests/remindctlTests/ListActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Testing

struct ListActionTests {
private func action(_ arguments: [String]) throws -> ListCommand.Action {
let values = try CommandRouter().program.resolve(argv: ["remindctl", "list"] + arguments).parsedValues
let values = try CommandRouter().program.resolve(arguments: ["remindctl", "list"] + arguments).parsedValues
return try ListCommand.action(
names: values.positional,
listID: values.option("listID"),
Expand Down
Loading