@@ -23,6 +23,7 @@ open FSharp.Compiler.TypedTreeOps
23
23
open FSharp.Compiler .DiagnosticsLogger
24
24
25
25
open Internal.Utilities
26
+ open System.Text
26
27
27
28
module Attributes =
28
29
open System.Runtime .CompilerServices
@@ -112,7 +113,11 @@ let compilerOptionUsage (CompilerOption (s, tag, spec, _, _)) =
112
113
else
113
114
sprintf " %s :%s " s tag (* still being decided *)
114
115
115
- let PrintCompilerOption ( CompilerOption ( _s , _tag , _spec , _ , help ) as compilerOption ) =
116
+ let nl = Environment.NewLine
117
+
118
+ let getCompilerOption ( CompilerOption ( _s , _tag , _spec , _ , help ) as compilerOption ) =
119
+ let sb = StringBuilder()
120
+
116
121
let flagWidth = 42 // fixed width for printing of flags, e.g. --debug:{full|pdbonly|portable|embedded}
117
122
let defaultLineWidth = 80 // the fallback width
118
123
@@ -131,18 +136,18 @@ let PrintCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOp
131
136
// flagWidth chars - for flags description or padding on continuation lines.
132
137
// single space - space.
133
138
// description - words upto but excluding the final character of the line.
134
- printf " %-40s " ( compilerOptionUsage compilerOption)
139
+ let _ = sb.Append $ " { compilerOptionUsage compilerOption, -40} "
135
140
136
141
let printWord column ( word : string ) =
137
142
// Have printed upto column.
138
143
// Now print the next word including any preceding whitespace.
139
144
// Returns the column printed to (suited to folding).
140
145
if column + 1 (* space*) + word.Length >= lineWidth then // NOTE: "equality" ensures final character of the line is never printed
141
- printfn " " (* newline *)
142
- printf " %-40s %s " " " (* <--flags *) word
146
+ let _ = sb.Append $ " {nl} "
147
+ let _ = sb.Append $ " {String.Empty, -40} { word} "
143
148
flagWidth + 1 + word.Length
144
149
else
145
- printf " %s " word
150
+ let _ = sb.Append $ " { word} "
146
151
column + 1 + word.Length
147
152
148
153
let words =
@@ -151,16 +156,19 @@ let PrintCompilerOption (CompilerOption (_s, _tag, _spec, _, help) as compilerOp
151
156
| Some s -> s.Split [| ' ' |]
152
157
153
158
let _finalColumn = Array.fold printWord flagWidth words
154
- printfn " " (* newline *)
159
+ let _ = sb.Append $" {nl}"
160
+ sb.ToString()
155
161
156
- let PrintPublicOptions ( heading , opts ) =
162
+ let getPublicOptions ( heading , opts ) =
157
163
if not ( isNil opts) then
158
- printfn " "
159
- printfn " "
160
- printfn " \t\t %s " heading
161
- List.iter PrintCompilerOption opts
164
+ $" {nl}{nl}\t\t {heading}{nl}"
165
+ + ( opts |> List.map getCompilerOption |> String.concat " " )
166
+ else
167
+ " "
168
+
169
+ let GetCompilerOptionBlocks blocks =
170
+ let sb = new StringBuilder()
162
171
163
- let PrintCompilerOptionBlocks blocks =
164
172
let publicBlocks =
165
173
blocks
166
174
|> List.choose ( function
@@ -174,10 +182,11 @@ let PrintCompilerOptionBlocks blocks =
174
182
let headingOptions =
175
183
publicBlocks |> List.filter ( fun ( h2 , _ ) -> heading = h2) |> List.collect snd
176
184
177
- PrintPublicOptions ( heading, headingOptions)
185
+ let _ = sb.Append ( getPublicOptions ( heading, headingOptions) )
178
186
Set.add heading doneHeadings
179
187
180
188
List.fold consider Set.empty publicBlocks |> ignore< Set< string>>
189
+ sb.ToString()
181
190
182
191
(* For QA *)
183
192
let dumpCompilerOption prefix ( CompilerOption ( str , _ , spec , _ , _ )) =
@@ -1981,31 +1990,46 @@ let deprecatedFlagsFsc tcConfigB =
1981
1990
// OptionBlock: Miscellaneous options
1982
1991
//-----------------------------------
1983
1992
1984
- let DisplayBannerText tcConfigB =
1993
+ let GetBannerText tcConfigB =
1985
1994
if tcConfigB.showBanner then
1986
- ( printfn " %s " tcConfigB.productNameForBannerText
1987
- printfn " %s " ( FSComp.SR.optsCopyright ()))
1995
+ $" {tcConfigB.productNameForBannerText}{nl}"
1996
+ + $" {FSComp.SR.optsCopyright ()}{nl}"
1997
+ else
1998
+ " "
1988
1999
1989
2000
/// FSC only help. (FSI has it's own help function).
1990
- let displayHelpFsc tcConfigB ( blocks : CompilerOptionBlock list ) =
1991
- DisplayBannerText tcConfigB
1992
- PrintCompilerOptionBlocks blocks
1993
- exit 0
2001
+ let GetHelpFsc tcConfigB ( blocks : CompilerOptionBlock list ) =
2002
+ GetBannerText tcConfigB + GetCompilerOptionBlocks blocks
1994
2003
1995
- let displayVersion tcConfigB =
1996
- printfn " %s " tcConfigB.productNameForBannerText
1997
- exit 0
2004
+ let GetVersion tcConfigB =
2005
+ $" {tcConfigB.productNameForBannerText}{nl}"
1998
2006
1999
2007
let miscFlagsBoth tcConfigB =
2000
2008
[
2001
2009
CompilerOption( " nologo" , tagNone, OptionUnit( fun () -> tcConfigB.showBanner <- false ), None, Some( FSComp.SR.optsNologo ()))
2002
- CompilerOption( " version" , tagNone, OptionConsoleOnly( fun _ -> displayVersion tcConfigB), None, Some( FSComp.SR.optsVersion ()))
2010
+ CompilerOption(
2011
+ " version" ,
2012
+ tagNone,
2013
+ OptionConsoleOnly( fun _ ->
2014
+ Console.Write( GetVersion tcConfigB)
2015
+ exit 0 ),
2016
+ None,
2017
+ Some( FSComp.SR.optsVersion ())
2018
+ )
2003
2019
]
2004
2020
2005
2021
let miscFlagsFsc tcConfigB =
2006
2022
miscFlagsBoth tcConfigB
2007
2023
@ [
2008
- CompilerOption( " help" , tagNone, OptionConsoleOnly( fun blocks -> displayHelpFsc tcConfigB blocks), None, Some( FSComp.SR.optsHelp ()))
2024
+ CompilerOption(
2025
+ " help" ,
2026
+ tagNone,
2027
+ OptionConsoleOnly( fun blocks ->
2028
+ Console.Write( GetHelpFsc tcConfigB blocks)
2029
+ exit 0 ),
2030
+ None,
2031
+ Some( FSComp.SR.optsHelp ())
2032
+ )
2009
2033
CompilerOption( " @<file>" , tagNone, OptionUnit ignore, None, Some( FSComp.SR.optsResponseFile ()))
2010
2034
]
2011
2035
@@ -2061,23 +2085,29 @@ let abbreviatedFlagsFsc tcConfigB =
2061
2085
CompilerOption(
2062
2086
" ?" ,
2063
2087
tagNone,
2064
- OptionConsoleOnly( fun blocks -> displayHelpFsc tcConfigB blocks),
2088
+ OptionConsoleOnly( fun blocks ->
2089
+ Console.Write( GetHelpFsc tcConfigB blocks)
2090
+ exit 0 ),
2065
2091
None,
2066
2092
Some( FSComp.SR.optsShortFormOf ( " --help" ))
2067
2093
)
2068
2094
2069
2095
CompilerOption(
2070
2096
" help" ,
2071
2097
tagNone,
2072
- OptionConsoleOnly( fun blocks -> displayHelpFsc tcConfigB blocks),
2098
+ OptionConsoleOnly( fun blocks ->
2099
+ Console.Write( GetHelpFsc tcConfigB blocks)
2100
+ exit 0 ),
2073
2101
None,
2074
2102
Some( FSComp.SR.optsShortFormOf ( " --help" ))
2075
2103
)
2076
2104
2077
2105
CompilerOption(
2078
2106
" full-help" ,
2079
2107
tagNone,
2080
- OptionConsoleOnly( fun blocks -> displayHelpFsc tcConfigB blocks),
2108
+ OptionConsoleOnly( fun blocks ->
2109
+ Console.Write( GetHelpFsc tcConfigB blocks)
2110
+ exit 0 ),
2081
2111
None,
2082
2112
Some( FSComp.SR.optsShortFormOf ( " --help" ))
2083
2113
)
0 commit comments