Skip to content

Commit

Permalink
feat: improve CLI output (#26)
Browse files Browse the repository at this point in the history
* better logging

* chore: improve code coverage for add subcommand

* feat: add preinstall script for installer

* chore: update functional tests to reflect setup changes
  • Loading branch information
willswire authored Oct 1, 2024
1 parent d251736 commit 1c4a5f2
Show file tree
Hide file tree
Showing 11 changed files with 456 additions and 419 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
--version "${{ github.ref }}" \
--install-location "/" \
--sign="Developer ID Installer: William Walker (QSQY64SHJ5)" \
--scripts "scripts/" \
cosmic.pkg
- name: Notarize package
Expand Down Expand Up @@ -102,7 +103,7 @@ jobs:
draft: false
prerelease: false

- name: Upload binary
- name: Upload pkg installer
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,10 @@ jobs:
sudo cp ./build/Cosmic.xcarchive/Products/usr/local/bin/cosmic /usr/local/bin/cosmic
cosmic --help
- name: Run setup subcommand
run: |
cosmic setup --verbose
echo "$HOME/Packages" >> $GITHUB_PATH
- name: Run add subcommand
run: |
cosmic add k9s --verbose
- name: Run installed package
run: |
k9s version --short
~/.cosmic/k9s version --short
1 change: 0 additions & 1 deletion Cosmic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
Common/Utils.swift,
Cosmic.swift,
Subcommands/Add.swift,
Subcommands/Setup.swift,
);
target = 6BD783982C98FBFF009EEB33 /* CosmicTests */;
};
Expand Down
6 changes: 0 additions & 6 deletions Cosmic.xcodeproj/xcshareddata/xcschemes/Cosmic.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@
ReferencedContainer = "container:Cosmic.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "setup --verbose"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<EnvironmentVariables>
<EnvironmentVariable
key = "PATH"
Expand Down
90 changes: 45 additions & 45 deletions Cosmic/Common/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ let sharedSession: URLSession = {
return URLSession(configuration: configuration)
}()

/// Shared, default File Manager
let fileManager: FileManager = .default

/// Extension providing utility properties to `Digest`.
extension Digest {
/// Array of bytes representing the digest.
var bytes: [UInt8] { Array(makeIterator()) }

/// Data representation of the digest.
var data: Data { Data(bytes) }

/// Hexadecimal string representation of the digest.
var hexStr: String { bytes.map { String(format: "%02X", $0) }.joined() }
}
Expand Down Expand Up @@ -97,48 +97,48 @@ func unarchive(from sourcePath: String, for name: String, strip: Bool) throws ->
/// - name: Name of the package being extracted.
/// - Returns: URL of the extracted files' directory.
/// - Throws: `ExtractionError` in case of issues during the extraction.
func unzip(from sourcePath: String, for name: String) throws -> URL {
let fileManager = FileManager.default

// Check if the source file exists
guard fileManager.fileExists(atPath: sourcePath) else {
throw ExtractionError.fileDoesNotExist("File does not exist at \(sourcePath)")
}

// Set up the temporary directory path for extraction
let destinationURL = fileManager.temporaryDirectory.appendingPathComponent(name)

// Create the destination directory
do {
try fileManager.createDirectory(
at: destinationURL, withIntermediateDirectories: true, attributes: nil)
} catch {
throw ExtractionError.failedToCreateDirectory(
"Failed to create destination directory: \(error.localizedDescription)")
}

// Configure the `unzip` process for extraction
let process = Process()
process.executableURL = URL(fileURLWithPath: "/usr/bin/unzip")
process.arguments = [sourcePath, "-d", destinationURL.path]
process.standardOutput = nil
process.standardError = nil

// Execute the `unzip` process and handle its result
do {
try process.run()
process.waitUntilExit()

guard process.terminationStatus == 0 else {
throw ExtractionError.extractionFailed(process.terminationStatus)
}

return destinationURL
} catch {
throw ExtractionError.extractionProcessFailed(
"Failed to run extraction process: \(error.localizedDescription)")
}
}
//func unzip(from sourcePath: String, for name: String) throws -> URL {
// let fileManager = FileManager.default
//
// // Check if the source file exists
// guard fileManager.fileExists(atPath: sourcePath) else {
// throw ExtractionError.fileDoesNotExist("File does not exist at \(sourcePath)")
// }
//
// // Set up the temporary directory path for extraction
// let destinationURL = fileManager.temporaryDirectory.appendingPathComponent(name)
//
// // Create the destination directory
// do {
// try fileManager.createDirectory(
// at: destinationURL, withIntermediateDirectories: true, attributes: nil)
// } catch {
// throw ExtractionError.failedToCreateDirectory(
// "Failed to create destination directory: \(error.localizedDescription)")
// }
//
// // Configure the `unzip` process for extraction
// let process = Process()
// process.executableURL = URL(fileURLWithPath: "/usr/bin/unzip")
// process.arguments = [sourcePath, "-d", destinationURL.path]
// process.standardOutput = nil
// process.standardError = nil
//
// // Execute the `unzip` process and handle its result
// do {
// try process.run()
// process.waitUntilExit()
//
// guard process.terminationStatus == 0 else {
// throw ExtractionError.extractionFailed(process.terminationStatus)
// }
//
// return destinationURL
// } catch {
// throw ExtractionError.extractionProcessFailed(
// "Failed to run extraction process: \(error.localizedDescription)")
// }
//}

func setExecutablePermission(for fileURL: URL) throws {
let attributes = try FileManager.default.attributesOfItem(atPath: fileURL.path)
Expand Down
5 changes: 2 additions & 3 deletions Cosmic/Cosmic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import PklSwift
@main struct Cosmic: AsyncParsableCommand {
static var configuration = CommandConfiguration(
abstract: "A package manager for macOS.",
subcommands: [Setup.self, Add.self])
subcommands: [Add.self])

struct Options: ParsableArguments {
@Flag(name: [.long, .customShort("v")]) var verbose: Bool = false
@Flag(name: [.long, .customShort("f")]) var force: Bool = false
@Flag var verbose: Bool = false
}
}
Loading

0 comments on commit 1c4a5f2

Please sign in to comment.