-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from dmiedema/ModuloFileSettings
[WIP] Modulo file settings
- Loading branch information
Showing
18 changed files
with
250 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
## Build generated | ||
build/ | ||
.build/ | ||
DerivedData/ | ||
|
||
## Various settings | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# By default export all variables | ||
export | ||
|
||
.PHONY: install release debug build setup clean | ||
|
||
PROJECT ?= 'modulo.xcodeproj' | ||
SCHEME ?= 'modulo' | ||
SYMROOT ?= 'build' | ||
CONFIGURATION ?= 'Debug' | ||
|
||
# Build for debugging | ||
debug: build | ||
|
||
# Install `modulo` to `/usr/local/bin` | ||
install: release | ||
cp $(SYMROOT)/Release/modulo /usr/local/bin/ | ||
|
||
# Build for release | ||
release: CONFIGURATION = 'Release' | ||
release: build | ||
|
||
|
||
# Build modulo | ||
# This will build the `PROJECT` with the given `SCHEME` | ||
# to the `SYMROOT` with a given `CONFIGURATION` | ||
# Defaults for these values are | ||
# `PROJECT` - `modulo.xcodeproj` | ||
# `SCHEME` - `modulo` | ||
# `SYMROOM` - `build` | ||
# `CONFIGURATION` - `Debug` | ||
# | ||
# These can be overwritten via ENV variables. | ||
build: setup | ||
xcodebuild -project $(PROJECT) -scheme $(SCHEME) -configuration $(CONFIGURATION) SYMROOT=$(SYMROOT) | ||
|
||
# Setup the environment | ||
setup: | ||
mkdir -p $(SYMROOT) | ||
|
||
clean: | ||
rm -rfv $(SYMROOT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// | ||
// DefaultsCommand.swift | ||
// ModuloKit | ||
// | ||
// Created by Daniel Miedema on 9/25/18. | ||
// Copyright © 2018 TheHolyGrail. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
#if NOFRAMEWORKS | ||
#else | ||
import ELCLI | ||
#endif | ||
|
||
open class DefaultsCommand: NSObject, Command { | ||
// Internal Properties | ||
fileprivate var toggleVerbose: Bool = false | ||
fileprivate var verboseValue: String? = nil | ||
fileprivate var moduleFolderPath: String? = nil | ||
fileprivate var setValue: Bool = false | ||
|
||
// Protocol Conformance | ||
public var name: String { return "defaults" } | ||
|
||
public var shortHelpDescription: String { | ||
return "Set default arguments/configuration properties for this repository" | ||
} | ||
|
||
public var longHelpDescription: String { | ||
return """ | ||
Set default argument values for all commands to be run. | ||
This will make changes to the `.modulo` file reflecting the | ||
new defaults that have been set | ||
""" | ||
} | ||
|
||
public var failOnUnrecognizedOptions: Bool { return true } | ||
|
||
public var verbose: Bool = State.instance.options.verboseOutput | ||
public var quiet: Bool = false | ||
|
||
public func execute(_ otherParams: Array<String>?) -> Int { | ||
guard var spec = ModuleSpec.workingSpec() else { | ||
exit(ErrorCode.notInitialized) | ||
return ErrorCode.notInitialized.rawValue | ||
} | ||
|
||
if setValue { | ||
if toggleVerbose { | ||
let newValue: Bool | ||
switch verboseValue { | ||
case "true": | ||
newValue = true | ||
case "false": | ||
newValue = false | ||
default: | ||
writeln(.stderr, "\(verboseValue ?? "") is not `true` or `false`. Interpretting as `false`.") | ||
newValue = false | ||
} | ||
|
||
spec.options.verboseOutput = newValue | ||
State.instance.options.verboseOutput = newValue | ||
} | ||
if let moduleFolderPath = moduleFolderPath, | ||
!moduleFolderPath.isEmpty { | ||
spec.options.depdencyInstallationPath = moduleFolderPath | ||
State.instance.options.depdencyInstallationPath = moduleFolderPath | ||
} | ||
spec.save() | ||
} else { | ||
if toggleVerbose { | ||
writeln(.stdout, "VerboseOutput - \(spec.options.verboseOutput)") | ||
} | ||
if moduleFolderPath != nil { | ||
writeln(.stdout, "depdencyInstallationPath - \(spec.options.depdencyInstallationPath)") | ||
} | ||
|
||
} | ||
|
||
return ErrorCode.success.rawValue | ||
} | ||
|
||
open func configureOptions() { | ||
addOption(["--set"], usage: "set a new value for the given") { (option, value) in | ||
self.setValue = true | ||
} | ||
|
||
addOptionValue(["--verboseOutput"], | ||
usage: "specify `verbose` for all commands that are run", | ||
valueSignature: "<[true|false}>") { (option, value) in | ||
self.toggleVerbose = true | ||
self.verboseValue = value | ||
} | ||
|
||
addOptionValue(["--moduleFolder"], | ||
usage: "specify the desired dependency path", | ||
valueSignature: "<path>") { (option, value) in | ||
self.moduleFolderPath = value ?? "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// OptionsSpec.swift | ||
// ModuloKit | ||
// | ||
// Created by Daniel Miedema on 9/25/18. | ||
// Copyright © 2018 TheHolyGrail. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
#if NOFRAMEWORKS | ||
#else | ||
import ELCodable | ||
#endif | ||
|
||
public struct OptionsSpec { | ||
/// Should we have `verbose` on all commands | ||
var verboseOutput: Bool = false | ||
/// Path to store our 'modules'/dependencies in | ||
var depdencyInstallationPath: String = "modules" | ||
} | ||
|
||
extension OptionsSpec: ELDecodable { | ||
public static func decode(_ json: JSON?) throws -> OptionsSpec { | ||
return try OptionsSpec( | ||
verboseOutput: json ==> "verboseOutput", | ||
depdencyInstallationPath: json ==> "depdencyInstallationPath" | ||
) | ||
} | ||
} | ||
|
||
extension OptionsSpec: ELEncodable { | ||
public func encode() throws -> JSON { | ||
return try encodeToJSON([ | ||
"verboseOutput" <== verboseOutput, | ||
"depdencyInstallationPath" <== depdencyInstallationPath | ||
]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// TestDefaults.swift | ||
// ModuloKitTests | ||
// | ||
// Created by Daniel Miedema on 9/25/18. | ||
// Copyright © 2018 TheHolyGrail. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
import ELCLI | ||
import ELFoundation | ||
@testable import ModuloKit | ||
|
||
class TestDefaults: XCTestCase { | ||
let modulo = Modulo() | ||
|
||
} |
Oops, something went wrong.