Skip to content

Commit

Permalink
Add pasteboard commands
Browse files Browse the repository at this point in the history
  • Loading branch information
NickAb committed Jun 2, 2019
1 parent 34dec73 commit ac7e625
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ios-utils

Command-line utils for iOS simulators. Use in automated tests to list or delete media assets from a simulator.
Command-line utils for iOS simulators. Use in automated tests to list or delete media assets and/or pasteboard items from a simulator.


## Quickstart
Expand Down Expand Up @@ -29,6 +29,9 @@ Subcommands:
media <subcommand>
list List media assets
delete Delete all media assets
pasteboard <subcommand>
list List string and url pasteboard items
delete Clear pasteboard
help Print usage
```
Expand Down
16 changes: 12 additions & 4 deletions ios-utils.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
F7AB4C41229C0B33007DBA95 /* HelpCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7AB4C40229C0B33007DBA95 /* HelpCommand.swift */; };
F7AB4C43229C0C19007DBA95 /* CliError.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7AB4C42229C0C19007DBA95 /* CliError.swift */; };
F7AB4C45229C0FF0007DBA95 /* Media.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7AB4C44229C0FF0007DBA95 /* Media.swift */; };
F7AB4C47229C0FF8007DBA95 /* MediaCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7AB4C46229C0FF8007DBA95 /* MediaCommand.swift */; };
F7AB4C47229C0FF8007DBA95 /* PasteboardCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7AB4C46229C0FF8007DBA95 /* PasteboardCommand.swift */; };
F7EAC9D1229C2C950000973F /* Pasteboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7EAC9D0229C2C950000973F /* Pasteboard.swift */; };
F7EAC9D3229C2EFF0000973F /* MediaCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7EAC9D2229C2EFF0000973F /* MediaCommand.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -31,8 +33,10 @@
F7AB4C40229C0B33007DBA95 /* HelpCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelpCommand.swift; sourceTree = "<group>"; };
F7AB4C42229C0C19007DBA95 /* CliError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CliError.swift; sourceTree = "<group>"; };
F7AB4C44229C0FF0007DBA95 /* Media.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Media.swift; sourceTree = "<group>"; };
F7AB4C46229C0FF8007DBA95 /* MediaCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MediaCommand.swift; sourceTree = "<group>"; };
F7AB4C46229C0FF8007DBA95 /* PasteboardCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasteboardCommand.swift; sourceTree = "<group>"; };
F7AB4C48229C1020007DBA95 /* ios-utils.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "ios-utils.entitlements"; sourceTree = "<group>"; };
F7EAC9D0229C2C950000973F /* Pasteboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pasteboard.swift; sourceTree = "<group>"; };
F7EAC9D2229C2EFF0000973F /* MediaCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MediaCommand.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -80,7 +84,8 @@
F7AB4C31229BFBFB007DBA95 /* Commands */ = {
isa = PBXGroup;
children = (
F7AB4C46229C0FF8007DBA95 /* MediaCommand.swift */,
F7EAC9D2229C2EFF0000973F /* MediaCommand.swift */,
F7AB4C46229C0FF8007DBA95 /* PasteboardCommand.swift */,
F7AB4C40229C0B33007DBA95 /* HelpCommand.swift */,
);
path = Commands;
Expand All @@ -90,6 +95,7 @@
isa = PBXGroup;
children = (
F7AB4C44229C0FF0007DBA95 /* Media.swift */,
F7EAC9D0229C2C950000973F /* Pasteboard.swift */,
);
path = Core;
sourceTree = "<group>";
Expand Down Expand Up @@ -180,11 +186,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F7EAC9D3229C2EFF0000973F /* MediaCommand.swift in Sources */,
F7AB4C41229C0B33007DBA95 /* HelpCommand.swift in Sources */,
F7AB4C3C229BFBFC007DBA95 /* CommandGroup.swift in Sources */,
F7AB4C45229C0FF0007DBA95 /* Media.swift in Sources */,
F7AB4C3D229BFBFC007DBA95 /* Cli.swift in Sources */,
F7AB4C47229C0FF8007DBA95 /* MediaCommand.swift in Sources */,
F7AB4C47229C0FF8007DBA95 /* PasteboardCommand.swift in Sources */,
F7EAC9D1229C2C950000973F /* Pasteboard.swift in Sources */,
F7AB4C28229BEDF0007DBA95 /* main.swift in Sources */,
F7AB4C43229C0C19007DBA95 /* CliError.swift in Sources */,
F7AB4C3B229BFBFC007DBA95 /* Command.swift in Sources */,
Expand Down
6 changes: 6 additions & 0 deletions ios-utils/Cli/Cli.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ final class Cli {
DeleteMediaCommand(),
]
),
CommandGroup(command: "pasteboard", shortDescription: "", subCommands:
[
ListPasteboardCommand(),
DeletePasteboardCommand(),
]
),
HelpCommand()
]
)
Expand Down
30 changes: 30 additions & 0 deletions ios-utils/Commands/PasteboardCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Copyright © 2019 Nikolai Abalov and contributors
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//

import Foundation

final class ListPasteboardCommand: Command {
var command: String = "list"

var shortDescription: String = "List string and url pasteboard items"

func run(with arguments: [String]) throws -> [Encodable] {
return Pasteboard().list()
}
}

final class DeletePasteboardCommand: Command {
var command: String = "delete"

var shortDescription: String = "Clear pasteboard"

func run(with arguments: [String]) throws -> [Encodable] {
Pasteboard().delete()

return []
}
}
36 changes: 36 additions & 0 deletions ios-utils/Core/Pasteboard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Copyright © 2019 Nikolai Abalov and contributors
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//

import Foundation
import UIKit

struct PasteboardItem: Codable {
let type: String
let value: String
}

class Pasteboard {
func list() -> [PasteboardItem] {
var items = [PasteboardItem]()

let pasteboard = UIPasteboard.general

for string in pasteboard.strings ?? [] {
items.append(PasteboardItem(type: "string", value: string))
}

for url in pasteboard.urls ?? [] {
items.append(PasteboardItem(type: "url", value: url.absoluteString))
}

return items
}

func delete() -> Void {
UIPasteboard.general.items = []
}
}

0 comments on commit ac7e625

Please sign in to comment.