diff --git a/docs/content/paket-push.md b/docs/content/paket-push.md new file mode 100644 index 0000000000..6eba092c8c --- /dev/null +++ b/docs/content/paket-push.md @@ -0,0 +1,20 @@ +# paket push + +Pushes the given `.nupkg` file. + + [lang=msh] + paket push url file [apikey ] [endpoint ] + +### Options: + + `url `: Url of the NuGet feed. + + `file `: Path to the package. + + `apikey `: Optionally specify your API key on the command line. Otherwise uses the value of the `nugetkey` environment variable, or the api key stored in the [`paket.config` file](paket-config.html) for this url. + + `endpoint `: Optionally specify a custom api endpoint to push to. Defaults to `/api/v2/package`. + +If you add the `-v` flag, then Paket will run in verbose mode and show detailed information. + +With `--log-file [FileName]` you can trace the logged information into a file. diff --git a/src/Paket.Core/PublicAPI.fs b/src/Paket.Core/PublicAPI.fs index 365d359814..b2baa5c172 100644 --- a/src/Paket.Core/PublicAPI.fs +++ b/src/Paket.Core/PublicAPI.fs @@ -542,11 +542,20 @@ type Dependencies(dependenciesFileName: string) = /// Pushes a nupkg file. static member Push(packageFileName, ?url, ?apiKey, (?endPoint: string), ?maxTrials) = let urlWithEndpoint = RemoteUpload.GetUrlWithEndpoint url endPoint - let apiKey = defaultArg apiKey (Environment.GetEnvironmentVariable("nugetkey")) - if String.IsNullOrEmpty apiKey then - failwithf "Could not push package %s. Please specify a NuGet API key via environment variable \"nugetkey\"." packageFileName - let maxTrials = defaultArg maxTrials 5 - RemoteUpload.Push maxTrials urlWithEndpoint apiKey packageFileName + let envKey = Environment.GetEnvironmentVariable("nugetkey") |> Option.ofObj + let configKey = url |> Option.bind ConfigFile.GetAuthentication |> Option.bind (fun a -> match a with Token t -> Some t | _ -> None ) + let firstPresentKey = + [apiKey; envKey; configKey] + |> List.choose id + |> List.where (String.IsNullOrEmpty >> not) + |> List.tryHead + + match firstPresentKey with + | None -> + failwithf "Could not push package %s due to missing credentials for the url %s. Please specify a NuGet API key via the command line, the environment variable \"nugetkey\", or by using 'paket config add-token'." packageFileName urlWithEndpoint + | Some apiKey -> + let maxTrials = defaultArg maxTrials 5 + RemoteUpload.Push maxTrials urlWithEndpoint apiKey packageFileName /// Lists all paket.template files in the current solution. member this.ListTemplateFiles() : TemplateFile list =