您如何向“伪造目标"添加描述? [英] How do you add a description to a FAKE Target?

查看:77
本文介绍了您如何向“伪造目标"添加描述?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以向该目标添加说明?还是我需要另辟?径?

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..."
)

TargetHelper 允许在listTargets()时显示说明被称为.

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

至少,这是我对此处代码的理解: https://github.com/fsharp/FAKE/blob/master/src/app/FakeLib/TargetHelper.fs#L360-L365

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

推荐答案

如果只想使构建脚本可读,则可以使用普通的F#方式添加注释:

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..."
)

据我所知,在FAKE中没有内置任何可用于向目标中添加说明的内容,但是FAKE的好处在于它只是一个F#库,因此可自定义.

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.

这是您可以做的一件事-定义包装Target的自己的函数,但需要附加描述并自动使用描述构建帮助"目标:

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
)

这篇关于您如何向“伪造目标"添加描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆