Skip to content

Feature/base directory#3

Open
wstrunk wants to merge 3 commits into
crd1:masterfrom
wstrunk:feature/base-directory
Open

Feature/base directory#3
wstrunk wants to merge 3 commits into
crd1:masterfrom
wstrunk:feature/base-directory

Conversation

@wstrunk

@wstrunk wstrunk commented Feb 2, 2020

Copy link
Copy Markdown

No description provided.

return
}
val file = File(input.first())
var scriptfilePath = input.first()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The following lines of code have been duplicated several times. I would like to suggest to put the logic for that in a separate helper object that knows how to construct a File object from an input string, respecting the StateHolder's base dir if present.

input.consume(1)
parsedInput.actions.add(object : Action {
override fun run(arguments: Set<ParsedArgument>) {
StateHolder.state.basedir= ""

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think that this has been implemented a little too complicated. If baseDir isn't a dir, then this is an error and should be added to parsedInput.errors accordingly beforehand. This will automatically lead to it being printed the right way which allows for removing the manual settings of the prompt here.


object StateHolder {
data class State(var portSet: Boolean = false, var chaosMonkeyProbability: Int = 0, val openAPISpec: OpenAPI = OpenApiMonitor.getPrototype(), val websocketResources: MutableMap<String, WebsocketResource> = mutableMapOf(), val timerTasks: MutableSet<TimerTask> = mutableSetOf(), var resourceCounter: Int = 0)
data class State(var portSet: Boolean = false, var chaosMonkeyProbability: Int = 0, val openAPISpec: OpenAPI = OpenApiMonitor.getPrototype(), val websocketResources: MutableMap<String, WebsocketResource> = mutableMapOf(), val timerTasks: MutableSet<TimerTask> = mutableSetOf(), var resourceCounter: Int = 0, var basedir: String = ".")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

In my opinion, baseDir should be initialized with null since the logic above for determining the relative path already handles that as "relative to here".

object OpenApiHandler : Handler {
override fun handle(input: Input, parsedInput: ParsedInput) {
val pathToOpenApiSpec = input.second()
var pathToOpenApiSpec = input.second()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

See comment above.

return
}
val file = File(input.first())
var scriptfilePath = input.first()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

See comment above.


private fun getRetValFromFile(input: Input, statusCode: Int): DynamicRetVal {
val file = File(input.second())
var returnValueFilePath = input.second()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

See comment above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants