How do you add a description to a FAKE Target?

坚强是说给别人听的谎言 提交于 2019-12-11 11:54:49

问题


Is it possible to add a description to this target? Or would I have to go about it another way?

Target "Test" (fun _ ->
    trace "Testing stuff..."
)

Edit:

TargetHelper allows for the description to be shown when listTargets() is called.

At least, that's my understanding from the code here: https://github.com/fsharp/FAKE/blob/master/src/app/FakeLib/TargetHelper.fs#L360-L365


回答1:


If you just want to make your build script readable, you can add a comment in the normal F# way:

// Tests some stuff
Target "Test" (fun _ ->
    trace "Testing stuff..."
)

As far as I know, there isn't anything built-in for adding descriptions to your targets in FAKE, but the nice thing about FAKE is that it is just an F# library, and so it is very customizable.

Here is one thing you could do - define your own function that wraps Target, but takes an additional description and builds a "Help" target with the descriptions automatically:

// The 'TargetDescr' function calls 'Target', but stores the description
let Description = System.Text.StringBuilder("Usage:\n")
let TargetDescr name comment f = 
  Description.AppendFormat(" * {0} - {1}\n", name, comment) |> ignore
  Target name f

// Now you can define targets using 'TargetDescr' and get help page for free!
TargetDescr "Test" "Tests some stuff..." (fun _ ->
    trace "Testing stuff..."
)

TargetDescr "Help" "Displays this help" (fun _ ->
  printfn "%O" Description
)


来源:https://stackoverflow.com/questions/32017021/how-do-you-add-a-description-to-a-fake-target

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!