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

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenTiigi committed Feb 17, 2020
2 parents c2809ed + 9d804c8 commit 5bf36b6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ If you wish to specify a name for the Playground run:
$ swiftplayground new MyAwesomePlayground
```

Generate a Playground from your clipboard content via:

```bash
$ swiftplayground new --clipboard
```

To generate a Playground with a SwiftUI template run:

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


## Arguments

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

### new command

| Long parameter | Short parameter | Description
| ----------- | ----------- | -------------- |
| `--view` | `-v` | Generate a Playground with a SwiftUI template |
| `--url` | `-u` | Generate a Playground with contents from a URL |
| `--clipboard` | `-c` | Generate a Playground from the current Clipboard content |
| `--silent` | `-s` | Generate a Playground without opening the Playgrounds application |
| `--url` | `-u` | Generate a Playground with contents from a URL |
| `--view` | `-v` | Generate a Playground with a SwiftUI template |

## Contributing
Contributions are very welcome 🙌 🤓
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ extension SwiftPlaygroundsCLI {
@Flag("-v", "--view", description: "Generate a Playground with a SwiftUI template")
var viewContent: Bool

/// Bool value if Clipboard Content should be used
@Flag("-c", "--clipboard", description: "Generate a Playground from the current Clipboard content")
var clipboardContent: Bool

/// The remote URL Content Key
@Key("-u", "--url", description: "Generate a Playground with contents from a URL")
var remoteContentURL: String?
Expand Down Expand Up @@ -65,6 +69,9 @@ extension SwiftPlaygroundsCLI.NewCommand: Command {
if self.viewContent {
// Set View Content
content = .view
} else if self.clipboardContent {
// Use Clipboard Content
content = .clipboard
} else if let remoteContentURL = self.remoteContentURL {
// If a remote content URL is available use remote
content = .remote(url: remoteContentURL)
Expand Down
17 changes: 11 additions & 6 deletions Sources/SwiftPlaygroundsKit/PlaygroundBook+Content.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Sven Tiigi on 12.02.20.
//

import Cocoa
import Foundation

// MARK: - Content
Expand All @@ -17,6 +18,8 @@ public extension PlaygroundBook {
case `default`
/// View Content
case view
/// Clipboard Content
case clipboard
/// Remove Content from URL
case remote(url: String)
}
Expand All @@ -36,12 +39,6 @@ extension PlaygroundBook.Content {
print("Hello Developer")
"""
case .remote(let url):
if let code = self.loadCode(from: url) {
return code
} else {
return "// Unable to load content from: \(url)"
}
case .view:
return """
import PlaygroundSupport
Expand All @@ -59,6 +56,14 @@ extension PlaygroundBook.Content {
let view = MyView()
PlaygroundPage.current.setLiveView(view)
"""
case .clipboard:
return NSPasteboard.general.string(forType: .string) ?? .init()
case .remote(let url):
if let code = self.loadCode(from: url) {
return code
} else {
return "// Unable to load content from: \(url)"
}
}
}

Expand Down

0 comments on commit 5bf36b6

Please sign in to comment.