-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the new arguments parser framework (#14)
* Make use of the new argument parser * Add configuration description * Fix tests and add extra options for arguments * Add verbose logging * Updated the readme * Fix Danger error for trailing comma
- Loading branch information
Showing
12 changed files
with
1,531 additions
and
1,878 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,7 +1,3 @@ | ||
import PoesCore | ||
|
||
do { | ||
try Poes.run() | ||
} catch { | ||
print("Pushing failed: \(error)") | ||
} | ||
Poes.main() |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// Send.swift | ||
// PoesCore | ||
// | ||
// Created by Antoine van der Lee on 08/02/2020. | ||
// Copyright © 2020 AvdLee. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import ArgumentParser | ||
|
||
struct Send: ParsableCommand, ShellInjectable { | ||
|
||
public static let configuration = CommandConfiguration(abstract: "Send a push notification to an app installed on the iOS Simulator") | ||
|
||
@Argument(help: "The bundle identifier of the app to push to") | ||
private var bundleIdentifier: String | ||
|
||
@Option(name: .shortAndLong, default: "Default Title", help: "The title of the Push notification") | ||
private var title: String | ||
|
||
@Option(name: .shortAndLong, default: "Default Body", help: "The body of the Push notification") | ||
private var body: String | ||
|
||
@Option(name: .shortAndLong, help: "The number to display in a badge on your app’s icon") | ||
private var badge: Int? | ||
|
||
@Flag(name: .shortAndLong, help: "Adds the mutable-content key to the payload") | ||
private var isMutable: Bool | ||
|
||
@Flag(name: .long, help: "Show extra logging for debugging purposes") | ||
private var verbose: Bool | ||
|
||
func run() throws { | ||
Log.isVerbose = verbose | ||
|
||
let payload = Payload(title: title, body: body, isMutable: isMutable, badge: badge) | ||
let jsonData = try JSONEncoder().encode(payload) | ||
|
||
if Log.isVerbose, let object = try? JSONSerialization.jsonObject(with: jsonData, options: []), let jsonString = String(data: try! JSONSerialization.data(withJSONObject: object, options: .prettyPrinted), encoding: .utf8) { | ||
Log.debug("Generated payload:\n\n\(jsonString)\n") | ||
} | ||
|
||
let url = Foundation.URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent("payload.json") | ||
FileManager.default.createFile(atPath: url.path, contents: jsonData, attributes: nil) | ||
|
||
Log.message("Sending push notification...") | ||
Self.shell.execute(.push(bundleIdentifier: bundleIdentifier, payloadPath: url.path)) | ||
Log.message("Push notification sent successfully") | ||
} | ||
} |
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