Skip to content

Commit

Permalink
Merge pull request #51 from CaptnCodr/feature/output-enhancement
Browse files Browse the repository at this point in the history
CustomOperation for each output type.
  • Loading branch information
CaptnCodr committed May 27, 2023
2 parents ec9e8c5 + fb5efd7 commit 36ab51e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"isRoot": true,
"tools": {
"paket": {
"version": "7.1.5",
"version": "7.2.1",
"commands": [
"paket"
]
},
"fantomas": {
"version": "5.1.4",
"version": "6.0.3",
"commands": [
"fantomas"
]
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ cli {
|> Command.execute
```

Write output to a function (logging, printing, etc.):
```fsharp
let log (output: string) = Debug.Log($"CLI log: {output}")
cli {
Exec "dotnet"
Arguments "--list-sdks"
Output log
}
|> Command.execute
```

Add environment variables for the executing program:
```fsharp
cli {
Expand Down
35 changes: 24 additions & 11 deletions src/Fli/CE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ module CE =

member this.Yield(_) = this

member internal _.outputTypeMapping(output) =
match box (output) with
| :? string as s -> Outputs.File s
| :? StringBuilder as sb -> Outputs.StringBuilder sb
| :? (string -> unit) as func -> Outputs.Custom func
| _ -> failwith "Cannot convert output type."

type StartingContext =
{ config: Config option }

Expand Down Expand Up @@ -45,8 +38,18 @@ module CE =

/// Extra `Output` that is being executed immediately after getting output from execution.
[<CustomOperation("Output")>]
member this.Output(context: ICommandContext<ShellContext>, output) =
Cli.output ((this :> ICommandContext<_>).outputTypeMapping output) context.Context
member _.Output(context: ICommandContext<ShellContext>, filePath: string) =
Cli.output (File filePath) context.Context

/// Extra `Output` that is being executed immediately after getting output from execution.
[<CustomOperation("Output")>]
member _.Output(context: ICommandContext<ShellContext>, stringBuilder: StringBuilder) =
Cli.output (StringBuilder stringBuilder) context.Context

/// Extra `Output` that is being executed immediately after getting output from execution.
[<CustomOperation("Output")>]
member _.Output(context: ICommandContext<ShellContext>, func: string -> unit) =
Cli.output (Custom func) context.Context

/// Current executing `working directory`.
[<CustomOperation("WorkingDirectory")>]
Expand Down Expand Up @@ -92,8 +95,18 @@ module CE =

/// Extra `Output` that is being executed immediately after getting output from execution.
[<CustomOperation("Output")>]
member this.Output(context: ICommandContext<ExecContext>, output) =
Program.output ((this :> ICommandContext<_>).outputTypeMapping output) context.Context
member _.Output(context: ICommandContext<ExecContext>, filePath: string) =
Program.output (File filePath) context.Context

/// Extra `Output` that is being executed immediately after getting output from execution.
[<CustomOperation("Output")>]
member _.Output(context: ICommandContext<ExecContext>, stringBuilder: StringBuilder) =
Program.output (StringBuilder stringBuilder) context.Context

/// Extra `Output` that is being executed immediately after getting output from execution.
[<CustomOperation("Output")>]
member _.Output(context: ICommandContext<ExecContext>, func: string -> unit) =
Program.output (Custom func) context.Context

/// Current executing `working directory`.
[<CustomOperation("WorkingDirectory")>]
Expand Down

0 comments on commit 36ab51e

Please sign in to comment.