-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9426345
commit 78d14a3
Showing
3 changed files
with
91 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "swift-argument-parser", | ||
"repositoryURL": "https://github.com/apple/swift-argument-parser.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "6b2aa2748a7881eebb9f84fb10c01293e15b52ca", | ||
"version": "0.5.0" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,68 @@ | ||
let generator = PasswordGenerator() | ||
let password = generator.generate( | ||
type: .separated(8, 4, .space), | ||
characters: [.numbers, .lowercase, .uppercase] | ||
) | ||
import ArgumentParser | ||
import Foundation | ||
|
||
print("Generated password:") | ||
print(password) | ||
struct PassGen: ParsableCommand { | ||
static let configuration = CommandConfiguration( | ||
abstract: "Generates a Random Password", | ||
version: "1.0.0", | ||
subcommands: [Normal.self, Separated.self] | ||
) | ||
} | ||
|
||
PassGen.main() | ||
|
||
extension PassGen { | ||
struct Normal: ParsableCommand { | ||
static let configuration = CommandConfiguration(abstract: "Generates a string password", version: "1.0.0") | ||
|
||
@Argument(help: "Password length") var length: Int = 16 | ||
|
||
func validate() throws { | ||
guard length >= 4 else { | ||
throw ValidationError("Password length must be at least 4.") | ||
} | ||
} | ||
|
||
mutating func run() throws { | ||
|
||
let generator = PasswordGenerator() | ||
let password = generator.generate( | ||
type: .normal(length), | ||
characters: [.numbers, .lowercase, .uppercase] | ||
) | ||
|
||
print("Generated password:") | ||
print(password) | ||
} | ||
} | ||
|
||
struct Separated: ParsableCommand { | ||
static let configuration = CommandConfiguration(abstract: "Generates a password with separators", version: "1.0.0") | ||
|
||
@Argument(help: "Word length") var wordLength: Int = 8 | ||
@Argument(help: "Word count") var wordCount: Int = 4 | ||
|
||
func validate() throws { | ||
guard wordLength >= 3 else { | ||
throw ValidationError("Word length must be at least 3.") | ||
} | ||
|
||
guard wordCount >= 2 else { | ||
throw ValidationError("Word count must be at least 2.") | ||
} | ||
} | ||
|
||
mutating func run() throws { | ||
|
||
let generator = PasswordGenerator() | ||
let password = generator.generate( | ||
type: .separated(wordLength, wordCount, .space), | ||
characters: [.numbers, .lowercase, .uppercase] | ||
) | ||
|
||
print("Generated password:") | ||
print(password) | ||
|
||
} | ||
} | ||
} |