Skip to content

Commit 106f7a4

Browse files
authored
Merge pull request #13 from dmiedema/ModuloFileSettings
[WIP] Modulo file settings
2 parents 4e2176e + 7b90d2c commit 106f7a4

File tree

18 files changed

+250
-14
lines changed

18 files changed

+250
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Build generated
44
build/
5+
.build/
56
DerivedData/
67

78
## Various settings

Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# By default export all variables
2+
export
3+
4+
.PHONY: install release debug build setup clean
5+
6+
PROJECT ?= 'modulo.xcodeproj'
7+
SCHEME ?= 'modulo'
8+
SYMROOT ?= 'build'
9+
CONFIGURATION ?= 'Debug'
10+
11+
# Build for debugging
12+
debug: build
13+
14+
# Install `modulo` to `/usr/local/bin`
15+
install: release
16+
cp $(SYMROOT)/Release/modulo /usr/local/bin/
17+
18+
# Build for release
19+
release: CONFIGURATION = 'Release'
20+
release: build
21+
22+
23+
# Build modulo
24+
# This will build the `PROJECT` with the given `SCHEME`
25+
# to the `SYMROOT` with a given `CONFIGURATION`
26+
# Defaults for these values are
27+
# `PROJECT` - `modulo.xcodeproj`
28+
# `SCHEME` - `modulo`
29+
# `SYMROOM` - `build`
30+
# `CONFIGURATION` - `Debug`
31+
#
32+
# These can be overwritten via ENV variables.
33+
build: setup
34+
xcodebuild -project $(PROJECT) -scheme $(SCHEME) -configuration $(CONFIGURATION) SYMROOT=$(SYMROOT)
35+
36+
# Setup the environment
37+
setup:
38+
mkdir -p $(SYMROOT)
39+
40+
clean:
41+
rm -rfv $(SYMROOT)

ModuloKit/Commands/AddCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ open class AddCommand: NSObject, Command {
3131
}
3232
open var failOnUnrecognizedOptions: Bool { return true }
3333

34-
open var verbose: Bool = false
34+
open var verbose: Bool = State.instance.options.verboseOutput
3535
open var quiet: Bool = false
3636

3737
open func configureOptions() {
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
//
2+
// DefaultsCommand.swift
3+
// ModuloKit
4+
//
5+
// Created by Daniel Miedema on 9/25/18.
6+
// Copyright © 2018 TheHolyGrail. All rights reserved.
7+
//
8+
9+
import Foundation
10+
#if NOFRAMEWORKS
11+
#else
12+
import ELCLI
13+
#endif
14+
15+
open class DefaultsCommand: NSObject, Command {
16+
// Internal Properties
17+
fileprivate var toggleVerbose: Bool = false
18+
fileprivate var verboseValue: String? = nil
19+
fileprivate var moduleFolderPath: String? = nil
20+
fileprivate var setValue: Bool = false
21+
22+
// Protocol Conformance
23+
public var name: String { return "defaults" }
24+
25+
public var shortHelpDescription: String {
26+
return "Set default arguments/configuration properties for this repository"
27+
}
28+
29+
public var longHelpDescription: String {
30+
return """
31+
Set default argument values for all commands to be run.
32+
This will make changes to the `.modulo` file reflecting the
33+
new defaults that have been set
34+
"""
35+
}
36+
37+
public var failOnUnrecognizedOptions: Bool { return true }
38+
39+
public var verbose: Bool = State.instance.options.verboseOutput
40+
public var quiet: Bool = false
41+
42+
public func execute(_ otherParams: Array<String>?) -> Int {
43+
guard var spec = ModuleSpec.workingSpec() else {
44+
exit(ErrorCode.notInitialized)
45+
return ErrorCode.notInitialized.rawValue
46+
}
47+
48+
if setValue {
49+
if toggleVerbose {
50+
let newValue: Bool
51+
switch verboseValue {
52+
case "true":
53+
newValue = true
54+
case "false":
55+
newValue = false
56+
default:
57+
writeln(.stderr, "\(verboseValue ?? "") is not `true` or `false`. Interpretting as `false`.")
58+
newValue = false
59+
}
60+
61+
spec.options.verboseOutput = newValue
62+
State.instance.options.verboseOutput = newValue
63+
}
64+
if let moduleFolderPath = moduleFolderPath,
65+
!moduleFolderPath.isEmpty {
66+
spec.options.depdencyInstallationPath = moduleFolderPath
67+
State.instance.options.depdencyInstallationPath = moduleFolderPath
68+
}
69+
spec.save()
70+
} else {
71+
if toggleVerbose {
72+
writeln(.stdout, "VerboseOutput - \(spec.options.verboseOutput)")
73+
}
74+
if moduleFolderPath != nil {
75+
writeln(.stdout, "depdencyInstallationPath - \(spec.options.depdencyInstallationPath)")
76+
}
77+
78+
}
79+
80+
return ErrorCode.success.rawValue
81+
}
82+
83+
open func configureOptions() {
84+
addOption(["--set"], usage: "set a new value for the given") { (option, value) in
85+
self.setValue = true
86+
}
87+
88+
addOptionValue(["--verboseOutput"],
89+
usage: "specify `verbose` for all commands that are run",
90+
valueSignature: "<[true|false}>") { (option, value) in
91+
self.toggleVerbose = true
92+
self.verboseValue = value
93+
}
94+
95+
addOptionValue(["--moduleFolder"],
96+
usage: "specify the desired dependency path",
97+
valueSignature: "<path>") { (option, value) in
98+
self.moduleFolderPath = value ?? ""
99+
}
100+
}
101+
}

ModuloKit/Commands/InitCommand.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ open class InitCommand: NSObject, Command {
2525
}
2626
open var failOnUnrecognizedOptions: Bool { return true }
2727

28-
open var verbose: Bool = false
28+
open var verbose: Bool = State.instance.options.verboseOutput
2929
open var quiet: Bool = false
3030

3131
open func configureOptions() {
@@ -53,7 +53,7 @@ open class InitCommand: NSObject, Command {
5353
}
5454

5555
let specPath = workingPath.appendPathComponent(specFilename)
56-
let spec = ModuleSpec(name: FileManager.directoryName(), module: isModule, sourcePath: nil, dependencies: [], path: specPath)
56+
let spec = ModuleSpec(name: FileManager.directoryName(), module: isModule, sourcePath: nil, dependencies: [], options: OptionsSpec(), path: specPath)
5757
let success = spec.save()
5858

5959
if !success {

ModuloKit/Commands/MapCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ open class MapCommand: NSObject, Command {
2121
}
2222
open var failOnUnrecognizedOptions: Bool { return true }
2323

24-
open var verbose: Bool = false
24+
open var verbose: Bool = State.instance.options.verboseOutput
2525
open var quiet: Bool = false
2626

2727
fileprivate var simple = false

ModuloKit/Commands/RemoveCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ open class RemoveCommand: NSObject, Command {
2121
}
2222
open var failOnUnrecognizedOptions: Bool { return true }
2323

24-
open var verbose: Bool = false
24+
open var verbose: Bool = State.instance.options.verboseOutput
2525
open var quiet: Bool = false
2626

2727
open func configureOptions() {

ModuloKit/Commands/SetCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ open class SetCommand: NSObject, Command {
2121
}
2222
open var failOnUnrecognizedOptions: Bool { return true }
2323

24-
open var verbose: Bool = false
24+
open var verbose: Bool = State.instance.options.verboseOutput
2525
open var quiet: Bool = false
2626

2727
// subcommands

ModuloKit/Commands/StatusCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ open class StatusCommand: NSObject, Command {
2323
open var failOnUnrecognizedOptions: Bool { return true }
2424
open var ignoreMain: Bool = false
2525

26-
open var verbose: Bool = false
26+
open var verbose: Bool = State.instance.options.verboseOutput
2727
open var quiet: Bool = false
2828

2929
open func configureOptions() {

ModuloKit/Commands/UpdateCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ open class UpdateCommand: NSObject, Command {
2929
}
3030
open var failOnUnrecognizedOptions: Bool { return true }
3131

32-
open var verbose: Bool = false
32+
open var verbose: Bool = State.instance.options.verboseOutput
3333
open var quiet: Bool = false
3434

3535
open func configureOptions() {

0 commit comments

Comments
 (0)