From 8e6847a729b97e786cc7bd9b8da936482d908087 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Fri, 20 Feb 2015 16:01:23 +0100 Subject: [PATCH 01/28] Treat config as a command in docs --- Paket.sln | 1 - docs/content/paket-config-file.md | 17 ----------------- docs/tools/templates/template.cshtml | 2 +- src/Paket/HelpTexts.fs | 23 +++++++++++++++++++++-- src/Paket/Program.fs | 4 ++-- 5 files changed, 24 insertions(+), 23 deletions(-) delete mode 100644 docs/content/paket-config-file.md diff --git a/Paket.sln b/Paket.sln index 6189ae28e2..4665c94d5b 100644 --- a/Paket.sln +++ b/Paket.sln @@ -34,7 +34,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{8E6D docs\content\index.md = docs\content\index.md docs\content\lock-file.md = docs\content\lock-file.md docs\content\nuget-dependencies.md = docs\content\nuget-dependencies.md - docs\content\paket-config-file.md = docs\content\paket-config-file.md docs\content\paket.dependencies = docs\content\paket.dependencies docs\content\reference-from-repl.fsx = docs\content\reference-from-repl.fsx docs\content\references-files.md = docs\content\references-files.md diff --git a/docs/content/paket-config-file.md b/docs/content/paket-config-file.md deleted file mode 100644 index a5db3c9c16..0000000000 --- a/docs/content/paket-config-file.md +++ /dev/null @@ -1,17 +0,0 @@ -# paket.config file - -Allows to store global configuration values like NuGet credentials. It can be found in: - - let AppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) - let PaketConfigFolder = Path.Combine(AppDataFolder, "Paket") - let PaketConfigFile = Path.Combine(PaketConfigFolder, "paket.config") - -## Add credentials - -Credentials for a specific source can be added with the following command: - - paket config add-credentials http://myserver.com/myfeed - -Paket will then ask for username and password. - -This credentials will be used if no username and password for the source are configured in the [`paket.dependencies` file](nuget-dependencies.html). diff --git a/docs/tools/templates/template.cshtml b/docs/tools/templates/template.cshtml index 76446bd567..737f1cbff0 100644 --- a/docs/tools/templates/template.cshtml +++ b/docs/tools/templates/template.cshtml @@ -63,6 +63,7 @@
  • paket add
  • paket auto-restore
  • +
  • paket config
  • paket convert-from-nuget
  • paket find-refs
  • paket init
  • @@ -77,7 +78,6 @@
  • .paket folder
  • paket.bootstrapper.exe
  • -
  • paket.config
  • diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index f3dddb6fa3..283e461b1b 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -373,7 +373,26 @@ Options: `packagedir`: a directory; every `.nupkg` file in this directory or it's children will be pushed. `apikey`: Optionally specify your API key on the command line. Otherwise uses the value of the `nugetkey` environment variable. - - `url`: Optionally specify root url of the nuget repository you are pushing too. Defaults to [https://nuget.org](https://nuget.org)."""}] + + `url`: Optionally specify root url of the nuget repository you are pushing too. Defaults to [https://nuget.org](https://nuget.org)."""} + "config", + { Title = "paket config" + Text = """# paket.config file + +Allows to store global configuration values like NuGet credentials. It can be found in: + + let AppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + let PaketConfigFolder = Path.Combine(AppDataFolder, "Paket") + let PaketConfigFile = Path.Combine(PaketConfigFolder, "paket.config") + +## Add credentials + +Credentials for a specific source can be added with the following command: + + paket config add-credentials http://myserver.com/myfeed + +Paket will then ask for username and password. + +This credentials will be used if no username and password for the source are configured in the [`paket.dependencies` file](nuget-dependencies.html)."""}] |> dict diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 21fc73ff0c..fe4146b7eb 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -94,11 +94,11 @@ try let results = commandArgs args if results.IsUsageRequested then - trace <| results.Usage("paket config") + showHelp HelpTexts.commands.["config"] else let args = results.GetResults <@ ConfigArgs.AddCredentials @> if args.Length = 0 then - trace <| results.Usage("paket config") + showHelp HelpTexts.commands.["config"] else let source = args.Item 0 let username = From 4a48a9ab6dc83da66cba23025c8424bcd44cb74f Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Fri, 20 Feb 2015 18:08:28 +0100 Subject: [PATCH 02/28] auto generate syntax for install command --- docs/tools/generate.fsx | 1 + src/Paket/HelpTexts.fs | 2 +- src/Paket/Program.fs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/tools/generate.fsx b/docs/tools/generate.fsx index 5f854419be..1ae93b84a6 100644 --- a/docs/tools/generate.fsx +++ b/docs/tools/generate.fsx @@ -1,4 +1,5 @@ /// Getting help docs from Paket.exe +#r "../../bin/UnionArgParser.dll" #r "../../bin/Paket.exe" open System.IO diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index 283e461b1b..3ce2ad855c 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -347,7 +347,7 @@ Options: `--force`: Forces the download and reinstallation of all packages. `--hard`: Replaces package references within project files even if they are not yet adhering to Paket's conventions (and hence considered manually managed). See [convert from NuGet](paket-convert-from-nuget.html). - + `--redirects`: Creates binding redirects for the NuGet packages."""} "pack", { Title = "paket pack" diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index fe4146b7eb..5c12bfddd3 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -61,7 +61,7 @@ let commandArgs<'T when 'T :> IArgParserTemplate> args = errorHandler = ProcessExiter()) -let showHelp (helpTopic:HelpTexts.CommandHelpTopic) = +let showHelp (helpTopic:HelpTexts.CommandHelpTopic<_>) = tracefn "%s" helpTopic.Title tracefn "%s" helpTopic.Text From fcfe45cd7df3e1d79154eedf7684f22f6ee91f60 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sat, 21 Feb 2015 17:39:32 +0100 Subject: [PATCH 03/28] add Syntax member to CommandHelpTopic --- src/Paket/HelpTexts.fs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index 3ce2ad855c..cf53e6a42c 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -1,11 +1,39 @@ module Paket.HelpTexts +open Paket.Commands + +open Nessos.UnionArgParser + +let formatSyntax (parser:UnionArgParser<'TArgs>) commandName = + "$ " + commandName + " " + parser.PrintCommandLineSyntax() + +let formatUsage (parser:UnionArgParser<'TArgs>) commandName = + parser.Usage(formatSyntax parser commandName) + +let replace (pattern : string) (replacement : string) input = + System.Text.RegularExpressions.Regex.Replace(input, pattern, replacement) + +let formatCommandSyntax (parser : UnionArgParser<_>) title = + let options = + parser.Usage() + |> replace @"\s\t--help.*" "" + |> replace @"\t([-\w \[\]|\/\?]+):" (System.Environment.NewLine + @" `$1`:") + sprintf """ [lang=batchfile] + %s + +Options: +%s""" + (formatSyntax parser title) + options + type CommandHelpTopic = { Title : string + Syntax : string -> string Text : string } member this.ToMarkDown() = let text = this.Text + .Replace("<>", this.Syntax this.Title) .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)") @@ -17,6 +45,7 @@ type CommandHelpTopic = let commands = ["convert-from-nuget", { Title = "Convert your solution from NuGet" + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Manual process If you are already using `NuGet.exe` for package restore then it should be easy to convert to Paket. @@ -75,6 +104,7 @@ Consider using [`paket simplify`](paket-simplify.html) to remove unnecessary tra "auto-restore", { Title = "paket auto-restore" + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Enables or disables automatic Package Restore in Visual Studio during the build process. [lang=batchfile] @@ -93,6 +123,7 @@ Auto-restore off: "restore", { Title = "paket restore" + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Ensures that all dependencies in your paket.dependencies file are present in the `packages` directory . [lang=batchfile] @@ -106,6 +137,7 @@ Options: "simplify", { Title = "paket simplify" + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Simplifies your paket.dependencies file by removing transitive dependencies. Does also simplify paket.references files, unless [strict](dependencies-file.html#Strict-references) mode is used. @@ -167,6 +199,7 @@ which will ask you to confirm before deleting a dependency from a file."""} "init", { Title = "paket init" + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Creates empty paket.dependencies file in the working directory. [lang=batchfile] @@ -174,6 +207,7 @@ which will ask you to confirm before deleting a dependency from a file."""} "add", { Title = "paket add" + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Adds a new package to your paket.dependencies file. [lang=batchfile] @@ -217,6 +251,7 @@ This will add the package to the selected paket.references files and also to the "find-refs", { Title = "paket find-refs" + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Finds all project files that have the given NuGet packages installed. [lang=batchfile] @@ -250,6 +285,7 @@ and paket gives the following output: "update", { Title = "paket update" + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Recomputes the dependency resolution, updates the paket.lock file and propagates any resulting package changes into all project files referencing updated packages. [lang=batchfile] @@ -278,6 +314,7 @@ Options: "outdated", { Title = "paket outdated" + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Lists all dependencies that have newer versions available. [lang=batchfile] @@ -313,6 +350,7 @@ Now we run `paket outdated`: "remove", { Title = "paket remove" + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Removes a package from your paket.dependencies file and all paket.references files. [lang=batchfile] @@ -337,6 +375,7 @@ See also [paket add](paket-add.html)."""} "install", { Title = "paket install" + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Ensures that all dependencies in your paket.dependencies file are present in the `packages` directory and referenced correctly in all projects. [lang=batchfile] @@ -351,6 +390,7 @@ Options: `--redirects`: Creates binding redirects for the NuGet packages."""} "pack", { Title = "paket pack" + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Packs all paket.template files within this repository [lang=batchfile] @@ -363,6 +403,7 @@ Options: `buildconfig`: Optionally specify build configuration that should be packaged (defaults to Release)."""} "push", { Title = "paket push" + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Pushes all `.nupkg` files from the given directory. [lang=batchfile] @@ -377,6 +418,7 @@ Options: `url`: Optionally specify root url of the nuget repository you are pushing too. Defaults to [https://nuget.org](https://nuget.org)."""} "config", { Title = "paket config" + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """# paket.config file Allows to store global configuration values like NuGet credentials. It can be found in: From 96ccbed1f51a98da489977db8b34b309ee4868a0 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sat, 21 Feb 2015 17:44:54 +0100 Subject: [PATCH 04/28] automatic syntax for Install command --- src/Paket/Commands.fs | 6 +++++- src/Paket/HelpTexts.fs | 11 +---------- src/Paket/Paket.fsproj | 2 +- src/Paket/Program.fs | 2 +- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index bbb9320de6..669849cc62 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -80,7 +80,11 @@ type InstallArgs = | 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 Paket's conventions (and hence considered manually managed)." + | Redirects -> "Creates binding redirects for the NuGet packages." type OutdatedArgs = | Ignore_Constraints diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index cf53e6a42c..34e0619f1a 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -378,16 +378,7 @@ See also [paket add](paket-add.html)."""} Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Ensures that all dependencies in your paket.dependencies file are present in the `packages` directory and referenced correctly in all projects. - [lang=batchfile] - $ paket install [--force] [--hard] [--redirects] - -Options: - - `--force`: Forces the download and reinstallation of all packages. - - `--hard`: Replaces package references within project files even if they are not yet adhering to Paket's conventions (and hence considered manually managed). See [convert from NuGet](paket-convert-from-nuget.html). - - `--redirects`: Creates binding redirects for the NuGet packages."""} +<>"""} "pack", { Title = "paket pack" Syntax = formatCommandSyntax (UnionArgParser.Create()) diff --git a/src/Paket/Paket.fsproj b/src/Paket/Paket.fsproj index af5fa0a399..758597f7c4 100644 --- a/src/Paket/Paket.fsproj +++ b/src/Paket/Paket.fsproj @@ -62,8 +62,8 @@ - + diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 5c12bfddd3..fe4146b7eb 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -61,7 +61,7 @@ let commandArgs<'T when 'T :> IArgParserTemplate> args = errorHandler = ProcessExiter()) -let showHelp (helpTopic:HelpTexts.CommandHelpTopic<_>) = +let showHelp (helpTopic:HelpTexts.CommandHelpTopic) = tracefn "%s" helpTopic.Title tracefn "%s" helpTopic.Text From 0c93c0c6b5912e056bb8be54674a5ba4df188f68 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sat, 21 Feb 2015 17:50:52 +0100 Subject: [PATCH 05/28] print help for Install command --- src/Paket/Program.fs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index fe4146b7eb..3093feaa2a 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -149,10 +149,13 @@ try | _ -> showHelp HelpTexts.commands.["auto-restore"] | Command(Install, args) -> - let results = commandArgs args + let parser = UnionArgParser.Create() + let results = + parser.Parse(inputs = args, raiseOnUsage = false, ignoreMissing = true, + errorHandler = ProcessExiter()) if results.IsUsageRequested then - showHelp HelpTexts.commands.["install"] + parser.Usage(HelpTexts.formatSyntax parser "paket install") |> trace else let force = results.Contains <@ InstallArgs.Force @> let hard = results.Contains <@ InstallArgs.Hard @> From 2205f54140b37ef7ffbca35170cdba20369c6789 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sat, 21 Feb 2015 17:52:05 +0100 Subject: [PATCH 06/28] correct title for convert command --- src/Paket/HelpTexts.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index 34e0619f1a..69207edeed 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -44,7 +44,7 @@ type CommandHelpTopic = let commands = ["convert-from-nuget", - { Title = "Convert your solution from NuGet" + { Title = "paket convert-from-nuget" Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Manual process From 10e243052795b62d78b505481daaef77c9bfec86 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sat, 21 Feb 2015 17:58:44 +0100 Subject: [PATCH 07/28] extract helper fun processCommand --- src/Paket/Program.fs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 3093feaa2a..a1bff11341 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -60,6 +60,16 @@ let commandArgs<'T when 'T :> IArgParserTemplate> args = .Parse(inputs = args, raiseOnUsage = false, ignoreMissing = true, errorHandler = ProcessExiter()) +let processCommand<'T when 'T :> IArgParserTemplate> args commandName commandF = + let parser = UnionArgParser.Create<'T>() + let results = + parser.Parse(inputs = args, raiseOnUsage = false, ignoreMissing = true, + errorHandler = ProcessExiter()) + + if results.IsUsageRequested then + parser.Usage(HelpTexts.formatSyntax parser ("paket " + commandName)) |> trace + else + commandF results let showHelp (helpTopic:HelpTexts.CommandHelpTopic) = tracefn "%s" helpTopic.Title @@ -149,18 +159,12 @@ try | _ -> showHelp HelpTexts.commands.["auto-restore"] | Command(Install, args) -> - let parser = UnionArgParser.Create() - let results = - parser.Parse(inputs = args, raiseOnUsage = false, ignoreMissing = true, - errorHandler = ProcessExiter()) - - if results.IsUsageRequested then - parser.Usage(HelpTexts.formatSyntax parser "paket install") |> trace - else - let force = results.Contains <@ InstallArgs.Force @> - let hard = results.Contains <@ InstallArgs.Hard @> - let withBindingRedirects = results.Contains <@ InstallArgs.Redirects @> - Dependencies.Locate().Install(force,hard,withBindingRedirects) + processCommand args "install" + (fun results -> + let force = results.Contains <@ InstallArgs.Force @> + let hard = results.Contains <@ InstallArgs.Hard @> + let withBindingRedirects = results.Contains <@ InstallArgs.Redirects @> + Dependencies.Locate().Install(force,hard,withBindingRedirects)) | Command(Outdated, args) -> let results = commandArgs args From 7706da2905b707fdf32873baebbeb514759df6c7 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sat, 21 Feb 2015 18:49:23 +0100 Subject: [PATCH 08/28] migrate add command --- src/Paket/Commands.fs | 10 +++++++++- src/Paket/HelpTexts.fs | 15 +++------------ src/Paket/Program.fs | 9 +++------ 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index 669849cc62..e3a623041b 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -38,7 +38,15 @@ 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 to Paket's conventions (and hence considered manually managed)." + | No_Install -> "Skips paket install --hard process afterward generation of dependencies / references files." type ConfigArgs = | [] AddCredentials of string diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index 69207edeed..e24b64fa8a 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -17,7 +17,7 @@ let formatCommandSyntax (parser : UnionArgParser<_>) title = let options = parser.Usage() |> replace @"\s\t--help.*" "" - |> replace @"\t([-\w \[\]|\/\?]+):" (System.Environment.NewLine + @" `$1`:") + |> replace @"\t([-\w \[\]|\/\?<>]+):" (System.Environment.NewLine + @" `$1`:") sprintf """ [lang=batchfile] %s @@ -207,19 +207,10 @@ which will ask you to confirm before deleting a dependency from a file."""} "add", { Title = "paket add" - Syntax = formatCommandSyntax (UnionArgParser.Create()) + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Adds a new package to your paket.dependencies file. - [lang=batchfile] - $ paket add nuget PACKAGENAME [version VERSION] [--interactive] [--force] [--hard] - -Options: - - `--interactive`: Asks the user for every project if he or she wants to add the package to the projects's paket.references file. - - `--force`: Forces the download and reinstallation of all packages. - - `--hard`: Replaces package references within project files even if they are not yet adhering to to Paket's conventions (and hence considered manually managed). See [convert from NuGet](paket-convert-from-nuget.html). +<> ## Adding to a single project diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index a1bff11341..78fdba8e3e 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -83,11 +83,8 @@ Option.iter setLogFile logFile try match args with | Command(Add, args) -> - let results = commandArgs args - - if results.IsUsageRequested then - showHelp HelpTexts.commands.["add"] - else + processCommand args "add" + (fun results -> let packageName = results.GetResult <@ AddArgs.Nuget @> let version = defaultArg (results.TryGetResult <@ AddArgs.Version @>) "" let force = results.Contains <@ AddArgs.Force @> @@ -98,7 +95,7 @@ try Dependencies.Locate().AddToProject(packageName, version, force, hard, projectName, noInstall |> not) | None -> let interactive = results.Contains <@ AddArgs.Interactive @> - Dependencies.Locate().Add(packageName, version, force, hard, interactive, noInstall |> not) + Dependencies.Locate().Add(packageName, version, force, hard, interactive, noInstall |> not)) | Command(Config, args) -> let results = commandArgs args From 3586355a1ae53a358d7f479e1a6b05a34d145208 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sat, 21 Feb 2015 18:57:13 +0100 Subject: [PATCH 09/28] migrate auto-restore --- src/Paket/Commands.fs | 5 ++++- src/Paket/HelpTexts.fs | 5 ++--- src/Paket/Program.fs | 11 +++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index e3a623041b..b06e93b0d9 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -80,7 +80,10 @@ type AutoRestoreArgs = | [][] 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 = | [] Force diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index e24b64fa8a..1330003424 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -104,11 +104,10 @@ Consider using [`paket simplify`](paket-simplify.html) to remove unnecessary tra "auto-restore", { Title = "paket auto-restore" - Syntax = formatCommandSyntax (UnionArgParser.Create()) + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Enables or disables automatic Package Restore in Visual Studio during the build process. - [lang=batchfile] - $ paket auto-restore [on|off] +<> Auto-restore on: diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 78fdba8e3e..86678c7f3d 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -145,15 +145,14 @@ try Dependencies.Init() | Command(AutoRestore, args) -> - let results = commandArgs args - - if results.IsUsageRequested then - showHelp HelpTexts.commands.["auto-restore"] - else + processCommand args "add" + (fun results -> match results.GetAllResults() with | [On] -> Dependencies.Locate().TurnOnAutoRestore() | [Off] -> Dependencies.Locate().TurnOffAutoRestore() - | _ -> showHelp HelpTexts.commands.["auto-restore"] + | _ -> + let parser = UnionArgParser.Create() + parser.Usage(HelpTexts.formatSyntax parser "paket auto-restore") |> trace) | Command(Install, args) -> processCommand args "install" From 049666d357c2be6791a2ea8572e5bc380e6cf168 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sat, 21 Feb 2015 19:02:03 +0100 Subject: [PATCH 10/28] migrate config command --- src/Paket/Commands.fs | 4 +++- src/Paket/HelpTexts.fs | 8 +++----- src/Paket/Program.fs | 12 +++++------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index b06e93b0d9..461bfbb327 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -52,7 +52,9 @@ type ConfigArgs = | [] 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 = | [] Force diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index 1330003424..12677e2521 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -399,10 +399,8 @@ Options: `url`: Optionally specify root url of the nuget repository you are pushing too. Defaults to [https://nuget.org](https://nuget.org)."""} "config", { Title = "paket config" - Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """# paket.config file - -Allows to store global configuration values like NuGet credentials. It can be found in: + Syntax = formatCommandSyntax (UnionArgParser.Create()) + Text = """Allows to store global configuration values like NuGet credentials. It can be found in: let AppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) let PaketConfigFolder = Path.Combine(AppDataFolder, "Paket") @@ -412,7 +410,7 @@ Allows to store global configuration values like NuGet credentials. It can be fo Credentials for a specific source can be added with the following command: - paket config add-credentials http://myserver.com/myfeed +<> Paket will then ask for username and password. diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 86678c7f3d..83697901c0 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -98,14 +98,12 @@ try Dependencies.Locate().Add(packageName, version, force, hard, interactive, noInstall |> not)) | Command(Config, args) -> - let results = commandArgs args - - if results.IsUsageRequested then - showHelp HelpTexts.commands.["config"] - else + processCommand args "config" + (fun results -> let args = results.GetResults <@ ConfigArgs.AddCredentials @> if args.Length = 0 then - showHelp HelpTexts.commands.["config"] + let parser = UnionArgParser.Create() + parser.Usage(HelpTexts.formatSyntax parser "paket config") |> trace else let source = args.Item 0 let username = @@ -113,7 +111,7 @@ try args.Item 1 else "" - Dependencies.Locate().AddCredentials(source, username) + Dependencies.Locate().AddCredentials(source, username)) | Command(ConvertFromNuget, args) -> let results = commandArgs args From 7c7017c0f7df65312c590a86b6f43a09c5da99c3 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sat, 21 Feb 2015 19:11:36 +0100 Subject: [PATCH 11/28] migrate convert-from-nuget --- src/Paket/Commands.fs | 7 ++++++- src/Paket/HelpTexts.fs | 17 +++-------------- src/Paket/Program.fs | 9 +++------ 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index 461bfbb327..061dfd26a9 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -63,7 +63,12 @@ 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 = | [][][] Packages of string diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index 12677e2521..6b7fb75b78 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -45,7 +45,7 @@ type CommandHelpTopic = let commands = ["convert-from-nuget", { Title = "paket convert-from-nuget" - Syntax = formatCommandSyntax (UnionArgParser.Create()) + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Manual process If you are already using `NuGet.exe` for package restore then it should be easy to convert to Paket. @@ -75,19 +75,8 @@ Paket can assist you with the conversion. The `paket convert-from-nuget` command
    - [lang=batchfile] - $ paket convert-from-nuget [--force] [--no-install] [--no-auto-restore] [--creds-migration MODE] - -Options: - - `--force`: Forces the conversion, even if a paket.dependencies file or paket.references files are present. - - `--no-install`: Skips [`paket install --hard`](paket-install.html) process afterward generation of dependencies / references files. - - `--no-auto-restore`: Skips [`paket auto-restore`](paket-auto-restore.html) process afterward generation of dependencies / references files. - - `--creds-migration`: Specify mode for migrating NuGet source credentials. Possible values for `MODE` are [`encrypt`|`plaintext`|`selective`]. The default `MODE` is `encrypt`. - +<> + ## Migrating NuGet source credentials If you are using authorized NuGet feeds, convert-from-nuget command will automatically migrate the credentials for you. diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 83697901c0..c4032eff18 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -114,16 +114,13 @@ try Dependencies.Locate().AddCredentials(source, username)) | Command(ConvertFromNuget, args) -> - let results = commandArgs args - - if results.IsUsageRequested then - showHelp HelpTexts.commands.["convert-from-nuget"] - else + processCommand args "convert-from-nuget" + (fun results -> let force = results.Contains <@ ConvertFromNugetArgs.Force @> let noInstall = results.Contains <@ ConvertFromNugetArgs.No_Install @> let noAutoRestore = results.Contains <@ ConvertFromNugetArgs.No_Auto_Restore @> let credsMigrationMode = results.TryGetResult <@ ConvertFromNugetArgs.Creds_Migration @> - Dependencies.ConvertFromNuget(force, noInstall |> not, noAutoRestore |> not, credsMigrationMode) + Dependencies.ConvertFromNuget(force, noInstall |> not, noAutoRestore |> not, credsMigrationMode)) | Command(FindRefs, args) -> let results = commandArgs args From 7c5826eee80365891a9d5b8162558698706b56ab Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sat, 21 Feb 2015 19:23:05 +0100 Subject: [PATCH 12/28] migrate find-refs command --- src/Paket/Commands.fs | 4 +++- src/Paket/HelpTexts.fs | 7 +++---- src/Paket/Program.fs | 9 +++------ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index 061dfd26a9..6d76fa5916 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -74,7 +74,9 @@ type FindRefsArgs = | [][][] Packages of string with interface IArgParserTemplate with - member __.Usage = "" + member this.Usage = + match this with + | Packages(_) -> "List of packages." type InitArgs = | [] NoArg diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index 6b7fb75b78..a8e12477ec 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -17,7 +17,7 @@ let formatCommandSyntax (parser : UnionArgParser<_>) title = let options = parser.Usage() |> replace @"\s\t--help.*" "" - |> replace @"\t([-\w \[\]|\/\?<>]+):" (System.Environment.NewLine + @" `$1`:") + |> replace @"\t([-\w \[\]|\/\?<>\.]+):" (System.Environment.NewLine + @" `$1`:") sprintf """ [lang=batchfile] %s @@ -230,11 +230,10 @@ This will add the package to the selected paket.references files and also to the "find-refs", { Title = "paket find-refs" - Syntax = formatCommandSyntax (UnionArgParser.Create()) + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Finds all project files that have the given NuGet packages installed. - [lang=batchfile] - $ paket find-refs nuget PACKAGENAME1 PACKAGENAME1 ... +<> ## Sample diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index c4032eff18..6b571f3daf 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -123,13 +123,10 @@ try Dependencies.ConvertFromNuget(force, noInstall |> not, noAutoRestore |> not, credsMigrationMode)) | Command(FindRefs, args) -> - let results = commandArgs args - - if results.IsUsageRequested then - showHelp HelpTexts.commands.["find-refs"] - else + processCommand args "find-refs" + (fun results -> let packages = results.GetResults <@ FindRefsArgs.Packages @> - Dependencies.Locate().ShowReferencesFor(packages) + Dependencies.Locate().ShowReferencesFor(packages)) | Command(Init, args) -> let results = commandArgs args From e345a7bfb29b86527fdc226e26b4f9616f1455ae Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sat, 21 Feb 2015 19:25:33 +0100 Subject: [PATCH 13/28] migrate init --- src/Paket/HelpTexts.fs | 5 ++--- src/Paket/Program.fs | 9 +++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index a8e12477ec..5b6e606bad 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -187,11 +187,10 @@ which will ask you to confirm before deleting a dependency from a file."""} "init", { Title = "paket init" - Syntax = formatCommandSyntax (UnionArgParser.Create()) + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Creates empty paket.dependencies file in the working directory. - [lang=batchfile] - $ paket init"""} +<>"""} "add", { Title = "paket add" diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 6b571f3daf..3da8195eaf 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -129,12 +129,9 @@ try Dependencies.Locate().ShowReferencesFor(packages)) | Command(Init, args) -> - let results = commandArgs args - - if results.IsUsageRequested then - showHelp HelpTexts.commands.["init"] - else - Dependencies.Init() + processCommand args "init" + (fun results -> + Dependencies.Init()) | Command(AutoRestore, args) -> processCommand args "add" From 0c429c99b140ff3c3dbd680baf6aa5c0d3ea8d35 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sat, 21 Feb 2015 19:33:53 +0100 Subject: [PATCH 14/28] migrate outdated --- src/Paket/Commands.fs | 5 ++++- src/Paket/HelpTexts.fs | 11 ++--------- src/Paket/Program.fs | 9 +++------ 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index 6d76fa5916..9b292091e6 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -111,7 +111,10 @@ type OutdatedArgs = | [] 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 = | [][] Nuget of string diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index 5b6e606bad..cc5a75c1e3 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -291,17 +291,10 @@ Options: "outdated", { Title = "paket outdated" - Syntax = formatCommandSyntax (UnionArgParser.Create()) + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Lists all dependencies that have newer versions available. - [lang=batchfile] - $ paket outdated [--pre] [--ignore-constraints] - -Options: - - `--pre`: Includes prereleases. - - `--ignore-constraints`: Ignores the version requirement as in the paket.dependencies file. +<> ## Sample diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 3da8195eaf..9dd5b95bdb 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -152,14 +152,11 @@ try Dependencies.Locate().Install(force,hard,withBindingRedirects)) | Command(Outdated, args) -> - let results = commandArgs args - - if results.IsUsageRequested then - showHelp HelpTexts.commands.["outdated"] - else + processCommand args "outdated" + (fun results -> let strict = results.Contains <@ OutdatedArgs.Ignore_Constraints @> |> not let includePrereleases = results.Contains <@ OutdatedArgs.Include_Prereleases @> - Dependencies.Locate().ShowOutdated(strict,includePrereleases) + Dependencies.Locate().ShowOutdated(strict,includePrereleases)) | Command(Remove, args) -> let results = commandArgs args From 8dacac49ab8b4c5ed368b526e6524d6c41eef6e5 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sat, 21 Feb 2015 19:45:54 +0100 Subject: [PATCH 15/28] for rest of commands use processCommand helper fun --- src/Paket/Commands.fs | 80 ++++++++++++++++++++++++++++++++++++++++++ src/Paket/HelpTexts.fs | 72 +++++++------------------------------ src/Paket/Program.fs | 64 ++++++++++----------------------- 3 files changed, 110 insertions(+), 106 deletions(-) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index 9b292091e6..bc651e09e5 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -116,6 +116,21 @@ with | Ignore_Constraints -> "Ignores the version requirement as in the paket.dependencies file." | Include_Prereleases -> "Includes prereleases." +(* + + [lang=batchfile] + $ paket remove nuget PACKAGENAME [--interactive] [--force] [--hard] + +Options: + + `--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. + + `--force`: Forces the download and reinstallation of all packages. + + `--hard`: Replaces package references within project files even if they are not yet adhering to to Paket's conventions (and hence considered manually managed). See [convert from NuGet](paket-convert-from-nuget.html). + +*) + type RemoveArgs = | [][] Nuget of string | [] Project of string @@ -127,6 +142,17 @@ with interface IArgParserTemplate with member __.Usage = "" +(* + [lang=batchfile] + $ paket restore [--force] [--references-files REFERENCESFILE1 REFERENCESFILE2 ...] + +Options: + + `--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 RestoreArgs = | [] Force | [] References_Files of string @@ -134,12 +160,39 @@ with interface IArgParserTemplate with member __.Usage = "" +(* + + [lang=batchfile] + $ paket simplify [-v] [--interactive] + +Options: + + `-v`: Verbose - output the difference in content before and after running simplify command. + + `--interactive`: Asks to confirm to delete every transitive dependency from each of the files. See [Interactive Mode](paket-simplify.html#Interactive-mode). + +*) + type SimplifyArgs = | [] Interactive with interface IArgParserTemplate with member __.Usage = "" +(* + + [lang=batchfile] + $ paket update [--force] [--hard] [--redirects] + +Options: + + `--force`: Forces the download and reinstallation of all packages. + + `--hard`: Replaces package references within project files even if they are not yet adhering to to Paket's conventions (and hence considered manually managed). See [convert from NuGet](paket-convert-from-nuget.html). + + `--redirects`: Creates binding redirects for the NuGet packages. +*) + type UpdateArgs = | [] Nuget of string | [] Version of string @@ -150,6 +203,18 @@ with interface IArgParserTemplate with member __.Usage = "" +(* + + [lang=batchfile] + $ paket pack output outputDirectory [buildconfig Debug] + +Options: + + `output`: Output directory to put nupkgs + + `buildconfig`: Optionally specify build configuration that should be packaged (defaults to Release). +*) + type PackArgs = | [][] Output of string | [] BuildConfig of string @@ -159,6 +224,21 @@ with interface IArgParserTemplate with member __.Usage = "" + +(* + + [lang=batchfile] + $ paket push packagedir path/to/packages [apikey YourApiKey] [url NuGetFeed] + +Options: + + `packagedir`: a directory; every `.nupkg` file in this directory or it's children will be pushed. + + `apikey`: Optionally specify your API key on the command line. Otherwise uses the value of the `nugetkey` environment variable. + + `url`: Optionally specify root url of the nuget repository you are pushing too. Defaults to [https://nuget.org](https://nuget.org). +*) + type PushArgs = | [][] Url of string | [][] FileName of string diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index cc5a75c1e3..8036a8aff3 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -111,32 +111,18 @@ Auto-restore off: "restore", { Title = "paket restore" - Syntax = formatCommandSyntax (UnionArgParser.Create()) + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Ensures that all dependencies in your paket.dependencies file are present in the `packages` directory . - [lang=batchfile] - $ paket restore [--force] [--references-files REFERENCESFILE1 REFERENCESFILE2 ...] - -Options: - - `--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."""} +<>"""} "simplify", { Title = "paket simplify" - Syntax = formatCommandSyntax (UnionArgParser.Create()) + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Simplifies your paket.dependencies file by removing transitive dependencies. Does also simplify paket.references files, unless [strict](dependencies-file.html#Strict-references) mode is used. - [lang=batchfile] - $ paket simplify [-v] [--interactive] - -Options: - - `-v`: Verbose - output the difference in content before and after running simplify command. - - `--interactive`: Asks to confirm to delete every transitive dependency from each of the files. See [Interactive Mode](paket-simplify.html#Interactive-mode). +<> ## Sample @@ -262,19 +248,10 @@ and paket gives the following output: "update", { Title = "paket update" - Syntax = formatCommandSyntax (UnionArgParser.Create()) + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Recomputes the dependency resolution, updates the paket.lock file and propagates any resulting package changes into all project files referencing updated packages. - [lang=batchfile] - $ paket update [--force] [--hard] [--redirects] - -Options: - - `--force`: Forces the download and reinstallation of all packages. - - `--hard`: Replaces package references within project files even if they are not yet adhering to to Paket's conventions (and hence considered manually managed). See [convert from NuGet](paket-convert-from-nuget.html). - - `--redirects`: Creates binding redirects for the NuGet packages. +<> ## Updating a single package @@ -320,19 +297,10 @@ Now we run `paket outdated`: "remove", { Title = "paket remove" - Syntax = formatCommandSyntax (UnionArgParser.Create()) + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Removes a package from your paket.dependencies file and all paket.references files. - [lang=batchfile] - $ paket remove nuget PACKAGENAME [--interactive] [--force] [--hard] - -Options: - - `--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. - - `--force`: Forces the download and reinstallation of all packages. - - `--hard`: Replaces package references within project files even if they are not yet adhering to to Paket's conventions (and hence considered manually managed). See [convert from NuGet](paket-convert-from-nuget.html). +<> ## Removing from a single project @@ -351,32 +319,16 @@ See also [paket add](paket-add.html)."""} <>"""} "pack", { Title = "paket pack" - Syntax = formatCommandSyntax (UnionArgParser.Create()) + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Packs all paket.template files within this repository - [lang=batchfile] - $ paket pack output outputDirectory [buildconfig Debug] - -Options: - - `output`: Output directory to put nupkgs - - `buildconfig`: Optionally specify build configuration that should be packaged (defaults to Release)."""} +<>"""} "push", { Title = "paket push" - Syntax = formatCommandSyntax (UnionArgParser.Create()) + Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Pushes all `.nupkg` files from the given directory. - [lang=batchfile] - $ paket push packagedir path/to/packages [apikey YourApiKey] [url NuGetFeed] - -Options: - - `packagedir`: a directory; every `.nupkg` file in this directory or it's children will be pushed. - - `apikey`: Optionally specify your API key on the command line. Otherwise uses the value of the `nugetkey` environment variable. - - `url`: Optionally specify root url of the nuget repository you are pushing too. Defaults to [https://nuget.org](https://nuget.org)."""} +<>"""} "config", { Title = "paket config" Syntax = formatCommandSyntax (UnionArgParser.Create()) diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 9dd5b95bdb..e68a248e5f 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -54,12 +54,6 @@ let filterGlobalArgs args = verbose, logFile, rest - -let commandArgs<'T when 'T :> IArgParserTemplate> args = - UnionArgParser.Create<'T>() - .Parse(inputs = args, raiseOnUsage = false, ignoreMissing = true, - errorHandler = ProcessExiter()) - let processCommand<'T when 'T :> IArgParserTemplate> args commandName commandF = let parser = UnionArgParser.Create<'T>() let results = @@ -71,10 +65,6 @@ let processCommand<'T when 'T :> IArgParserTemplate> args commandName commandF = else commandF results -let showHelp (helpTopic:HelpTexts.CommandHelpTopic) = - tracefn "%s" helpTopic.Title - tracefn "%s" helpTopic.Text - let v, logFile, args = filterGlobalArgs (Environment.GetCommandLineArgs().[1..]) Logging.verbose <- v @@ -159,11 +149,8 @@ try Dependencies.Locate().ShowOutdated(strict,includePrereleases)) | Command(Remove, args) -> - let results = commandArgs args - - if results.IsUsageRequested then - showHelp HelpTexts.commands.["remove"] - else + processCommand args "remove" + (fun results -> let packageName = results.GetResult <@ RemoveArgs.Nuget @> let force = results.Contains <@ RemoveArgs.Force @> let hard = results.Contains <@ RemoveArgs.Hard @> @@ -173,33 +160,24 @@ try Dependencies.Locate().RemoveFromProject(packageName, force, hard, projectName, noInstall |> not) | None -> let interactive = results.Contains <@ RemoveArgs.Interactive @> - Dependencies.Locate().Remove(packageName, force, hard, interactive, noInstall |> not) + Dependencies.Locate().Remove(packageName, force, hard, interactive, noInstall |> not)) | Command(Restore, args) -> - let results = commandArgs args - - if results.IsUsageRequested then - showHelp HelpTexts.commands.["restore"] - else + processCommand args "restore" + (fun results -> let force = results.Contains <@ RestoreArgs.Force @> let files = results.GetResults <@ RestoreArgs.References_Files @> - Dependencies.Locate().Restore(force,files) + Dependencies.Locate().Restore(force,files)) | Command(Simplify, args) -> - let results = commandArgs args - - if results.IsUsageRequested then - showHelp HelpTexts.commands.["simplify"] - else + processCommand args "simplify" + (fun results -> let interactive = results.Contains <@ SimplifyArgs.Interactive @> - Dependencies.Simplify(interactive) + Dependencies.Simplify(interactive)) | Command(Update, args) -> - let results = commandArgs args - - if results.IsUsageRequested then - showHelp HelpTexts.commands.["update"] - else + processCommand args "update" + (fun results -> let hard = results.Contains <@ UpdateArgs.Hard @> let force = results.Contains <@ UpdateArgs.Force @> match results.TryGetResult <@ UpdateArgs.Nuget @> with @@ -208,30 +186,24 @@ try Dependencies.Locate().UpdatePackage(packageName, version, force, hard) | _ -> let withBindingRedirects = results.Contains <@ UpdateArgs.Redirects @> - Dependencies.Locate().Update(force,hard,withBindingRedirects) + Dependencies.Locate().Update(force,hard,withBindingRedirects)) | Command(Pack, args) -> - let results = commandArgs args - - if results.IsUsageRequested then - showHelp HelpTexts.commands.["pack"] - else + processCommand args "pack" + (fun results -> let outputPath = results.GetResult <@ PackArgs.Output @> Dependencies.Locate().Pack( outputPath, ?buildConfig = results.TryGetResult <@ PackArgs.BuildConfig @>, ?version = results.TryGetResult <@ PackArgs.Version @>, - ?releaseNotes = results.TryGetResult <@ PackArgs.ReleaseNotes @>) + ?releaseNotes = results.TryGetResult <@ PackArgs.ReleaseNotes @>)) | Command(Push, args) -> - let results = commandArgs args - - if results.IsUsageRequested then - showHelp HelpTexts.commands.["push"] - else + processCommand args "push" + (fun results -> let fileName = results.GetResult <@ PushArgs.FileName @> Dependencies.Locate().Push( fileName, ?url = results.TryGetResult <@ PushArgs.Url @>, - ?apiKey = results.TryGetResult <@ PushArgs.ApiKey @>) + ?apiKey = results.TryGetResult <@ PushArgs.ApiKey @>)) | _ -> let allCommands = Microsoft.FSharp.Reflection.FSharpType.GetUnionCases(typeof) From cc418701c1a27f6d0c6ed2121ec318c1d3726c4c Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sat, 21 Feb 2015 19:50:53 +0100 Subject: [PATCH 16/28] fill in a 2 more command args - 4 yet to go --- src/Paket/Commands.fs | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index bc651e09e5..8b076a13a1 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -116,21 +116,6 @@ with | Ignore_Constraints -> "Ignores the version requirement as in the paket.dependencies file." | Include_Prereleases -> "Includes prereleases." -(* - - [lang=batchfile] - $ paket remove nuget PACKAGENAME [--interactive] [--force] [--hard] - -Options: - - `--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. - - `--force`: Forces the download and reinstallation of all packages. - - `--hard`: Replaces package references within project files even if they are not yet adhering to to Paket's conventions (and hence considered manually managed). See [convert from NuGet](paket-convert-from-nuget.html). - -*) - type RemoveArgs = | [][] Nuget of string | [] Project of string @@ -140,25 +125,24 @@ type RemoveArgs = | No_Install with interface IArgParserTemplate with - member __.Usage = "" - -(* - [lang=batchfile] - $ paket restore [--force] [--references-files REFERENCESFILE1 REFERENCESFILE2 ...] - -Options: - - `--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. - *) + 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 -> "sks 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 to Paket's conventions (and hence considered manually managed)." + | No_Install -> "Skips paket install --hard process afterward generation of dependencies / references files." type RestoreArgs = | [] Force | [] 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." (* From f52afbd83e81c4b089d76bd2a41aeed0ee19adfa Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sun, 22 Feb 2015 09:07:16 +0100 Subject: [PATCH 17/28] fix typos --- src/Paket/Commands.fs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index 8b076a13a1..047ef3701b 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -45,7 +45,7 @@ with | 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 to Paket's conventions (and hence considered manually managed)." + | 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 = @@ -103,7 +103,7 @@ with 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 Paket's conventions (and hence considered manually managed)." + | 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 = @@ -130,8 +130,8 @@ 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 -> "sks 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 to Paket's conventions (and hence considered manually managed)." + | 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 = @@ -172,7 +172,7 @@ Options: `--force`: Forces the download and reinstallation of all packages. - `--hard`: Replaces package references within project files even if they are not yet adhering to to Paket's conventions (and hence considered manually managed). See [convert from NuGet](paket-convert-from-nuget.html). + `--hard`: Replaces package references within project files even if they are not yet adhering to the Paket's conventions (and hence considered manually managed). See [convert from NuGet](paket-convert-from-nuget.html). `--redirects`: Creates binding redirects for the NuGet packages. *) From 7682922fa85fd2c65d7d0a01aaa92efe609d2e56 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sun, 22 Feb 2015 09:21:25 +0100 Subject: [PATCH 18/28] fill the args for remaining commands --- src/Paket/Commands.fs | 79 ++++++++++++------------------------------- 1 file changed, 21 insertions(+), 58 deletions(-) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index 047ef3701b..4090e2f061 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -144,38 +144,13 @@ 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." -(* - - [lang=batchfile] - $ paket simplify [-v] [--interactive] - -Options: - - `-v`: Verbose - output the difference in content before and after running simplify command. - - `--interactive`: Asks to confirm to delete every transitive dependency from each of the files. See [Interactive Mode](paket-simplify.html#Interactive-mode). - -*) - type SimplifyArgs = | [] Interactive with interface IArgParserTemplate with - member __.Usage = "" - -(* - - [lang=batchfile] - $ paket update [--force] [--hard] [--redirects] - -Options: - - `--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). See [convert from NuGet](paket-convert-from-nuget.html). - - `--redirects`: Creates binding redirects for the NuGet packages. -*) + member this.Usage = + match this with + | Interactive -> "Asks to confirm to delete every transitive dependency from each of the files." type UpdateArgs = | [] Nuget of string @@ -185,19 +160,13 @@ type UpdateArgs = | Redirects with interface IArgParserTemplate with - member __.Usage = "" - -(* - - [lang=batchfile] - $ paket pack output outputDirectory [buildconfig Debug] - -Options: - - `output`: Output directory to put nupkgs - - `buildconfig`: Optionally specify build configuration that should be packaged (defaults to Release). -*) + 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 = | [][] Output of string @@ -206,22 +175,12 @@ type PackArgs = | [] ReleaseNotes of string with interface IArgParserTemplate with - member __.Usage = "" - - -(* - - [lang=batchfile] - $ paket push packagedir path/to/packages [apikey YourApiKey] [url NuGetFeed] - -Options: - - `packagedir`: a directory; every `.nupkg` file in this directory or it's children will be pushed. - - `apikey`: Optionally specify your API key on the command line. Otherwise uses the value of the `nugetkey` environment variable. - - `url`: Optionally specify root url of the nuget repository you are pushing too. Defaults to [https://nuget.org](https://nuget.org). -*) + member this.Usage = + 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 = | [][] Url of string @@ -229,4 +188,8 @@ type PushArgs = | [] ApiKey of string with interface IArgParserTemplate with - member __.Usage = "" \ No newline at end of file + member this.Usage = + 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." \ No newline at end of file From 182ede16e6bede3badd0770fdd7e5f6d9d0d366c Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sun, 22 Feb 2015 11:50:51 +0100 Subject: [PATCH 19/28] canonicalize convert-from-nuget command docs --- docs/content/faq.md | 9 ++++++++- src/Paket/HelpTexts.fs | 19 ++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/content/faq.md b/docs/content/faq.md index a7c5225b6b..8fc9ffc0dd 100644 --- a/docs/content/faq.md +++ b/docs/content/faq.md @@ -54,7 +54,14 @@ Instead we encourage the .NET community to use a declarative install process and ## I'm already using NuGet. How can I convert to Paket? -The process is very easy and you can read more about it in the [convert from NuGet](paket-convert-from-nuget.html) section. +The process can be automated with [paket convert-from-nuget](paket-convert-from-nuget.html) command. + +In case of the command's failure, you can fallback to manual approach: + +1. Analyse your `packages.config` files and extract the referenced packages into a paket.dependencies file. +2. Convert each `packages.config` file to a paket.references file. This is very easy - you just have to remove all the XML and keep the package names. +3. Run [paket install](paket-install.html) with the `--hard` flag. This will analyze the dependencies, generate a paket.lock file, remove all the old package references from your project files and replace them with equivalent `Reference`s in a syntax that can be managed automatically by Paket. +4. (Optional) Raise corresponding issue [here](https://github.com/fsprojects/Paket/issues) so that we can make the comand even better. ## Why should I commit the lock file? diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index 8036a8aff3..b48cfec825 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -42,22 +42,19 @@ type CommandHelpTopic = sprintf "# %s%s%s" this.Title System.Environment.NewLine text -let commands = +let commands = ["convert-from-nuget", { Title = "paket convert-from-nuget" Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """## Manual process + Text = """Converts from using NuGet to Paket. -If you are already using `NuGet.exe` for package restore then it should be easy to convert to Paket. +
    -1. Analyse your `packages.config` files and extract the referenced packages into a paket.dependencies file. -2. Convert each `packages.config` file to a paket.references file. This is very easy - you just have to remove all the XML and keep the package names. -3. Run [paket install](paket-install.html) with the `--hard` flag. This will analyze the dependencies, generate a paket.lock file, remove all the old package references from your project files and replace them with equivalent `Reference`s in a syntax that can be managed automatically by Paket. +<> -
    -## Automated process +## Command steps -Paket can assist you with the conversion. The `paket convert-from-nuget` command: +The `paket convert-from-nuget` command: 1. Finds all `packages.config` files, generates a paket.dependencies file in the solution root and replaces each `packages.config` with an equivalent paket.references file. 2. If there is a solution-level `packages.config`, then it will be removed and its dependencies will be included into the paket.dependencies file. @@ -72,10 +69,6 @@ Paket can assist you with the conversion. The `paket convert-from-nuget` command - add any newly discovered dependencies to the end of an existing `paket.dependencies` file. - transfer/append references from the `packages.config` files into `paket.references` files alongside. - -
    - -<> ## Migrating NuGet source credentials From 5c2cdb622b7049c58da007df1a348e61a71f77f4 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sun, 22 Feb 2015 11:54:50 +0100 Subject: [PATCH 20/28] make commands from HelpTexts lazy --- docs/tools/generate.fsx | 2 +- src/Paket/HelpTexts.fs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/tools/generate.fsx b/docs/tools/generate.fsx index 1ae93b84a6..d7b457a394 100644 --- a/docs/tools/generate.fsx +++ b/docs/tools/generate.fsx @@ -3,7 +3,7 @@ #r "../../bin/Paket.exe" open System.IO -Paket.HelpTexts.commands +Paket.HelpTexts.commands.Force() |> Seq.iter (fun kv -> File.WriteAllText(sprintf "../content/paket-%s.md" kv.Key,kv.Value.ToMarkDown())) // -------------------------------------------------------------------------------------- diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index b48cfec825..93fe2b18ee 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -43,6 +43,7 @@ type CommandHelpTopic = sprintf "# %s%s%s" this.Title System.Environment.NewLine text let commands = + lazy ["convert-from-nuget", { Title = "paket convert-from-nuget" Syntax = formatCommandSyntax (UnionArgParser.Create()) From 8d7c6774779c6a7600977cc978c31406cf671d21 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sun, 22 Feb 2015 12:37:54 +0100 Subject: [PATCH 21/28] print usage for Command DU --- src/Paket/Commands.fs | 2 +- src/Paket/Program.fs | 17 ++--------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index 4090e2f061..3034e0c7db 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -19,7 +19,7 @@ type Command = | [][] Push with interface IArgParserTemplate with - member __.Usage = "" + member __.Usage = "Converts from using NuGet to Paket." type GlobalArgs = | [] Verbose diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index e68a248e5f..f53037f8df 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -205,21 +205,8 @@ try ?url = results.TryGetResult <@ PushArgs.Url @>, ?apiKey = results.TryGetResult <@ PushArgs.ApiKey @>)) | _ -> - let allCommands = - Microsoft.FSharp.Reflection.FSharpType.GetUnionCases(typeof) - |> Array.map (fun command -> - let attr = - command.GetCustomAttributes(typeof) - |> Seq.cast - |> Seq.head - attr.Name) - |> String.concat Environment.NewLine - - tracefn "available commands: %s%s%s%s" - Environment.NewLine - Environment.NewLine - allCommands - Environment.NewLine + let parser = UnionArgParser.Create() + parser.Usage("available commands:") |> trace let elapsedTime = Utils.TimeSpanToReadableString stopWatch.Elapsed tracefn "%s - ready." elapsedTime From eb1014652ac0cf9526ba69525aea3eb1478dd942 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sun, 22 Feb 2015 13:17:08 +0100 Subject: [PATCH 22/28] read command name from attribute --- src/Paket/Program.fs | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index f53037f8df..53e0c1d3e0 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -1,6 +1,7 @@ /// [omit] module Paket.Program +open Microsoft.FSharp.Reflection open System open System.Diagnostics open System.Reflection @@ -54,14 +55,25 @@ let filterGlobalArgs args = verbose, logFile, rest -let processCommand<'T when 'T :> IArgParserTemplate> args commandName commandF = +let processCommand<'T when 'T :> IArgParserTemplate> (command : Command) args commandF = + let uci,_ = FSharpValue.GetUnionFields(command, typeof) + let commandName = + (uci.GetCustomAttributes(typeof) + |> Seq.head + :?> CustomCommandLineAttribute).Name + let parser = UnionArgParser.Create<'T>() let results = parser.Parse(inputs = args, raiseOnUsage = false, ignoreMissing = true, errorHandler = ProcessExiter()) if results.IsUsageRequested then - parser.Usage(HelpTexts.formatSyntax parser ("paket " + commandName)) |> trace + parser.Usage( + "Paket " + commandName + + Environment.NewLine + Environment.NewLine + + (command :> IArgParserTemplate).Usage + + Environment.NewLine + Environment.NewLine + + HelpTexts.formatSyntax parser ("paket " + commandName)) |> trace else commandF results @@ -73,7 +85,7 @@ Option.iter setLogFile logFile try match args with | Command(Add, args) -> - processCommand args "add" + processCommand Add args (fun results -> let packageName = results.GetResult <@ AddArgs.Nuget @> let version = defaultArg (results.TryGetResult <@ AddArgs.Version @>) "" @@ -88,7 +100,7 @@ try Dependencies.Locate().Add(packageName, version, force, hard, interactive, noInstall |> not)) | Command(Config, args) -> - processCommand args "config" + processCommand Config args (fun results -> let args = results.GetResults <@ ConfigArgs.AddCredentials @> if args.Length = 0 then @@ -104,7 +116,7 @@ try Dependencies.Locate().AddCredentials(source, username)) | Command(ConvertFromNuget, args) -> - processCommand args "convert-from-nuget" + processCommand ConvertFromNuget args (fun results -> let force = results.Contains <@ ConvertFromNugetArgs.Force @> let noInstall = results.Contains <@ ConvertFromNugetArgs.No_Install @> @@ -113,18 +125,18 @@ try Dependencies.ConvertFromNuget(force, noInstall |> not, noAutoRestore |> not, credsMigrationMode)) | Command(FindRefs, args) -> - processCommand args "find-refs" + processCommand FindRefs args (fun results -> let packages = results.GetResults <@ FindRefsArgs.Packages @> Dependencies.Locate().ShowReferencesFor(packages)) | Command(Init, args) -> - processCommand args "init" + processCommand Init args (fun results -> Dependencies.Init()) | Command(AutoRestore, args) -> - processCommand args "add" + processCommand AutoRestore args (fun results -> match results.GetAllResults() with | [On] -> Dependencies.Locate().TurnOnAutoRestore() @@ -134,7 +146,7 @@ try parser.Usage(HelpTexts.formatSyntax parser "paket auto-restore") |> trace) | Command(Install, args) -> - processCommand args "install" + processCommand Install args (fun results -> let force = results.Contains <@ InstallArgs.Force @> let hard = results.Contains <@ InstallArgs.Hard @> @@ -142,14 +154,14 @@ try Dependencies.Locate().Install(force,hard,withBindingRedirects)) | Command(Outdated, args) -> - processCommand args "outdated" + processCommand Outdated args (fun results -> let strict = results.Contains <@ OutdatedArgs.Ignore_Constraints @> |> not let includePrereleases = results.Contains <@ OutdatedArgs.Include_Prereleases @> Dependencies.Locate().ShowOutdated(strict,includePrereleases)) | Command(Remove, args) -> - processCommand args "remove" + processCommand Remove args (fun results -> let packageName = results.GetResult <@ RemoveArgs.Nuget @> let force = results.Contains <@ RemoveArgs.Force @> @@ -163,20 +175,20 @@ try Dependencies.Locate().Remove(packageName, force, hard, interactive, noInstall |> not)) | Command(Restore, args) -> - processCommand args "restore" + processCommand Restore args (fun results -> let force = results.Contains <@ RestoreArgs.Force @> let files = results.GetResults <@ RestoreArgs.References_Files @> Dependencies.Locate().Restore(force,files)) | Command(Simplify, args) -> - processCommand args "simplify" + processCommand Simplify args (fun results -> let interactive = results.Contains <@ SimplifyArgs.Interactive @> Dependencies.Simplify(interactive)) | Command(Update, args) -> - processCommand args "update" + processCommand Update args (fun results -> let hard = results.Contains <@ UpdateArgs.Hard @> let force = results.Contains <@ UpdateArgs.Force @> @@ -188,7 +200,7 @@ try let withBindingRedirects = results.Contains <@ UpdateArgs.Redirects @> Dependencies.Locate().Update(force,hard,withBindingRedirects)) | Command(Pack, args) -> - processCommand args "pack" + processCommand Pack args (fun results -> let outputPath = results.GetResult <@ PackArgs.Output @> Dependencies.Locate().Pack( @@ -197,7 +209,7 @@ try ?version = results.TryGetResult <@ PackArgs.Version @>, ?releaseNotes = results.TryGetResult <@ PackArgs.ReleaseNotes @>)) | Command(Push, args) -> - processCommand args "push" + processCommand Push args (fun results -> let fileName = results.GetResult <@ PushArgs.FileName @> Dependencies.Locate().Push( From a900114ae4a6a02883718fd6a0e9d7b0272a75f9 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sun, 22 Feb 2015 13:24:09 +0100 Subject: [PATCH 23/28] fill usages for Command DU --- src/Paket/Commands.fs | 17 ++++++++++++++++- src/Paket/HelpTexts.fs | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index 3034e0c7db..d030e46dac 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -19,7 +19,22 @@ type Command = | [][] Push with interface IArgParserTemplate with - member __.Usage = "Converts from using NuGet to Paket." + 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." type GlobalArgs = | [] Verbose diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index 93fe2b18ee..f0c3e5b590 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -114,10 +114,11 @@ Auto-restore off: { Title = "paket simplify" Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Simplifies your paket.dependencies file by removing transitive dependencies. -Does also simplify paket.references files, unless [strict](dependencies-file.html#Strict-references) mode is used. <> +Simplify will also affect paket.references files, unless [strict](dependencies-file.html#Strict-references) mode is used. + ## Sample When you install `Castle.Windsor` package in NuGet to a project, it will generate a following `packages.config` file in the project location: From 2960a52e27e380c47cca4c497563e9d1bbe5a874 Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sun, 22 Feb 2015 13:31:39 +0100 Subject: [PATCH 24/28] canonicalize config command documentation --- src/Paket/HelpTexts.fs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index f0c3e5b590..a9dda27ef9 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -327,20 +327,19 @@ See also [paket add](paket-add.html)."""} "config", { Title = "paket config" Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Allows to store global configuration values like NuGet credentials. It can be found in: - - let AppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) - let PaketConfigFolder = Path.Combine(AppDataFolder, "Paket") - let PaketConfigFile = Path.Combine(PaketConfigFolder, "paket.config") - -## Add credentials - -Credentials for a specific source can be added with the following command: + Text = """Allows to store global configuration values like NuGet credentials. <> Paket will then ask for username and password. -This credentials will be used if no username and password for the source are configured in the [`paket.dependencies` file](nuget-dependencies.html)."""}] +This credentials will be used if no username and password for the source are configured in the [`paket.dependencies` file](nuget-dependencies.html). + +The configuration file can be found in: + + let AppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + let PaketConfigFolder = Path.Combine(AppDataFolder, "Paket") + let PaketConfigFile = Path.Combine(PaketConfigFolder, "paket.config") +"""}] |> dict From 95bed5340dd7133a62884f447f8f7ca456b5523a Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sun, 22 Feb 2015 13:51:44 +0100 Subject: [PATCH 25/28] extract syntax docs --- src/Paket/HelpTexts.fs | 134 +++++++++++++++-------------------------- src/Paket/Program.fs | 8 +-- 2 files changed, 51 insertions(+), 91 deletions(-) diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index a9dda27ef9..d483926bec 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -4,12 +4,15 @@ open Paket.Commands open Nessos.UnionArgParser +let commandName (command : Command) = + let uci,_ = Microsoft.FSharp.Reflection.FSharpValue.GetUnionFields(command, typeof) + (uci.GetCustomAttributes(typeof) + |> Seq.head + :?> CustomCommandLineAttribute).Name + let formatSyntax (parser:UnionArgParser<'TArgs>) commandName = "$ " + commandName + " " + parser.PrintCommandLineSyntax() -let formatUsage (parser:UnionArgParser<'TArgs>) commandName = - parser.Usage(formatSyntax parser commandName) - let replace (pattern : string) (replacement : string) input = System.Text.RegularExpressions.Regex.Replace(input, pattern, replacement) @@ -27,33 +30,38 @@ Options: options type CommandHelpTopic = - { Title : string + { Command : Command Syntax : string -> string Text : string } member this.ToMarkDown() = - let text = - this.Text - .Replace("<>", this.Syntax this.Title) + 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)") - sprintf "# %s%s%s" this.Title System.Environment.NewLine text + sprintf + "# %s%s%s%s%s%s%s%s%s%s" + ("paket " + (commandName this.Command)) + System.Environment.NewLine + System.Environment.NewLine + (this.Command :> IArgParserTemplate).Usage + System.Environment.NewLine + System.Environment.NewLine + (this.Syntax (commandName this.Command)) + System.Environment.NewLine + System.Environment.NewLine + this.Text + |> replaceLinks let commands = lazy ["convert-from-nuget", - { Title = "paket convert-from-nuget" + { Command = ConvertFromNuget Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Converts from using NuGet to Paket. - -
    - -<> - -## Command steps + Text = """## Command steps The `paket convert-from-nuget` command: @@ -86,13 +94,9 @@ After converting your solution from NuGet, you may end up with many transitive d Consider using [`paket simplify`](paket-simplify.html) to remove unnecessary transitive dependencies from your paket.dependencies file and paket.references files."""} "auto-restore", - { Title = "paket auto-restore" + { Command = AutoRestore Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Enables or disables automatic Package Restore in Visual Studio during the build process. - -<> - -Auto-restore on: + Text = """Auto-restore on: - creates a `.paket` directory in your root directory, - downloads `paket.targets` and `paket.bootstrapper.exe` into the `.paket` directory, @@ -104,20 +108,14 @@ Auto-restore off: - removes the `` statement for `paket.targets` from projects that have the [references file](references-files.html)."""} "restore", - { Title = "paket restore" + { Command = Restore Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Ensures that all dependencies in your paket.dependencies file are present in the `packages` directory . - -<>"""} + Text = """"""} "simplify", - { Title = "paket simplify" + { Command = Simplify Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Simplifies your paket.dependencies file by removing transitive dependencies. - -<> - -Simplify will also affect paket.references files, unless [strict](dependencies-file.html#Strict-references) mode is used. + Text = """Simplify will also affect paket.references files, unless [strict](dependencies-file.html#Strict-references) mode is used. ## Sample @@ -167,20 +165,14 @@ Sometimes, you may still want to have control over some of the transitive depend which will ask you to confirm before deleting a dependency from a file."""} "init", - { Title = "paket init" + { Command = Init Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Creates empty paket.dependencies file in the working directory. - -<>"""} + Text = """"""} "add", - { Title = "paket add" + { Command = Add Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Adds a new package to your paket.dependencies file. - -<> - -## Adding to a single project + Text = """## Adding to a single project It's also possible to add a package to a specified project only: @@ -209,13 +201,9 @@ This will add the package to the selected paket.references files and also to the nuget xunit"""} "find-refs", - { Title = "paket find-refs" + { Command = FindRefs Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Finds all project files that have the given NuGet packages installed. - -<> - -## Sample + Text = """## Sample *.src/Paket/paket.references* contains: @@ -242,13 +230,9 @@ and paket gives the following output: .src/Paket/Paket.fsproj"""} "update", - { Title = "paket update" + { Command = Update Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Recomputes the dependency resolution, updates the paket.lock file and propagates any resulting package changes into all project files referencing updated packages. - -<> - -## Updating a single package + Text = """## Updating a single package It's also possible to update only a single package and to keep all other dependencies fixed: @@ -262,13 +246,9 @@ Options: `--hard`: Replaces package references within project files even if they are not yet adhering to to Paket's conventions (and hence considered manually managed). See [convert from NuGet](paket-convert-from-nuget.html)."""} "outdated", - { Title = "paket outdated" + { Command = Outdated Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Lists all dependencies that have newer versions available. - -<> - -## Sample + Text = """## Sample Consider the following paket.dependencies file: @@ -291,13 +271,9 @@ Now we run `paket outdated`: ![alt text](img/paket-outdated.png "paket outdated command")"""} "remove", - { Title = "paket remove" + { Command = Remove Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Removes a package from your paket.dependencies file and all paket.references files. - -<> - -## Removing from a single project + Text = """## Removing from a single project It's also possible to remove a package from a specified project only: @@ -307,31 +283,21 @@ It's also possible to remove a package from a specified project only: See also [paket add](paket-add.html)."""} "install", - { Title = "paket install" + { Command = Install Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Ensures that all dependencies in your paket.dependencies file are present in the `packages` directory and referenced correctly in all projects. - -<>"""} + Text = """"""} "pack", - { Title = "paket pack" + { Command = Pack Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Packs all paket.template files within this repository - -<>"""} + Text = """"""} "push", - { Title = "paket push" + { Command = Push Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Pushes all `.nupkg` files from the given directory. - -<>"""} + Text = """"""} "config", - { Title = "paket config" + { Command = Config Syntax = formatCommandSyntax (UnionArgParser.Create()) - Text = """Allows to store global configuration values like NuGet credentials. - -<> - -Paket will then ask for username and password. + Text = """Paket will then ask for username and password. This credentials will be used if no username and password for the source are configured in the [`paket.dependencies` file](nuget-dependencies.html). diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 53e0c1d3e0..3bcf524b9c 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -1,7 +1,6 @@ /// [omit] module Paket.Program -open Microsoft.FSharp.Reflection open System open System.Diagnostics open System.Reflection @@ -56,12 +55,7 @@ let filterGlobalArgs args = verbose, logFile, rest let processCommand<'T when 'T :> IArgParserTemplate> (command : Command) args commandF = - let uci,_ = FSharpValue.GetUnionFields(command, typeof) - let commandName = - (uci.GetCustomAttributes(typeof) - |> Seq.head - :?> CustomCommandLineAttribute).Name - + let commandName = HelpTexts.commandName command let parser = UnionArgParser.Create<'T>() let results = parser.Parse(inputs = args, raiseOnUsage = false, ignoreMissing = true, From f202192ffed645c9b286e36e4fce9bfcd71d349f Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sun, 22 Feb 2015 17:43:02 +0100 Subject: [PATCH 26/28] cleanup Program.fs --- src/Paket/Program.fs | 321 +++++++++++++++++++++---------------------- 1 file changed, 156 insertions(+), 165 deletions(-) diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 3bcf524b9c..575ba05b8b 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -18,20 +18,6 @@ let assembly = Assembly.GetExecutingAssembly() let fvi = FileVersionInfo.GetVersionInfo(assembly.Location); tracefn "Paket version %s" fvi.FileVersion -let (|Command|_|) args = - let results = - UnionArgParser.Create() - .Parse(inputs = args, - ignoreMissing = true, - ignoreUnrecognized = true, - raiseOnUsage = false) - - match results.GetAllResults() with - | [ command ] -> Some (command, args.[1..]) - | [] -> None - | _ -> failwith "expected only one command" - - let filterGlobalArgs args = let globalResults = UnionArgParser.Create() @@ -54,172 +40,177 @@ let filterGlobalArgs args = verbose, logFile, rest -let processCommand<'T when 'T :> IArgParserTemplate> (command : Command) args commandF = - let commandName = HelpTexts.commandName command +let processWithValidation<'T when 'T :> IArgParserTemplate> validateF commandF commandName usage + args = let parser = UnionArgParser.Create<'T>() let results = - parser.Parse(inputs = args, raiseOnUsage = false, ignoreMissing = true, - errorHandler = ProcessExiter()) - - if results.IsUsageRequested then - parser.Usage( - "Paket " + commandName + - Environment.NewLine + Environment.NewLine + - (command :> IArgParserTemplate).Usage + - Environment.NewLine + Environment.NewLine + - HelpTexts.formatSyntax parser ("paket " + commandName)) |> trace - else + parser.Parse + (inputs = args, raiseOnUsage = false, ignoreMissing = true, + errorHandler = ProcessExiter()) + let resultsValid = validateF (results) + if results.IsUsageRequested || not resultsValid then + parser.Usage + ("Paket " + commandName + Environment.NewLine + Environment.NewLine + usage + + Environment.NewLine + Environment.NewLine + + HelpTexts.formatSyntax parser ("paket " + commandName)) |> trace + else commandF results + let elapsedTime = Utils.TimeSpanToReadableString stopWatch.Elapsed + tracefn "%s - ready." elapsedTime + +let processCommand<'T when 'T :> IArgParserTemplate> (commandF : ArgParseResults<'T> -> unit) = + processWithValidation (fun _ -> true) commandF let v, logFile, args = filterGlobalArgs (Environment.GetCommandLineArgs().[1..]) Logging.verbose <- v Option.iter setLogFile logFile -try - match args with - | Command(Add, args) -> - processCommand Add args - (fun results -> - let packageName = results.GetResult <@ AddArgs.Nuget @> - let version = defaultArg (results.TryGetResult <@ AddArgs.Version @>) "" - let force = results.Contains <@ AddArgs.Force @> - let hard = results.Contains <@ AddArgs.Hard @> - let noInstall = results.Contains <@ AddArgs.No_Install @> - match results.TryGetResult <@ AddArgs.Project @> with - | Some projectName -> - Dependencies.Locate().AddToProject(packageName, version, force, hard, projectName, noInstall |> not) - | None -> - let interactive = results.Contains <@ AddArgs.Interactive @> - Dependencies.Locate().Add(packageName, version, force, hard, interactive, noInstall |> not)) - - | Command(Config, args) -> - processCommand Config args - (fun results -> - let args = results.GetResults <@ ConfigArgs.AddCredentials @> - if args.Length = 0 then - let parser = UnionArgParser.Create() - parser.Usage(HelpTexts.formatSyntax parser "paket config") |> trace - else - let source = args.Item 0 - let username = - if(args.Length > 1) then - args.Item 1 - else - "" - Dependencies.Locate().AddCredentials(source, username)) - - | Command(ConvertFromNuget, args) -> - processCommand ConvertFromNuget args - (fun results -> - let force = results.Contains <@ ConvertFromNugetArgs.Force @> - let noInstall = results.Contains <@ ConvertFromNugetArgs.No_Install @> - let noAutoRestore = results.Contains <@ ConvertFromNugetArgs.No_Auto_Restore @> - let credsMigrationMode = results.TryGetResult <@ ConvertFromNugetArgs.Creds_Migration @> - Dependencies.ConvertFromNuget(force, noInstall |> not, noAutoRestore |> not, credsMigrationMode)) +let add (results : ArgParseResults<_>) = + let packageName = results.GetResult <@ AddArgs.Nuget @> + let version = defaultArg (results.TryGetResult <@ AddArgs.Version @>) "" + let force = results.Contains <@ AddArgs.Force @> + let hard = results.Contains <@ AddArgs.Hard @> + let noInstall = results.Contains <@ AddArgs.No_Install @> + match results.TryGetResult <@ AddArgs.Project @> with + | Some projectName -> + Dependencies.Locate().AddToProject(packageName, version, force, hard, projectName, noInstall |> not) + | None -> + let interactive = results.Contains <@ AddArgs.Interactive @> + Dependencies.Locate().Add(packageName, version, force, hard, interactive, noInstall |> not) + +let validateConfig (results : ArgParseResults<_>) = + let args = results.GetResults <@ ConfigArgs.AddCredentials @> + args.Length > 0 + +let config (results : ArgParseResults<_>) = + let args = results.GetResults <@ ConfigArgs.AddCredentials @> + let source = args.Item 0 + let username = + if(args.Length > 1) then + args.Item 1 + else + "" + Dependencies.Locate().AddCredentials(source, username) + +let validateAutoRestore (results : ArgParseResults<_>) = + results.GetAllResults().Length = 1 + +let autoRestore (results : ArgParseResults<_>) = + match results.GetAllResults() with + | [On] -> Dependencies.Locate().TurnOnAutoRestore() + | [Off] -> Dependencies.Locate().TurnOffAutoRestore() + | _ -> failwith "expected only one argument" + +let convert (results : ArgParseResults<_>) = + let force = results.Contains <@ ConvertFromNugetArgs.Force @> + let noInstall = results.Contains <@ ConvertFromNugetArgs.No_Install @> + let noAutoRestore = results.Contains <@ ConvertFromNugetArgs.No_Auto_Restore @> + let credsMigrationMode = results.TryGetResult <@ ConvertFromNugetArgs.Creds_Migration @> + Dependencies.ConvertFromNuget(force, noInstall |> not, noAutoRestore |> not, credsMigrationMode) - | Command(FindRefs, args) -> - processCommand FindRefs args - (fun results -> - let packages = results.GetResults <@ FindRefsArgs.Packages @> - Dependencies.Locate().ShowReferencesFor(packages)) +let findRefs (results : ArgParseResults<_>) = + let packages = results.GetResults <@ FindRefsArgs.Packages @> + Dependencies.Locate().ShowReferencesFor(packages) - | Command(Init, args) -> - processCommand Init args - (fun results -> - Dependencies.Init()) - - | Command(AutoRestore, args) -> - processCommand AutoRestore args - (fun results -> - match results.GetAllResults() with - | [On] -> Dependencies.Locate().TurnOnAutoRestore() - | [Off] -> Dependencies.Locate().TurnOffAutoRestore() - | _ -> - let parser = UnionArgParser.Create() - parser.Usage(HelpTexts.formatSyntax parser "paket auto-restore") |> trace) - - | Command(Install, args) -> - processCommand Install args - (fun results -> - let force = results.Contains <@ InstallArgs.Force @> - let hard = results.Contains <@ InstallArgs.Hard @> - let withBindingRedirects = results.Contains <@ InstallArgs.Redirects @> - Dependencies.Locate().Install(force,hard,withBindingRedirects)) - - | Command(Outdated, args) -> - processCommand Outdated args - (fun results -> - let strict = results.Contains <@ OutdatedArgs.Ignore_Constraints @> |> not - let includePrereleases = results.Contains <@ OutdatedArgs.Include_Prereleases @> - Dependencies.Locate().ShowOutdated(strict,includePrereleases)) - - | Command(Remove, args) -> - processCommand Remove args - (fun results -> - let packageName = results.GetResult <@ RemoveArgs.Nuget @> - let force = results.Contains <@ RemoveArgs.Force @> - let hard = results.Contains <@ RemoveArgs.Hard @> - let noInstall = results.Contains <@ RemoveArgs.No_Install @> - match results.TryGetResult <@ RemoveArgs.Project @> with - | Some projectName -> - Dependencies.Locate().RemoveFromProject(packageName, force, hard, projectName, noInstall |> not) - | None -> - let interactive = results.Contains <@ RemoveArgs.Interactive @> - Dependencies.Locate().Remove(packageName, force, hard, interactive, noInstall |> not)) - - | Command(Restore, args) -> - processCommand Restore args - (fun results -> - let force = results.Contains <@ RestoreArgs.Force @> - let files = results.GetResults <@ RestoreArgs.References_Files @> - Dependencies.Locate().Restore(force,files)) - - | Command(Simplify, args) -> - processCommand Simplify args - (fun results -> - let interactive = results.Contains <@ SimplifyArgs.Interactive @> - Dependencies.Simplify(interactive)) - - | Command(Update, args) -> - processCommand Update args - (fun results -> - let hard = results.Contains <@ UpdateArgs.Hard @> - let force = results.Contains <@ UpdateArgs.Force @> - match results.TryGetResult <@ UpdateArgs.Nuget @> with - | Some packageName -> - let version = results.TryGetResult <@ UpdateArgs.Version @> - Dependencies.Locate().UpdatePackage(packageName, version, force, hard) - | _ -> - let withBindingRedirects = results.Contains <@ UpdateArgs.Redirects @> - Dependencies.Locate().Update(force,hard,withBindingRedirects)) - | Command(Pack, args) -> - processCommand Pack args - (fun results -> - let outputPath = results.GetResult <@ PackArgs.Output @> - Dependencies.Locate().Pack( - outputPath, - ?buildConfig = results.TryGetResult <@ PackArgs.BuildConfig @>, - ?version = results.TryGetResult <@ PackArgs.Version @>, - ?releaseNotes = results.TryGetResult <@ PackArgs.ReleaseNotes @>)) - | Command(Push, args) -> - processCommand Push args - (fun results -> - let fileName = results.GetResult <@ PushArgs.FileName @> - Dependencies.Locate().Push( - fileName, - ?url = results.TryGetResult <@ PushArgs.Url @>, - ?apiKey = results.TryGetResult <@ PushArgs.ApiKey @>)) - | _ -> - let parser = UnionArgParser.Create() - parser.Usage("available commands:") |> trace +let init (results : ArgParseResults<_>) = + Dependencies.Init() + +let install (results : ArgParseResults<_>) = + let force = results.Contains <@ InstallArgs.Force @> + let hard = results.Contains <@ InstallArgs.Hard @> + let withBindingRedirects = results.Contains <@ InstallArgs.Redirects @> + Dependencies.Locate().Install(force, hard, withBindingRedirects) + +let outdated (results : ArgParseResults<_>) = + let strict = results.Contains <@ OutdatedArgs.Ignore_Constraints @> |> not + let includePrereleases = results.Contains <@ OutdatedArgs.Include_Prereleases @> + Dependencies.Locate().ShowOutdated(strict, includePrereleases) + +let remove (results : ArgParseResults<_>) = + let packageName = results.GetResult <@ RemoveArgs.Nuget @> + let force = results.Contains <@ RemoveArgs.Force @> + let hard = results.Contains <@ RemoveArgs.Hard @> + let noInstall = results.Contains <@ RemoveArgs.No_Install @> + match results.TryGetResult <@ RemoveArgs.Project @> with + | Some projectName -> + Dependencies.Locate() + .RemoveFromProject(packageName, force, hard, projectName, noInstall |> not) + | None -> + let interactive = results.Contains <@ RemoveArgs.Interactive @> + Dependencies.Locate().Remove(packageName, force, hard, interactive, noInstall |> not) + +let restore (results : ArgParseResults<_>) = + let force = results.Contains <@ RestoreArgs.Force @> + let files = results.GetResults <@ RestoreArgs.References_Files @> + Dependencies.Locate().Restore(force, files) + +let simplify (results : ArgParseResults<_>) = + let interactive = results.Contains <@ SimplifyArgs.Interactive @> + Dependencies.Simplify(interactive) + +let update (results : ArgParseResults<_>) = + let hard = results.Contains <@ UpdateArgs.Hard @> + let force = results.Contains <@ UpdateArgs.Force @> + match results.TryGetResult <@ UpdateArgs.Nuget @> with + | Some packageName -> + let version = results.TryGetResult <@ UpdateArgs.Version @> + Dependencies.Locate().UpdatePackage(packageName, version, force, hard) + | _ -> + let withBindingRedirects = results.Contains <@ UpdateArgs.Redirects @> + Dependencies.Locate().Update(force, hard, withBindingRedirects) + +let pack (results : ArgParseResults<_>) = + let outputPath = results.GetResult <@ PackArgs.Output @> + Dependencies.Locate() + .Pack(outputPath, ?buildConfig = results.TryGetResult <@ PackArgs.BuildConfig @>, + ?version = results.TryGetResult <@ PackArgs.Version @>, + ?releaseNotes = results.TryGetResult <@ PackArgs.ReleaseNotes @>) + +let push (results : ArgParseResults<_>) = + let fileName = results.GetResult <@ PushArgs.FileName @> + Dependencies.Locate() + .Push(fileName, ?url = results.TryGetResult <@ PushArgs.Url @>, + ?apiKey = results.TryGetResult <@ PushArgs.ApiKey @>) - let elapsedTime = Utils.TimeSpanToReadableString stopWatch.Elapsed - tracefn "%s - ready." elapsedTime +try + let parser = UnionArgParser.Create() + let results = + parser.Parse(inputs = args, + ignoreMissing = true, + ignoreUnrecognized = true, + raiseOnUsage = false) + + match results.GetAllResults() with + | [ command ] -> + let args = args.[1..] + let commandName = HelpTexts.commandName command + let usage = (command :> IArgParserTemplate).Usage + let handler = + match command with + | Add -> processCommand add + | Config -> processWithValidation validateConfig config + | ConvertFromNuget -> processCommand convert + | FindRefs -> processCommand findRefs + | Init -> processCommand init + | AutoRestore -> processCommand autoRestore + | Install -> processCommand install + | Outdated -> processCommand outdated + | Remove -> processCommand remove + | Restore -> processCommand restore + | Simplify -> processCommand simplify + | Update -> processCommand update + | Pack -> processCommand pack + | Push -> processCommand push + + handler commandName usage args + | [] -> + parser.Usage("available commands:") |> trace + | _ -> failwith "expected only one command" with | exn when not (exn :? System.NullReferenceException) -> Environment.ExitCode <- 1 traceErrorfn "Paket failed with:%s\t%s" Environment.NewLine exn.Message if verbose then - traceErrorfn "StackTrace:%s %s" Environment.NewLine exn.StackTrace + traceErrorfn "StackTrace:%s %s" Environment.NewLine exn.StackTrace \ No newline at end of file From 312b31e2b64ab7bfacbc816c3cbdc4deaa5aea0a Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sun, 22 Feb 2015 17:56:17 +0100 Subject: [PATCH 27/28] help texts - list instead of dict --- docs/tools/generate.fsx | 2 +- src/Paket/HelpTexts.fs | 20 ++------------------ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/docs/tools/generate.fsx b/docs/tools/generate.fsx index d7b457a394..37b637ccf1 100644 --- a/docs/tools/generate.fsx +++ b/docs/tools/generate.fsx @@ -4,7 +4,7 @@ open System.IO Paket.HelpTexts.commands.Force() -|> Seq.iter (fun kv -> File.WriteAllText(sprintf "../content/paket-%s.md" kv.Key,kv.Value.ToMarkDown())) +|> Seq.iter (fun ht -> File.WriteAllText(sprintf "../content/paket-%s.md" (Paket.HelpTexts.commandName ht.Command), ht.ToMarkDown())) // -------------------------------------------------------------------------------------- // Builds the documentation from `.fsx` and `.md` files in the 'docs/content' directory diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index d483926bec..ec731baba2 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -58,8 +58,7 @@ type CommandHelpTopic = let commands = lazy - ["convert-from-nuget", - { Command = ConvertFromNuget + [ { Command = ConvertFromNuget Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Command steps @@ -93,7 +92,6 @@ Following are valid modes for `--creds-migration` option: After converting your solution from NuGet, you may end up with many transitive dependencies in your Paket files. Consider using [`paket simplify`](paket-simplify.html) to remove unnecessary transitive dependencies from your paket.dependencies file and paket.references files."""} - "auto-restore", { Command = AutoRestore Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Auto-restore on: @@ -107,12 +105,10 @@ Auto-restore off: - removes `paket.targets` from the `.paket` directory, - removes the `` statement for `paket.targets` from projects that have the [references file](references-files.html)."""} - "restore", { Command = Restore Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """"""} - "simplify", { Command = Simplify Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Simplify will also affect paket.references files, unless [strict](dependencies-file.html#Strict-references) mode is used. @@ -164,12 +160,10 @@ The simplify command will help you maintain your direct dependencies. Sometimes, you may still want to have control over some of the transitive dependencies. In this case you can use the `--interactive` flag, which will ask you to confirm before deleting a dependency from a file."""} - "init", { Command = Init Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """"""} - "add", { Command = Add Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Adding to a single project @@ -200,7 +194,6 @@ This will add the package to the selected paket.references files and also to the nuget FAKE nuget xunit"""} - "find-refs", { Command = FindRefs Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Sample @@ -229,7 +222,6 @@ and paket gives the following output: .src/Paket.Core/Paket.Core.fsproj .src/Paket/Paket.fsproj"""} - "update", { Command = Update Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Updating a single package @@ -245,7 +237,6 @@ Options: `--hard`: Replaces package references within project files even if they are not yet adhering to to Paket's conventions (and hence considered manually managed). See [convert from NuGet](paket-convert-from-nuget.html)."""} - "outdated", { Command = Outdated Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Sample @@ -270,7 +261,6 @@ Now we run `paket outdated`: ![alt text](img/paket-outdated.png "paket outdated command")"""} - "remove", { Command = Remove Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Removing from a single project @@ -282,19 +272,15 @@ It's also possible to remove a package from a specified project only: See also [paket add](paket-add.html)."""} - "install", { Command = Install Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """"""} - "pack", { Command = Pack Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """"""} - "push", { Command = Push Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """"""} - "config", { Command = Config Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Paket will then ask for username and password. @@ -306,6 +292,4 @@ The configuration file can be found in: let AppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) let PaketConfigFolder = Path.Combine(AppDataFolder, "Paket") let PaketConfigFile = Path.Combine(PaketConfigFolder, "paket.config") -"""}] - - |> dict +"""}] \ No newline at end of file From a2df3a7c571b853cf6aba728dbb5b5ca0d4e938d Mon Sep 17 00:00:00 2001 From: Tomasz Heimowski Date: Sun, 22 Feb 2015 18:10:40 +0100 Subject: [PATCH 28/28] cleanup --- docs/tools/generate.fsx | 2 +- src/Paket/Commands.fs | 81 ++++++++++++++++++++++++++++++++++++++++- src/Paket/HelpTexts.fs | 64 -------------------------------- src/Paket/Program.fs | 15 +++----- 4 files changed, 85 insertions(+), 77 deletions(-) diff --git a/docs/tools/generate.fsx b/docs/tools/generate.fsx index 37b637ccf1..d920b84919 100644 --- a/docs/tools/generate.fsx +++ b/docs/tools/generate.fsx @@ -4,7 +4,7 @@ open System.IO Paket.HelpTexts.commands.Force() -|> Seq.iter (fun ht -> File.WriteAllText(sprintf "../content/paket-%s.md" (Paket.HelpTexts.commandName ht.Command), ht.ToMarkDown())) +|> Seq.iter (fun ht -> File.WriteAllText(sprintf "../content/paket-%s.md" ht.Command.Name, Paket.Commands.markdown ht.Command ht.Text)) // -------------------------------------------------------------------------------------- // Builds the documentation from `.fsx` and `.md` files in the 'docs/content' directory diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index d030e46dac..d67a991967 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -1,5 +1,7 @@ module Paket.Commands +open System + open Nessos.UnionArgParser type Command = @@ -35,7 +37,13 @@ with | 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) + (uci.GetCustomAttributes(typeof) + |> Seq.head + :?> CustomCommandLineAttribute).Name + type GlobalArgs = | [] Verbose | Log_File of string @@ -207,4 +215,73 @@ with 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." \ No newline at end of file + | 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()) + | Config -> syntaxAndOptions (UnionArgParser.Create()) + | ConvertFromNuget -> syntaxAndOptions (UnionArgParser.Create()) + | FindRefs -> syntaxAndOptions (UnionArgParser.Create()) + | Init -> syntaxAndOptions (UnionArgParser.Create()) + | AutoRestore -> syntaxAndOptions (UnionArgParser.Create()) + | Install -> syntaxAndOptions (UnionArgParser.Create()) + | Outdated -> syntaxAndOptions (UnionArgParser.Create()) + | Remove -> syntaxAndOptions (UnionArgParser.Create()) + | Restore -> syntaxAndOptions (UnionArgParser.Create()) + | Simplify -> syntaxAndOptions (UnionArgParser.Create()) + | Update -> syntaxAndOptions (UnionArgParser.Create()) + | Pack -> syntaxAndOptions (UnionArgParser.Create()) + | Push -> syntaxAndOptions (UnionArgParser.Create()) + + + 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 \ No newline at end of file diff --git a/src/Paket/HelpTexts.fs b/src/Paket/HelpTexts.fs index ec731baba2..51083d5260 100644 --- a/src/Paket/HelpTexts.fs +++ b/src/Paket/HelpTexts.fs @@ -2,64 +2,13 @@ module Paket.HelpTexts open Paket.Commands -open Nessos.UnionArgParser - -let commandName (command : Command) = - let uci,_ = Microsoft.FSharp.Reflection.FSharpValue.GetUnionFields(command, typeof) - (uci.GetCustomAttributes(typeof) - |> Seq.head - :?> CustomCommandLineAttribute).Name - -let formatSyntax (parser:UnionArgParser<'TArgs>) commandName = - "$ " + commandName + " " + parser.PrintCommandLineSyntax() - -let replace (pattern : string) (replacement : string) input = - System.Text.RegularExpressions.Regex.Replace(input, pattern, replacement) - -let formatCommandSyntax (parser : UnionArgParser<_>) title = - let options = - parser.Usage() - |> replace @"\s\t--help.*" "" - |> replace @"\t([-\w \[\]|\/\?<>\.]+):" (System.Environment.NewLine + @" `$1`:") - sprintf """ [lang=batchfile] - %s - -Options: -%s""" - (formatSyntax parser title) - options - type CommandHelpTopic = { Command : Command - Syntax : string -> string Text : string } - member this.ToMarkDown() = - 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)") - - sprintf - "# %s%s%s%s%s%s%s%s%s%s" - ("paket " + (commandName this.Command)) - System.Environment.NewLine - System.Environment.NewLine - (this.Command :> IArgParserTemplate).Usage - System.Environment.NewLine - System.Environment.NewLine - (this.Syntax (commandName this.Command)) - System.Environment.NewLine - System.Environment.NewLine - this.Text - |> replaceLinks let commands = lazy [ { Command = ConvertFromNuget - Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Command steps The `paket convert-from-nuget` command: @@ -93,7 +42,6 @@ After converting your solution from NuGet, you may end up with many transitive d Consider using [`paket simplify`](paket-simplify.html) to remove unnecessary transitive dependencies from your paket.dependencies file and paket.references files."""} { Command = AutoRestore - Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Auto-restore on: - creates a `.paket` directory in your root directory, @@ -106,11 +54,9 @@ Auto-restore off: - removes the `` statement for `paket.targets` from projects that have the [references file](references-files.html)."""} { Command = Restore - Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """"""} { Command = Simplify - Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Simplify will also affect paket.references files, unless [strict](dependencies-file.html#Strict-references) mode is used. ## Sample @@ -161,11 +107,9 @@ Sometimes, you may still want to have control over some of the transitive depend which will ask you to confirm before deleting a dependency from a file."""} { Command = Init - Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """"""} { Command = Add - Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Adding to a single project It's also possible to add a package to a specified project only: @@ -195,7 +139,6 @@ This will add the package to the selected paket.references files and also to the nuget xunit"""} { Command = FindRefs - Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Sample *.src/Paket/paket.references* contains: @@ -223,7 +166,6 @@ and paket gives the following output: .src/Paket/Paket.fsproj"""} { Command = Update - Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Updating a single package It's also possible to update only a single package and to keep all other dependencies fixed: @@ -238,7 +180,6 @@ Options: `--hard`: Replaces package references within project files even if they are not yet adhering to to Paket's conventions (and hence considered manually managed). See [convert from NuGet](paket-convert-from-nuget.html)."""} { Command = Outdated - Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Sample Consider the following paket.dependencies file: @@ -262,7 +203,6 @@ Now we run `paket outdated`: ![alt text](img/paket-outdated.png "paket outdated command")"""} { Command = Remove - Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """## Removing from a single project It's also possible to remove a package from a specified project only: @@ -273,16 +213,12 @@ It's also possible to remove a package from a specified project only: See also [paket add](paket-add.html)."""} { Command = Install - Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """"""} { Command = Pack - Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """"""} { Command = Push - Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """"""} { Command = Config - Syntax = formatCommandSyntax (UnionArgParser.Create()) Text = """Paket will then ask for username and password. This credentials will be used if no username and password for the source are configured in the [`paket.dependencies` file](nuget-dependencies.html). diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 575ba05b8b..6f238a9851 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -40,7 +40,7 @@ let filterGlobalArgs args = verbose, logFile, rest -let processWithValidation<'T when 'T :> IArgParserTemplate> validateF commandF commandName usage +let processWithValidation<'T when 'T :> IArgParserTemplate> validateF commandF command args = let parser = UnionArgParser.Create<'T>() let results = @@ -49,10 +49,7 @@ let processWithValidation<'T when 'T :> IArgParserTemplate> validateF commandF c errorHandler = ProcessExiter()) let resultsValid = validateF (results) if results.IsUsageRequested || not resultsValid then - parser.Usage - ("Paket " + commandName + Environment.NewLine + Environment.NewLine + usage - + Environment.NewLine + Environment.NewLine - + HelpTexts.formatSyntax parser ("paket " + commandName)) |> trace + parser.Usage(Commands.cmdLineUsageMessage command parser) |> trace else commandF results let elapsedTime = Utils.TimeSpanToReadableString stopWatch.Elapsed @@ -183,9 +180,6 @@ try match results.GetAllResults() with | [ command ] -> - let args = args.[1..] - let commandName = HelpTexts.commandName command - let usage = (command :> IArgParserTemplate).Usage let handler = match command with | Add -> processCommand add @@ -193,7 +187,7 @@ try | ConvertFromNuget -> processCommand convert | FindRefs -> processCommand findRefs | Init -> processCommand init - | AutoRestore -> processCommand autoRestore + | AutoRestore -> processWithValidation validateAutoRestore autoRestore | Install -> processCommand install | Outdated -> processCommand outdated | Remove -> processCommand remove @@ -203,7 +197,8 @@ try | Pack -> processCommand pack | Push -> processCommand push - handler commandName usage args + let args = args.[1..] + handler command args | [] -> parser.Usage("available commands:") |> trace | _ -> failwith "expected only one command"