@@ -18,6 +18,7 @@ const (
1818 searchDirFlag = "dir"
1919 excludeFlag = "exclude"
2020 generalInfoFlag = "generalInfo"
21+ pipeFlag = "pipe"
2122 propertyStrategyFlag = "propertyStrategy"
2223 outputFlag = "output"
2324 outputTypesFlag = "outputTypes"
@@ -195,11 +196,17 @@ func initAction(ctx *cli.Context) error {
195196 if ctx .IsSet (templateDelimsFlag ) {
196197 delims := strings .Split (ctx .String (templateDelimsFlag ), "," )
197198 if len (delims ) != 2 {
198- return fmt .Errorf ("exactly two template delimiters must be provided, comma separated" )
199+ return fmt .Errorf (
200+ "exactly two template delimiters must be provided, comma separated" ,
201+ )
199202 } else if delims [0 ] == delims [1 ] {
200203 return fmt .Errorf ("template delimiters must be different" )
201204 }
202- leftDelim , rightDelim = strings .TrimSpace (delims [0 ]), strings .TrimSpace (delims [1 ])
205+ leftDelim , rightDelim = strings .TrimSpace (
206+ delims [0 ],
207+ ), strings .TrimSpace (
208+ delims [1 ],
209+ )
203210 }
204211
205212 outputTypes := strings .Split (ctx .String (outputTypesFlag ), "," )
@@ -211,9 +218,14 @@ func initAction(ctx *cli.Context) error {
211218 logger = log .New (io .Discard , "" , log .LstdFlags )
212219 }
213220
214- collectionFormat := swag .TransToValidCollectionFormat (ctx .String (collectionFormatFlag ))
221+ collectionFormat := swag .TransToValidCollectionFormat (
222+ ctx .String (collectionFormatFlag ),
223+ )
215224 if collectionFormat == "" {
216- return fmt .Errorf ("not supported %s collectionFormat" , ctx .String (collectionFormat ))
225+ return fmt .Errorf (
226+ "not supported %s collectionFormat" ,
227+ ctx .String (collectionFormat ),
228+ )
217229 }
218230
219231 var pdv = ctx .Int (parseDependencyLevelFlag )
@@ -269,6 +281,11 @@ func main() {
269281 Aliases : []string {"f" },
270282 Usage : "format swag comments" ,
271283 Action : func (c * cli.Context ) error {
284+
285+ if c .Bool (pipeFlag ) {
286+ return format .New ().Run (os .Stdin , os .Stdout )
287+ }
288+
272289 searchDir := c .String (searchDirFlag )
273290 excludeDir := c .String (excludeFlag )
274291 mainFile := c .String (generalInfoFlag )
@@ -296,6 +313,12 @@ func main() {
296313 Value : "main.go" ,
297314 Usage : "Go file path in which 'swagger general API Info' is written" ,
298315 },
316+ & cli.BoolFlag {
317+ Name : "pipe" ,
318+ Aliases : []string {"p" },
319+ Value : false ,
320+ Usage : "Read from stdin, write to stdout." ,
321+ },
299322 },
300323 },
301324 }
0 commit comments