Commit f280f4008d
Verified · cmc
Layout: unified · split
Sources/keycask/Commands/Add.swift +3
| @@ -28,6 +28,9 @@ struct PasswordOptions: ParsableArguments { | ||
| 28 | 28 | if generate, words != nil { |
| 29 | 29 | throw ValidationError("--generate and --words are mutually exclusive") |
| 30 | 30 | } |
| 31 | if words != nil, length != nil { | |
| 32 | throw ValidationError("--length and --words are mutually exclusive") | |
| 33 | } | |
| 31 | 34 | if let length, length < 1 { throw ValidationError("--length must be at least 1") } |
| 32 | 35 | if let words, words < 1 { throw ValidationError("--words must be at least 1") } |
| 33 | 36 | if length != nil, !generate, words == nil { |
Tests/KeycaskCLITests/AddShowTests.swift +13
| @@ -101,6 +101,19 @@ import Testing | ||
| 101 | 101 | #expect(r.stderr.contains("keycask init")) |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | @Test func lengthWithWordsIsUsageError() throws { | |
| 105 | let cli = try CLI.initialized() | |
| 106 | let r = try cli.run(["add", "a", "--words", "4", "--length", "30"]) | |
| 107 | #expect(r.status == 2) | |
| 108 | } | |
| 109 | ||
| 110 | @Test func addWithoutPasswordSourceIsUsageError() throws { | |
| 111 | let cli = try CLI.initialized() | |
| 112 | let r = try cli.run(["add", "x"], stdin: "") | |
| 113 | #expect(r.status == 2) | |
| 114 | #expect(r.stderr.contains("no password")) | |
| 115 | } | |
| 116 | ||
| 104 | 117 | @Test func corruptVaultIsFailure() throws { |
| 105 | 118 | let cli = try CLI.initialized() |
| 106 | 119 | try Data("{}".utf8).write(to: cli.vault) |