Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 5bf36b6

Browse files
committed
Merge branch 'develop'
2 parents c2809ed + 9d804c8 commit 5bf36b6

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ If you wish to specify a name for the Playground run:
7878
$ swiftplayground new MyAwesomePlayground
7979
```
8080

81+
Generate a Playground from your clipboard content via:
82+
83+
```bash
84+
$ swiftplayground new --clipboard
85+
```
86+
8187
To generate a Playground with a SwiftUI template run:
8288

8389
```bash
@@ -98,16 +104,18 @@ $ swiftplayground new --url https://gist.github.com/SvenTiigi/7eae5e55edd9be4121
98104
<img src="https://raw.githubusercontent.com/SvenTiigi/SwiftPlaygroundsCLI/gh-pages/readme-assets/RemoteOptionDemo.png" alt="Remote Option Demo">
99105
</p>
100106

101-
102107
## Arguments
103108

104109
A list of the available arguments that are supported by the SwiftPlaygroundsCLI.
105110

111+
### new command
112+
106113
| Long parameter | Short parameter | Description
107114
| ----------- | ----------- | -------------- |
108-
| `--view` | `-v` | Generate a Playground with a SwiftUI template |
109-
| `--url` | `-u` | Generate a Playground with contents from a URL |
115+
| `--clipboard` | `-c` | Generate a Playground from the current Clipboard content |
110116
| `--silent` | `-s` | Generate a Playground without opening the Playgrounds application |
117+
| `--url` | `-u` | Generate a Playground with contents from a URL |
118+
| `--view` | `-v` | Generate a Playground with a SwiftUI template |
111119

112120
## Contributing
113121
Contributions are very welcome 🙌 🤓

Sources/SwiftPlaygroundsCLI/SwiftPlaygroundsCLI+NewCommand.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ extension SwiftPlaygroundsCLI {
2424
@Flag("-v", "--view", description: "Generate a Playground with a SwiftUI template")
2525
var viewContent: Bool
2626

27+
/// Bool value if Clipboard Content should be used
28+
@Flag("-c", "--clipboard", description: "Generate a Playground from the current Clipboard content")
29+
var clipboardContent: Bool
30+
2731
/// The remote URL Content Key
2832
@Key("-u", "--url", description: "Generate a Playground with contents from a URL")
2933
var remoteContentURL: String?
@@ -65,6 +69,9 @@ extension SwiftPlaygroundsCLI.NewCommand: Command {
6569
if self.viewContent {
6670
// Set View Content
6771
content = .view
72+
} else if self.clipboardContent {
73+
// Use Clipboard Content
74+
content = .clipboard
6875
} else if let remoteContentURL = self.remoteContentURL {
6976
// If a remote content URL is available use remote
7077
content = .remote(url: remoteContentURL)

Sources/SwiftPlaygroundsKit/PlaygroundBook+Content.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by Sven Tiigi on 12.02.20.
66
//
77

8+
import Cocoa
89
import Foundation
910

1011
// MARK: - Content
@@ -17,6 +18,8 @@ public extension PlaygroundBook {
1718
case `default`
1819
/// View Content
1920
case view
21+
/// Clipboard Content
22+
case clipboard
2023
/// Remove Content from URL
2124
case remote(url: String)
2225
}
@@ -36,12 +39,6 @@ extension PlaygroundBook.Content {
3639
3740
print("Hello Developer")
3841
"""
39-
case .remote(let url):
40-
if let code = self.loadCode(from: url) {
41-
return code
42-
} else {
43-
return "// Unable to load content from: \(url)"
44-
}
4542
case .view:
4643
return """
4744
import PlaygroundSupport
@@ -59,6 +56,14 @@ extension PlaygroundBook.Content {
5956
let view = MyView()
6057
PlaygroundPage.current.setLiveView(view)
6158
"""
59+
case .clipboard:
60+
return NSPasteboard.general.string(forType: .string) ?? .init()
61+
case .remote(let url):
62+
if let code = self.loadCode(from: url) {
63+
return code
64+
} else {
65+
return "// Unable to load content from: \(url)"
66+
}
6267
}
6368
}
6469

0 commit comments

Comments
 (0)