From c2da3fd919708c7bfdee5c48e7297af391c4118f Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Tue, 17 May 2022 17:40:21 +0300 Subject: [PATCH] Support "tart --version" (#81) * Support "tart --version" * Move CI.swift patcher into a separate script Otherwise it doesn't work in GoReleaser. --- .ci/set-version.sh | 3 +++ .goreleaser.yml | 1 + Sources/tart/CI/CI.swift | 13 +++++++++++++ Sources/tart/Commands/Run.swift | 15 +++++++++++++++ Sources/tart/Root.swift | 1 + 5 files changed, 33 insertions(+) create mode 100755 .ci/set-version.sh create mode 100644 Sources/tart/CI/CI.swift diff --git a/.ci/set-version.sh b/.ci/set-version.sh new file mode 100755 index 0000000..9301fdf --- /dev/null +++ b/.ci/set-version.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +cat Sources/tart/CI/CI.swift | envsubst | tee Sources/tart/CI/CI.swift diff --git a/.goreleaser.yml b/.goreleaser.yml index ff6b185..f5c2b0c 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -11,6 +11,7 @@ builds: before: hooks: + - .ci/set-version.sh - swift build -c release --product tart - codesign --sign - --entitlements Resources/tart.entitlements --force .build/arm64-apple-macosx/release/tart diff --git a/Sources/tart/CI/CI.swift b/Sources/tart/CI/CI.swift new file mode 100644 index 0000000..53abb0a --- /dev/null +++ b/Sources/tart/CI/CI.swift @@ -0,0 +1,13 @@ +struct CI { + private static let rawVersion = "${CIRRUS_TAG}" + + static var version: String { + rawVersion.expanded() ? rawVersion : "SNAPSHOT" + } +} + +private extension String { + func expanded() -> Bool { + !isEmpty && !starts(with: "$") + } +} diff --git a/Sources/tart/Commands/Run.swift b/Sources/tart/Commands/Run.swift index 8cc7b9c..c440b23 100644 --- a/Sources/tart/Commands/Run.swift +++ b/Sources/tart/Commands/Run.swift @@ -62,6 +62,8 @@ struct Run: AsyncParsableCommand { CommandGroup(replacing: .textEditing, addition: {}) CommandGroup(replacing: .undoRedo, addition: {}) CommandGroup(replacing: .windowSize, addition: {}) + // Replace some standard menu options + CommandGroup(replacing: .appInfo) { AboutTart() } } } } @@ -70,6 +72,19 @@ struct Run: AsyncParsableCommand { } } +struct AboutTart: View { + var body: some View { + Button("About Tart") { + NSApplication.shared.orderFrontStandardAboutPanel(options: [ + NSApplication.AboutPanelOptionKey.applicationIcon: NSApplication.shared.applicationIconImage as Any, + NSApplication.AboutPanelOptionKey.applicationName: "Tart", + NSApplication.AboutPanelOptionKey.applicationVersion: CI.version, + NSApplication.AboutPanelOptionKey.credits: try! NSAttributedString(markdown: "https://github.com/cirruslabs/tart"), + ]) + } + } +} + struct VMView: NSViewRepresentable { typealias NSViewType = VZVirtualMachineView diff --git a/Sources/tart/Root.swift b/Sources/tart/Root.swift index ec0d706..b04e2a9 100644 --- a/Sources/tart/Root.swift +++ b/Sources/tart/Root.swift @@ -5,6 +5,7 @@ import Foundation struct Root: AsyncParsableCommand { static var configuration = CommandConfiguration( commandName: "tart", + version: CI.version, subcommands: [ Create.self, Clone.self,