Skip to content
2 changes: 1 addition & 1 deletion Stellar/Sources/CLI/Commands/CreateActionCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct CreateActionCommand: ParsableCommand {
@Option(name: .shortAndLong, help: "The name of the Action. Must have the 'Action' suffix.")
private var name: String

@Option(name: .shortAndLong, help: "The path in which to create the action. Optional, defaults to .stellar/Actions")
@Option(name: .shortAndLong, help: "The path in which to create the action. Optional, defaults to .stellar/Actions.")
private var outputPath: String?

@Option(name: .shortAndLong, help: "The path to the templates. Optional, defaults to the templates shipped with the release.")
Expand Down
1 change: 1 addition & 0 deletions Stellar/Sources/Core/Constants/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Constants.swift

import Foundation

struct Constants {
Expand Down
12 changes: 0 additions & 12 deletions Stellar/Sources/Core/FileManaging/FileManager+FileManaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,6 @@ extension FileManager: FileManaging {
enumerator(at: location, includingPropertiesForKeys: [], options: [])
}

public func copyFile(from location: URL, to destination: URL) throws {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BundleService is now using the existing implementation of copy(at... on line 41 in this file.
It is OK as the code in BundleService checks for the existence of the target folder and deletes it if existing.

guard fileExists(atPath: location.path) else {
return
}

if fileExists(atPath: destination.path) {
try removeItem(atPath: destination.path)
}

try copyItem(atPath: location.path, toPath: destination.path)
}

/// Create a temporary directory and evaluates a closure with the directory path as an argument.
///
///
Expand Down
1 change: 0 additions & 1 deletion Stellar/Sources/Core/FileManaging/FileManaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ public protocol FileManaging {
func verifyFolderExisting(at location: URL) throws
func enumerator(at location: URL) -> FileManager.DirectoryEnumerator?
func withTemporaryDirectory<Result>(path: String?, prefix: String, autoRemove: Bool, _ closure: (URL) throws -> Result) throws -> Result
func copyFile(from location: URL, to destination: URL) throws
}
1 change: 0 additions & 1 deletion Stellar/Sources/Core/Logger/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Foundation
public class Logger {

public init() {}


public func log(_ message: String) {
print("[\(Constants.stellar)] \(message)")
Expand Down
16 changes: 9 additions & 7 deletions Stellar/Sources/Core/Providers/CommandResolver.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// CommandResolver.swift

import Foundation

public final class CommandResolver {
Expand All @@ -6,7 +8,7 @@ public final class CommandResolver {

private let urlManager = URLManager()
private let versionResolver: VersionResolving
private let bundleUpdater: UpdaterService
private let updateService: UpdateService

private let logger = Logger()

Expand All @@ -18,7 +20,7 @@ public final class CommandResolver {

public init(releaseProvider: ReleaseProviding = ReleaseProvider(),
versionResolver: VersionResolving = VersionResolver()) {
self.bundleUpdater = .init(releaseProvider: releaseProvider)
self.updateService = .init(releaseProvider: releaseProvider)
self.versionResolver = versionResolver
}

Expand Down Expand Up @@ -79,7 +81,7 @@ public final class CommandResolver {
}

// Check if version is available locally, install if necessary.
guard let versionURL = try bundleUpdater.update(version) else {
guard let versionURL = try updateService.update(to: version) else {
exiter(1)
return
}
Expand All @@ -94,20 +96,20 @@ public final class CommandResolver {
private func runCommandsUsingLatestInstalledVersion(args: [String]) throws {
var targetVersion: String!

if let highgestVersion = try bundleUpdater.cliService.latestInstalledVersion() {
if let highgestVersion = try updateService.cliService.latestInstalledVersion() {
// Get the latest version installed locally.
targetVersion = highgestVersion.version.description
} else {
// Nothing installed, we try to update all.
_ = try bundleUpdater.update()
guard let highgestVersion = try bundleUpdater.cliService.latestInstalledVersion() else {
_ = try updateService.update()
guard let highgestVersion = try updateService.cliService.latestInstalledVersion() else {
throw Errors.versionNotFound
}

targetVersion = highgestVersion.version.description
}

guard let targetVersionPath = try bundleUpdater.versionResolver.pathForVersion(targetVersion)?.path else {
guard let targetVersionPath = try updateService.versionResolver.pathForVersion(targetVersion)?.path else {
logger.log("Failed to use version \(targetVersion ?? ""). Aborting the process...")
exiter(1)
return
Expand Down
2 changes: 2 additions & 0 deletions Stellar/Sources/Core/Providers/ReleaseProvider.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ReleaseProvider.swift

import Foundation

public protocol ReleaseProviding {
Expand Down
2 changes: 2 additions & 0 deletions Stellar/Sources/Core/Providers/Support/LocalVersion.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// LocalVersion.swift

import Foundation

/// Represent an installed version of the stellar environment.
Expand Down
2 changes: 2 additions & 0 deletions Stellar/Sources/Core/Providers/Support/RemoteRelease.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// RemoteRelease.swift

import Foundation

public struct RemoteRelease: Comparable, CustomStringConvertible {
Expand Down
2 changes: 2 additions & 0 deletions Stellar/Sources/Core/Providers/VersionResolver.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// VersionResolver.swift

import Foundation

public protocol VersionResolving {
Expand Down
5 changes: 4 additions & 1 deletion Stellar/Sources/Core/Services/BundleService.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// BundleService.swift

import Foundation

// MARK: - BundleService
Expand Down Expand Up @@ -59,7 +61,8 @@ public final class BundleService {
if fileManager.folderExists(at: binFolderURL) {
try fileManager.deleteFolder(at: binFolderURL) // remove any other bundled version
}
try fileManager.copyFile(from: versionPath, to: binFolderURL)

try fileManager.copyFile(at: versionPath, to: binFolderURL)

logger.log("Stellar \(targetVersion) bundled successfully at \(binFolderURL.path)")
}
Expand Down
2 changes: 2 additions & 0 deletions Stellar/Sources/Core/Services/CLIService.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// CLIService.swift

import Foundation
import AppKit

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// EnvService.swift

import Foundation
import AppKit

// MARK: - ENVServiceProtocol
// MARK: - EnvServiceProtocol

protocol ENVServiceProtocol {
protocol EnvServiceProtocol {

/// Install StellarEnv tool.
///
Expand All @@ -12,10 +14,10 @@ protocol ENVServiceProtocol {

}

// MARK: - ENVService
// MARK: - EnvService

/// `ENVService` is used to update the `stellarenv` tool.
public final class ENVService: ENVServiceProtocol {
/// `EnvService` is used to update the `stellarenv` tool.
public final class EnvService: EnvServiceProtocol {

// MARK: - Public Properties

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
// UpdateService.swift

import Foundation

// MARK: - UpdaterServiceProtocol
// MARK: - UpdateServiceProtocol

protocol UpdaterServiceProtocol: AnyObject {
protocol UpdateServiceProtocol: AnyObject {

/// Download and update both CLI and Env tools to the specified version.
///
/// - Parameter version: version to update. if `nil` a check with the latest remote release is made.
@discardableResult
func update(_ version: String?) throws -> URL?
func update(to version: String?) throws -> URL?

}

// MARK: - UpdaterService
// MARK: - UpdateService

public final class UpdaterService: UpdaterServiceProtocol {
public final class UpdateService: UpdateServiceProtocol {

// MARK: - Public Properties

public let cliService: CLIService
public let envService: ENVService
public let envService: EnvService

private let logger = Logger()

Expand All @@ -42,7 +44,7 @@ public final class UpdaterService: UpdaterServiceProtocol {
// MARK: - Public Functions

@discardableResult
public func update(_ version: String? = nil) throws -> URL? {
public func update(to version: String? = nil) throws -> URL? {
if let version {
return try update(toVersion: version)
} else {
Expand Down Expand Up @@ -75,7 +77,7 @@ public final class UpdaterService: UpdaterServiceProtocol {
}

let versionURL = try updateCLIToLatestVersion(release.version)
try updateENVToLatestVersion(release.version)
try updateEnvToLatestVersion(release.version)

logger.log("Stellar version \(release.description) installed")

Expand All @@ -98,7 +100,7 @@ public final class UpdaterService: UpdaterServiceProtocol {
return try cliService.install(version: version.description)
}

private func updateENVToLatestVersion(_ version: SemVer) throws {
private func updateEnvToLatestVersion(_ version: SemVer) throws {
logger.log("Updating stellarenv")
try envService.install(version: version.description)
}
Expand Down
7 changes: 1 addition & 6 deletions Stellar/Sources/Core/Utils/FatalError.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
//
// File.swift
//
//
// Created by daniele on 11/03/23.
//
// FatalError.swift

import Foundation

Expand Down
2 changes: 2 additions & 0 deletions Stellar/Sources/Core/Utils/Foundation+Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Foundation+Extensions.swift

import Foundation

// MARK: - String
Expand Down
2 changes: 2 additions & 0 deletions Stellar/Sources/Core/Utils/Glob.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Glob.swift

import Foundation

/// Finds files on the file system using pattern matching.
Expand Down
2 changes: 2 additions & 0 deletions Stellar/Sources/Core/Utils/SemVer.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SemVer.swift

import Foundation

/// Represents a version conforming to [Semantic Versioning 2.0.0](http://semver.org).
Expand Down
2 changes: 2 additions & 0 deletions Stellar/Sources/Core/Utils/Shell.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Shell.swift

import Foundation
import TSCBasic

Expand Down
2 changes: 2 additions & 0 deletions Stellar/Sources/Core/Utils/URLSession+Extension.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// URLSession+Extension.swift

import Foundation

extension URLSession {
Expand Down
6 changes: 5 additions & 1 deletion Stellar/Sources/Env/Commands/BundleCommand.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// BundleCommand.swift

import ArgumentParser
import Foundation
import StellarCore
Expand All @@ -7,10 +9,12 @@ struct BundleCommand: ParsableCommand {
static var configuration: CommandConfiguration {
CommandConfiguration(
commandName: "bundle",
abstract: "Bundles the version specified in the .stellar-version file into the .stellar-bin directory"
abstract: "Bundle the version specified in the .stellar-version file into the .stellar-bin directory."
)
}

// MARK: - Functions

func run() throws {
try BundleService().run()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// InstallCommand.swift

import ArgumentParser
import Foundation
import StellarCore

/// The following tool is used to install a version of stellar into the system.
public struct CLIInstallCommand: ParsableCommand {
struct InstallCommand: ParsableCommand {

public static var configuration: CommandConfiguration {
static var configuration: CommandConfiguration {
CommandConfiguration(
commandName: "install",
abstract: "Install a version of stellar."
Expand All @@ -15,20 +16,14 @@ public struct CLIInstallCommand: ParsableCommand {
// MARK: - Options

@Argument(help: "The version of stellar to be installed.")
public var version: String?
var version: String?

@Flag(help: "When no version is specified, set this tag to install latest stable/pre-release.")
public var preRelease: Bool = false

// MARK: - Initialization

public init() {

}
var preRelease: Bool = false

// MARK: - Public Functions
// MARK: - Functions

public func run() throws {
func run() throws {
try CLIService().install(version: version, preRelease: preRelease)
}

Expand Down
35 changes: 35 additions & 0 deletions Stellar/Sources/Env/Commands/InstalledCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// InstalledCommand.swift

import ArgumentParser
import Foundation
import StellarCore

struct InstalledCommand: ParsableCommand {

static let configuration = CommandConfiguration(
commandName: "installed",
abstract: "Prints the local versions."
)

// MARK: - Functions

func run() throws {
try enumerateInstalledVersions()
}

// MARK: - Private Functions

/// Enumerate the list of the installed versions of stellar.
private func enumerateInstalledVersions() throws {
let versions = try VersionResolver().installedVersions()
guard !versions.isEmpty else {
Logger().log("No versions of stellar are installed yet")
return
}

Logger().log("Installed versions are:")
let output = versions.reversed().map { "- \($0)" }.joined(separator: "\n")
Logger().log("\n\(output)")
}

}
Loading