-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format commands help #639
Format commands help #639
Changes from all commits
8e6847a
4a48a9a
fcfe45c
96ccbed
0c93c0c
2205f54
10e2430
7706da2
3586355
049666d
7c7017c
7c5826e
e345a7b
0c429c9
8dacac4
cc41870
f52afbd
7682922
182ede1
5c2cdb6
8d7c677
eb10146
a900114
2960a52
95bed53
f202192
312b31e
a2df3a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
module Paket.Commands | ||
|
||
open System | ||
|
||
open Nessos.UnionArgParser | ||
|
||
type Command = | ||
|
@@ -19,8 +21,29 @@ type Command = | |
| [<First>][<CustomCommandLine("push")>] Push | ||
with | ||
interface IArgParserTemplate with | ||
member __.Usage = "" | ||
|
||
member this.Usage = | ||
match this with | ||
| Add -> "Adds a new package to your paket.dependencies file." | ||
| Config -> "Allows to store global configuration values like NuGet credentials." | ||
| ConvertFromNuget -> "Converts from using NuGet to Paket." | ||
| FindRefs -> "Finds all project files that have the given NuGet packages installed." | ||
| Init -> "Creates empty paket.dependencies file in the working directory." | ||
| AutoRestore -> "Enables or disables automatic Package Restore in Visual Studio during the build process." | ||
| Install -> "Ensures that all dependencies in your paket.dependencies file are present in the `packages` directory and referenced correctly in all projects." | ||
| Outdated -> "Lists all dependencies that have newer versions available." | ||
| Remove -> "Removes a package from your paket.dependencies file and all paket.references files." | ||
| Restore -> "Ensures that all dependencies in your paket.dependencies file are present in the `packages` directory." | ||
| Simplify -> "Simplifies your paket.dependencies file by removing transitive dependencies." | ||
| Update -> "Recomputes the dependency resolution, updates the paket.lock file and propagates any resulting package changes into all project files referencing updated packages." | ||
| Pack -> "Packs all paket.template files within this repository" | ||
| Push -> "Pushes all `.nupkg` files from the given directory." | ||
|
||
member this.Name = | ||
let uci,_ = Microsoft.FSharp.Reflection.FSharpValue.GetUnionFields(this, typeof<Command>) | ||
(uci.GetCustomAttributes(typeof<CustomCommandLineAttribute>) | ||
|> Seq.head | ||
:?> CustomCommandLineAttribute).Name | ||
|
||
type GlobalArgs = | ||
| [<AltCommandLine("-v")>] Verbose | ||
| Log_File of string | ||
|
@@ -38,13 +61,23 @@ type AddArgs = | |
| No_Install | ||
with | ||
interface IArgParserTemplate with | ||
member __.Usage = "" | ||
member this.Usage = | ||
match this with | ||
| Nuget(_) -> "Nuget package id." | ||
| Version(_) -> "Allows to specify version of the package." | ||
| Project(_) -> "Allows to add the package to a single project only." | ||
| Force -> "Forces the download and reinstallation of all packages." | ||
| Interactive -> "Asks the user for every project if he or she wants to add the package to the projects's paket.references file." | ||
| Hard -> "Replaces package references within project files even if they are not yet adhering to the Paket's conventions (and hence considered manually managed)." | ||
| No_Install -> "Skips paket install --hard process afterward generation of dependencies / references files." | ||
|
||
type ConfigArgs = | ||
| [<CustomCommandLine("add-credentials")>] AddCredentials of string | ||
with | ||
interface IArgParserTemplate with | ||
member __.Usage = "" | ||
member this.Usage = | ||
match this with | ||
| AddCredentials(_) -> "Add credentials for the specified Nuget feed" | ||
|
||
type ConvertFromNugetArgs = | ||
| [<AltCommandLine("-f")>] Force | ||
|
@@ -53,13 +86,20 @@ type ConvertFromNugetArgs = | |
| Creds_Migration of string | ||
with | ||
interface IArgParserTemplate with | ||
member __.Usage = "" | ||
member this.Usage = | ||
match this with | ||
| Force -> "Forces the conversion, even if a paket.dependencies file or paket.references files are present." | ||
| No_Install -> "Skips paket install --hard process afterward generation of dependencies / references files." | ||
| No_Auto_Restore -> "Skips paket auto-restore process afterward generation of dependencies / references files." | ||
| Creds_Migration(_) -> "Specify mode for migrating NuGet source credentials. Possible values are [`encrypt`|`plaintext`|`selective`]. The default mode is `encrypt`." | ||
|
||
type FindRefsArgs = | ||
| [<Rest>][<CustomCommandLine("nuget")>][<Mandatory>] Packages of string | ||
with | ||
interface IArgParserTemplate with | ||
member __.Usage = "" | ||
member this.Usage = | ||
match this with | ||
| Packages(_) -> "List of packages." | ||
|
||
type InitArgs = | ||
| [<Hidden>] NoArg | ||
|
@@ -72,22 +112,32 @@ type AutoRestoreArgs = | |
| [<First>][<CustomCommandLine("off")>] Off | ||
with | ||
interface IArgParserTemplate with | ||
member __.Usage = "" | ||
member this.Usage = | ||
match this with | ||
| On -> "Turns auto restore on" | ||
| Off -> "Turns auto restore off" | ||
|
||
type InstallArgs = | ||
| [<AltCommandLine("-f")>] Force | ||
| Hard | ||
| Redirects | ||
with | ||
interface IArgParserTemplate with | ||
member __.Usage = "" | ||
member this.Usage = | ||
match this with | ||
| Force -> "Forces the download and reinstallation of all packages." | ||
| Hard -> "Replaces package references within project files even if they are not yet adhering to the Paket's conventions (and hence considered manually managed)." | ||
| Redirects -> "Creates binding redirects for the NuGet packages." | ||
|
||
type OutdatedArgs = | ||
| Ignore_Constraints | ||
| [<AltCommandLine("--pre")>] Include_Prereleases | ||
with | ||
interface IArgParserTemplate with | ||
member __.Usage = "" | ||
member this.Usage = | ||
match this with | ||
| Ignore_Constraints -> "Ignores the version requirement as in the paket.dependencies file." | ||
| Include_Prereleases -> "Includes prereleases." | ||
|
||
type RemoveArgs = | ||
| [<CustomCommandLine("nuget")>][<Mandatory>] Nuget of string | ||
|
@@ -98,20 +148,32 @@ type RemoveArgs = | |
| No_Install | ||
with | ||
interface IArgParserTemplate with | ||
member __.Usage = "" | ||
member this.Usage = | ||
match this with | ||
| Nuget(_) -> "Nuget package id." | ||
| Project(_) -> "Allows to add the package to a single project only." | ||
| Force -> "Forces the download and reinstallation of all packages." | ||
| Interactive -> "Asks the user for every project if he or she wants to remove the package from the projects's paket.references file. By default every installation of the package is removed." | ||
| Hard -> "Replaces package references within project files even if they are not yet adhering to the Paket's conventions (and hence considered manually managed)." | ||
| No_Install -> "Skips paket install --hard process afterward generation of dependencies / references files." | ||
|
||
type RestoreArgs = | ||
| [<AltCommandLine("-f")>] Force | ||
| [<Rest>] References_Files of string | ||
with | ||
interface IArgParserTemplate with | ||
member __.Usage = "" | ||
member this.Usage = | ||
match this with | ||
| Force -> "Forces the download of all packages." | ||
| References_Files(_) -> "Allows to restore all packages from the given paket.references files. If no paket.references file is given then all packages will be restored." | ||
|
||
type SimplifyArgs = | ||
| [<AltCommandLine("-i")>] Interactive | ||
with | ||
interface IArgParserTemplate with | ||
member __.Usage = "" | ||
member this.Usage = | ||
match this with | ||
| Interactive -> "Asks to confirm to delete every transitive dependency from each of the files." | ||
|
||
type UpdateArgs = | ||
| [<CustomCommandLine("nuget")>] Nuget of string | ||
|
@@ -121,7 +183,13 @@ type UpdateArgs = | |
| Redirects | ||
with | ||
interface IArgParserTemplate with | ||
member __.Usage = "" | ||
member this.Usage = | ||
match this with | ||
| Nuget(_) -> "Nuget package id" | ||
| Version(_) -> "Allows to specify version of the package." | ||
| Force -> "Forces the download and reinstallation of all packages." | ||
| Hard -> "Replaces package references within project files even if they are not yet adhering to the Paket's conventions (and hence considered manually managed)." | ||
| Redirects -> "Creates binding redirects for the NuGet packages." | ||
|
||
type PackArgs = | ||
| [<CustomCommandLine("output")>][<Mandatory>] Output of string | ||
|
@@ -130,12 +198,90 @@ type PackArgs = | |
| [<CustomCommandLine("releaseNotes")>] ReleaseNotes of string | ||
with | ||
interface IArgParserTemplate with | ||
member __.Usage = "" | ||
member this.Usage = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mavnn could you please review the messages for this new command? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good |
||
match this with | ||
| Output(_) -> "Output directory to put nupkgs." | ||
| BuildConfig(_) -> "Optionally specify build configuration that should be packaged (defaults to Release)." | ||
| Version(_) -> "Specify version of the package." | ||
| ReleaseNotes(_) -> "Specify relase notes for the package." | ||
|
||
type PushArgs = | ||
| [<CustomCommandLine("url")>][<Mandatory>] Url of string | ||
| [<CustomCommandLine("file")>][<Mandatory>] FileName of string | ||
| [<CustomCommandLine("apikey")>] ApiKey of string | ||
with | ||
interface IArgParserTemplate with | ||
member __.Usage = "" | ||
member this.Usage = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mavnn - and the same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good here too |
||
match this with | ||
| Url(_) -> "Url of the Nuget feed." | ||
| FileName(_) -> "Path to the package." | ||
| ApiKey(_) -> "Optionally specify your API key on the command line. Otherwise uses the value of the `nugetkey` environment variable." | ||
|
||
let cmdLineSyntax (parser:UnionArgParser<_>) commandName = | ||
"$ paket " + commandName + " " + parser.PrintCommandLineSyntax() | ||
|
||
let cmdLineUsageMessage (command : Command) parser = | ||
System.Text.StringBuilder() | ||
.Append("Paket ") | ||
.AppendLine(command.Name) | ||
.AppendLine() | ||
.AppendLine((command :> IArgParserTemplate).Usage) | ||
.AppendLine() | ||
.Append(cmdLineSyntax parser command.Name) | ||
.ToString() | ||
|
||
let markdown (command : Command) (additionalText : string) = | ||
let replace (pattern : string) (replacement : string) input = | ||
System.Text.RegularExpressions.Regex.Replace(input, pattern, replacement) | ||
|
||
let syntaxAndOptions (parser : UnionArgParser<_>) = | ||
let options = | ||
parser.Usage() | ||
|> replace @"\s\t--help.*" "" | ||
|> replace @"\t([-\w \[\]|\/\?<>\.]+):" (System.Environment.NewLine + @" `$1`:") | ||
|
||
let syntax = cmdLineSyntax parser command.Name | ||
syntax, options | ||
|
||
let getSyntax = function | ||
| Add -> syntaxAndOptions (UnionArgParser.Create<AddArgs>()) | ||
| Config -> syntaxAndOptions (UnionArgParser.Create<ConfigArgs>()) | ||
| ConvertFromNuget -> syntaxAndOptions (UnionArgParser.Create<ConvertFromNugetArgs>()) | ||
| FindRefs -> syntaxAndOptions (UnionArgParser.Create<FindRefsArgs>()) | ||
| Init -> syntaxAndOptions (UnionArgParser.Create<InitArgs>()) | ||
| AutoRestore -> syntaxAndOptions (UnionArgParser.Create<AutoRestoreArgs>()) | ||
| Install -> syntaxAndOptions (UnionArgParser.Create<InstallArgs>()) | ||
| Outdated -> syntaxAndOptions (UnionArgParser.Create<OutdatedArgs>()) | ||
| Remove -> syntaxAndOptions (UnionArgParser.Create<RemoveArgs>()) | ||
| Restore -> syntaxAndOptions (UnionArgParser.Create<RestoreArgs>()) | ||
| Simplify -> syntaxAndOptions (UnionArgParser.Create<SimplifyArgs>()) | ||
| Update -> syntaxAndOptions (UnionArgParser.Create<UpdateArgs>()) | ||
| Pack -> syntaxAndOptions (UnionArgParser.Create<PackArgs>()) | ||
| Push -> syntaxAndOptions (UnionArgParser.Create<PushArgs>()) | ||
|
||
|
||
let replaceLinks (text : string) = | ||
text | ||
.Replace("paket.dependencies file","[`paket.dependencies` file](dependencies-file.html)") | ||
.Replace("paket.lock file","[`paket.lock` file](lock-file.html)") | ||
.Replace("paket.template files","[`paket.template` files](template-files.html)") | ||
.Replace("paket.references files","[`paket.references` files](references-files.html)") | ||
.Replace("paket.references file","[`paket.references` file](references-files.html)") | ||
|
||
let syntax, options = getSyntax command | ||
|
||
System.Text.StringBuilder() | ||
.Append("# paket ") | ||
.AppendLine(command.Name) | ||
.AppendLine() | ||
.AppendLine((command :> IArgParserTemplate).Usage) | ||
.AppendLine() | ||
.AppendLine(" [lang=batchfile]") | ||
.Append(" ") | ||
.AppendLine(syntax) | ||
.AppendLine() | ||
.AppendLine("Options:") | ||
.AppendLine(options) | ||
.Append(additionalText) | ||
.ToString() | ||
|> replaceLinks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this gone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I treat config as a command so it's now generated from the HelpTexts class.
Eventually we'll be able to fallback to separate md file for each command when this PR is merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool. just tell me when it's ready to merge - really cool stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I think it's ready now - I took it even a step further.