-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add --print-session option to history command
And document it while we're at it
- Loading branch information
Showing
6 changed files
with
54 additions
and
11 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
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
28 changes: 28 additions & 0 deletions
28
server/src/main/kotlin/io/typestream/compiler/shellcommand/history.kt
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,28 @@ | ||
package io.typestream.compiler.shellcommand | ||
|
||
import io.typestream.compiler.types.DataStream | ||
import io.typestream.compiler.types.schema.Schema | ||
import io.typestream.compiler.vm.Session | ||
import io.typestream.option.Option | ||
import io.typestream.option.parseOptions | ||
|
||
data class HistoryOptions( | ||
@param:Option( | ||
names = ["-p", "--print-session"], | ||
description = "inverts matching pattern" | ||
) val printSession: Boolean = false, | ||
) | ||
|
||
fun history(session: Session, args: List<String>): ShellCommandOutput { | ||
val (options, _) = parseOptions<HistoryOptions>(args) | ||
|
||
if (options.printSession) { | ||
return ShellCommandOutput.withOutput(session.env.history().map { command -> | ||
DataStream("/bin/history", Schema.String(command)) | ||
}) | ||
} | ||
|
||
return ShellCommandOutput.withOutput(session.env.history().mapIndexed { index, command -> | ||
DataStream("/bin/history", Schema.String("${index + 1} $command")) | ||
}) | ||
} |
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