Merge pull request #30 from Undo1/master

Allow password prompt instead of command line argument
This commit is contained in:
Andrew Naylor 2016-06-08 23:00:08 +01:00
commit cf23a1bd01
2 changed files with 16 additions and 2 deletions

View file

@ -56,6 +56,13 @@ To install all pending updates run `mas upgrade`.
To sign into the Mac App Store for the first time run `mas signin`. To sign into the Mac App Store for the first time run `mas signin`.
$ mas signin mas@example.com
==> Signing in to Apple ID: mas@example.com
Password:
You can also embed your password in the command.
$ mas signin mas@example.com "ZdkM4f$gzF;gX3ABXNLf8KcCt.x.np" $ mas signin mas@example.com "ZdkM4f$gzF;gX3ABXNLf8KcCt.x.np"
==> Signing in to Apple ID: mas@example.com ==> Signing in to Apple ID: mas@example.com

View file

@ -19,7 +19,14 @@ struct SignInCommand: CommandType {
do { do {
print("==> Signing in to Apple ID: \(options.username)") print("==> Signing in to Apple ID: \(options.username)")
try ISStoreAccount.signIn(username: options.username, password: options.password)
var password = options.password
if password == ""
{
password = String.fromCString(getpass("Password: "))!
}
try ISStoreAccount.signIn(username: options.username, password: password)
} catch let error as NSError { } catch let error as NSError {
return .Failure(MASError(code: .SignInError, sourceError: error)) return .Failure(MASError(code: .SignInError, sourceError: error))
} }
@ -35,6 +42,6 @@ struct SignInOptions: OptionsType {
static func evaluate(m: CommandMode) -> Result<SignInOptions, CommandantError<MASError>> { static func evaluate(m: CommandMode) -> Result<SignInOptions, CommandantError<MASError>> {
return curry(SignInOptions.init) return curry(SignInOptions.init)
<*> m <| Argument(usage: "Apple ID") <*> m <| Argument(usage: "Apple ID")
<*> m <| Argument(usage: "Password") <*> m <| Argument(defaultValue: "", usage: "Password")
} }
} }