Migrate Sirupsen to sirupsen.
This commit is contained in:
parent
c134dcd6fe
commit
fb4ba7af2b
684 changed files with 92394 additions and 33943 deletions
119
Gopkg.lock
generated
119
Gopkg.lock
generated
|
@ -94,7 +94,7 @@
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/Nvveen/Gotty"
|
name = "github.com/Nvveen/Gotty"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "6018b68f96b839edfbe3fb48668853f5dbad88a3"
|
revision = "a8b993ba6abdb0e0c12b0125c603323a71c7790c"
|
||||||
source = "github.com/ijc25/Gotty"
|
source = "github.com/ijc25/Gotty"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
|
@ -113,11 +113,6 @@
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "70f6a705d4a17af059acbc6946fb2bd30762acd7"
|
revision = "70f6a705d4a17af059acbc6946fb2bd30762acd7"
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/Sirupsen/logrus"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "10f801ebc38b33738c9d17d50860f484a0988ff5"
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/VividCortex/gohistogram"
|
name = "github.com/VividCortex/gohistogram"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
|
@ -216,8 +211,14 @@
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/codegangsta/cli"
|
name = "github.com/codegangsta/cli"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "bf4a526f48af7badd25d2cb02d587e1b01be3b50"
|
revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1"
|
||||||
version = "v1.4.1"
|
version = "v1.20.0"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/containerd/continuity"
|
||||||
|
packages = ["pathdriver"]
|
||||||
|
revision = "b2b946a77f5973f420514090d6f6dd58b08303f0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/containous/flaeg"
|
name = "github.com/containous/flaeg"
|
||||||
|
@ -325,9 +326,11 @@
|
||||||
packages = [
|
packages = [
|
||||||
"cli/command/image/build",
|
"cli/command/image/build",
|
||||||
"cli/config",
|
"cli/config",
|
||||||
"cli/config/configfile"
|
"cli/config/configfile",
|
||||||
|
"cli/config/credentials",
|
||||||
|
"opts"
|
||||||
]
|
]
|
||||||
revision = "d95fd2f38cfc23e077530c6181330727d561b6a0"
|
revision = "6b63d7b96a41055baddc3fa71f381c7f60bd5d8e"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/docker/distribution"
|
name = "github.com/docker/distribution"
|
||||||
|
@ -346,7 +349,7 @@
|
||||||
"registry/storage/cache/memory",
|
"registry/storage/cache/memory",
|
||||||
"uuid"
|
"uuid"
|
||||||
]
|
]
|
||||||
revision = "b38e5838b7b2f2ad48e06ec4b500011976080621"
|
revision = "edc3ab29cdff8694dd6feb85cfeb4b5f1b38ed9c"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/docker/docker"
|
name = "github.com/docker/docker"
|
||||||
|
@ -363,28 +366,24 @@
|
||||||
"api/types/registry",
|
"api/types/registry",
|
||||||
"api/types/strslice",
|
"api/types/strslice",
|
||||||
"api/types/swarm",
|
"api/types/swarm",
|
||||||
|
"api/types/swarm/runtime",
|
||||||
"api/types/time",
|
"api/types/time",
|
||||||
"api/types/versions",
|
"api/types/versions",
|
||||||
"api/types/volume",
|
"api/types/volume",
|
||||||
"builder/dockerignore",
|
"builder/dockerignore",
|
||||||
|
"builder/remotecontext/git",
|
||||||
"client",
|
"client",
|
||||||
"opts",
|
|
||||||
"pkg/archive",
|
"pkg/archive",
|
||||||
"pkg/fileutils",
|
"pkg/fileutils",
|
||||||
"pkg/gitutils",
|
|
||||||
"pkg/homedir",
|
"pkg/homedir",
|
||||||
"pkg/httputils",
|
|
||||||
"pkg/idtools",
|
"pkg/idtools",
|
||||||
"pkg/ioutils",
|
"pkg/ioutils",
|
||||||
"pkg/jsonlog",
|
|
||||||
"pkg/jsonmessage",
|
"pkg/jsonmessage",
|
||||||
"pkg/longpath",
|
"pkg/longpath",
|
||||||
"pkg/mount",
|
"pkg/mount",
|
||||||
"pkg/namesgenerator",
|
"pkg/namesgenerator",
|
||||||
"pkg/pools",
|
"pkg/pools",
|
||||||
"pkg/progress",
|
"pkg/progress",
|
||||||
"pkg/promise",
|
|
||||||
"pkg/random",
|
|
||||||
"pkg/stdcopy",
|
"pkg/stdcopy",
|
||||||
"pkg/streamformatter",
|
"pkg/streamformatter",
|
||||||
"pkg/stringid",
|
"pkg/stringid",
|
||||||
|
@ -393,12 +392,21 @@
|
||||||
"pkg/tarsum",
|
"pkg/tarsum",
|
||||||
"pkg/term",
|
"pkg/term",
|
||||||
"pkg/term/windows",
|
"pkg/term/windows",
|
||||||
"pkg/tlsconfig",
|
|
||||||
"pkg/urlutil",
|
"pkg/urlutil",
|
||||||
"registry",
|
"registry",
|
||||||
"runconfig/opts"
|
"registry/resumable"
|
||||||
]
|
]
|
||||||
revision = "75c7536d2e2e328b644bf69153de879d1d197988"
|
revision = "7848b8beb9d38a98a78b75f78e05f8d2255f9dfe"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
name = "github.com/docker/docker-credential-helpers"
|
||||||
|
packages = [
|
||||||
|
"client",
|
||||||
|
"credentials",
|
||||||
|
"pass"
|
||||||
|
]
|
||||||
|
revision = "d68f9aeca33f5fd3f08eeae5e9d175edf4e731d1"
|
||||||
|
version = "v0.6.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/docker/go-connections"
|
name = "github.com/docker/go-connections"
|
||||||
|
@ -407,7 +415,8 @@
|
||||||
"sockets",
|
"sockets",
|
||||||
"tlsconfig"
|
"tlsconfig"
|
||||||
]
|
]
|
||||||
revision = "e15c02316c12de00874640cd76311849de2aeed5"
|
revision = "3ede32e2033de7505e6500d6c868c2b9ed9f169d"
|
||||||
|
version = "v0.3.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/docker/go-units"
|
name = "github.com/docker/go-units"
|
||||||
|
@ -422,6 +431,7 @@
|
||||||
source = "github.com/containous/leadership"
|
source = "github.com/containous/leadership"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
name = "github.com/docker/libcompose"
|
name = "github.com/docker/libcompose"
|
||||||
packages = [
|
packages = [
|
||||||
"config",
|
"config",
|
||||||
|
@ -445,7 +455,7 @@
|
||||||
"version",
|
"version",
|
||||||
"yaml"
|
"yaml"
|
||||||
]
|
]
|
||||||
revision = "1b708aac26a4fc6f9bff31728a8e3a252ef57dbd"
|
revision = "57bd716502dcbe1799f026148016022b0f3b989c"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
@ -462,11 +472,6 @@
|
||||||
revision = "5e4bb288a9a74320bb03f5c18d6bdbab0d8049de"
|
revision = "5e4bb288a9a74320bb03f5c18d6bdbab0d8049de"
|
||||||
source = "github.com/abronan/libkv"
|
source = "github.com/abronan/libkv"
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/docker/libtrust"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "9cbd2a1374f46905c68a4eb3694a130610adc62a"
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/donovanhide/eventsource"
|
name = "github.com/donovanhide/eventsource"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
|
@ -505,7 +510,8 @@
|
||||||
"tokens",
|
"tokens",
|
||||||
"zones"
|
"zones"
|
||||||
]
|
]
|
||||||
revision = "398f53855ba258191157e20fabfaccca5e13cea9"
|
revision = "1563e622aaca0a8bb895a448f31d4a430ab97586"
|
||||||
|
version = "v1.0.3"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
@ -674,6 +680,12 @@
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "a69d9f6de432e2c6b296a947d8a5ee88f68522cf"
|
revision = "a69d9f6de432e2c6b296a947d8a5ee88f68522cf"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
name = "github.com/gravitational/trace"
|
||||||
|
packages = ["."]
|
||||||
|
revision = "0bd13642feb8f57acc0d8e3a568edc34e05a74b9"
|
||||||
|
version = "1.1.3"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/hashicorp/consul"
|
name = "github.com/hashicorp/consul"
|
||||||
packages = ["api"]
|
packages = ["api"]
|
||||||
|
@ -743,22 +755,25 @@
|
||||||
revision = "b84e30acd515aadc4b783ad4ff83aff3299bdfe0"
|
revision = "b84e30acd515aadc4b783ad4ff83aff3299bdfe0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
name = "github.com/libkermit/compose"
|
name = "github.com/libkermit/compose"
|
||||||
packages = [
|
packages = [
|
||||||
".",
|
".",
|
||||||
"check"
|
"check"
|
||||||
]
|
]
|
||||||
revision = "4a33a16f1446ba205c4da7b09105d5bdc293b432"
|
revision = "c04e39c026ad1c76c027d6780150c8f7dec0a610"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
name = "github.com/libkermit/docker"
|
name = "github.com/libkermit/docker"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "ddede409294e8c5ae66d68ac09edb6b27e8f3e4a"
|
revision = "e6674d32b80712b563ed8a0187af2bc93448b82f"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
name = "github.com/libkermit/docker-check"
|
name = "github.com/libkermit/docker-check"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "e0695005d6819191cf8969b479c94c40c8d22aa4"
|
revision = "1113af38e5916529ad7317b0fe12e273e6e92af5"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/mailgun/minheap"
|
name = "github.com/mailgun/minheap"
|
||||||
|
@ -991,10 +1006,11 @@
|
||||||
revision = "52e2f489534007ae843065468c5a1920d542afa4"
|
revision = "52e2f489534007ae843065468c5a1920d542afa4"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "containous-fork"
|
||||||
name = "github.com/rancher/go-rancher-metadata"
|
name = "github.com/rancher/go-rancher-metadata"
|
||||||
packages = ["metadata"]
|
packages = ["metadata"]
|
||||||
revision = "d2103caca5873119ff423d29cba09b4d03cd69b8"
|
revision = "e937e8308985dfd3bc157cc8a284454f0cbf4fef"
|
||||||
|
source = "github.com/containous/go-rancher-metadata"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/rcrowley/go-metrics"
|
name = "github.com/rcrowley/go-metrics"
|
||||||
|
@ -1018,6 +1034,12 @@
|
||||||
revision = "879c5887cd475cd7864858769793b2ceb0d44feb"
|
revision = "879c5887cd475cd7864858769793b2ceb0d44feb"
|
||||||
version = "v1.1.0"
|
version = "v1.1.0"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
name = "github.com/sirupsen/logrus"
|
||||||
|
packages = ["."]
|
||||||
|
revision = "d682213848ed68c0a260ca37d6dd5ace8423f5ba"
|
||||||
|
version = "v1.0.4"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/spf13/pflag"
|
name = "github.com/spf13/pflag"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
|
@ -1112,7 +1134,7 @@
|
||||||
version = "v0.1.0"
|
version = "v0.1.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "containous-fork"
|
branch = "master"
|
||||||
name = "github.com/vulcand/oxy"
|
name = "github.com/vulcand/oxy"
|
||||||
packages = [
|
packages = [
|
||||||
"cbreaker",
|
"cbreaker",
|
||||||
|
@ -1123,28 +1145,31 @@
|
||||||
"roundrobin",
|
"roundrobin",
|
||||||
"utils"
|
"utils"
|
||||||
]
|
]
|
||||||
revision = "812cebb8c764f2a78cb806267648b8728b4599ad"
|
revision = "092a2d70bb8859a9def2b1bb9a61cdc193ee55cc"
|
||||||
source = "https://github.com/containous/oxy.git"
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/vulcand/predicate"
|
name = "github.com/vulcand/predicate"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "19b9dde14240d94c804ae5736ad0e1de10bf8fe6"
|
revision = "939c094524d124c55fa8afe0e077701db4a865e2"
|
||||||
|
version = "v1.0.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
name = "github.com/vulcand/route"
|
name = "github.com/vulcand/route"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "cb89d787ddbb1c5849a7ac9f79004c1fd12a4a32"
|
revision = "61904570391bdf22252f8e376b49a57593d9124c"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
name = "github.com/vulcand/vulcand"
|
name = "github.com/vulcand/vulcand"
|
||||||
packages = [
|
packages = [
|
||||||
"conntracker",
|
"conntracker",
|
||||||
"plugin",
|
"plugin",
|
||||||
|
"plugin/cacheprovider",
|
||||||
"plugin/rewrite",
|
"plugin/rewrite",
|
||||||
"router"
|
"router"
|
||||||
]
|
]
|
||||||
revision = "42492a3a85e294bdbdd1bcabb8c12769a81ea284"
|
revision = "3ab68471860269ba2afdd1a97e2d058087631975"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
@ -1195,17 +1220,22 @@
|
||||||
revision = "b929aa5aab5ad2e197bb3d74ef99fac61bfa47bc"
|
revision = "b929aa5aab5ad2e197bb3d74ef99fac61bfa47bc"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
name = "golang.org/x/crypto"
|
name = "golang.org/x/crypto"
|
||||||
packages = [
|
packages = [
|
||||||
|
"acme",
|
||||||
|
"acme/autocert",
|
||||||
"bcrypt",
|
"bcrypt",
|
||||||
"blowfish",
|
"blowfish",
|
||||||
"ocsp",
|
"ocsp",
|
||||||
"pbkdf2",
|
"pbkdf2",
|
||||||
"scrypt"
|
"scrypt",
|
||||||
|
"ssh/terminal"
|
||||||
]
|
]
|
||||||
revision = "4ed45ec682102c643324fae5dff8dab085b6c300"
|
revision = "13931e22f9e72ea58bb73048bc752b48c6d4d4ac"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
name = "golang.org/x/net"
|
name = "golang.org/x/net"
|
||||||
packages = [
|
packages = [
|
||||||
"context",
|
"context",
|
||||||
|
@ -1219,7 +1249,7 @@
|
||||||
"trace",
|
"trace",
|
||||||
"websocket"
|
"websocket"
|
||||||
]
|
]
|
||||||
revision = "c8c74377599bd978aee1cf3b9b63a8634051cec2"
|
revision = "5ccada7d0a7ba9aeb5d3aca8d3501b4c2a509fec"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "golang.org/x/oauth2"
|
name = "golang.org/x/oauth2"
|
||||||
|
@ -1233,12 +1263,13 @@
|
||||||
revision = "7fdf09982454086d5570c7db3e11f360194830ca"
|
revision = "7fdf09982454086d5570c7db3e11f360194830ca"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
name = "golang.org/x/sys"
|
name = "golang.org/x/sys"
|
||||||
packages = [
|
packages = [
|
||||||
"unix",
|
"unix",
|
||||||
"windows"
|
"windows"
|
||||||
]
|
]
|
||||||
revision = "8f0908ab3b2457e2e15403d3697c9ef5cb4b57a9"
|
revision = "fff93fa7cd278d84afc205751523809c464168ab"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "golang.org/x/text"
|
name = "golang.org/x/text"
|
||||||
|
@ -1482,6 +1513,6 @@
|
||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "aa1aa76d15a49bbeee747782a71809fcfbaccf4586e924e70a6d93c51c173a30"
|
inputs-digest = "abd30ec16123cf6de5a869dcaba3e3247907785b4802f0eebaa0cf4d16ef444b"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
|
56
Gopkg.toml
56
Gopkg.toml
|
@ -19,8 +19,6 @@
|
||||||
# name = "github.com/x/y"
|
# name = "github.com/x/y"
|
||||||
# version = "2.4.0"
|
# version = "2.4.0"
|
||||||
|
|
||||||
ignored = ["github.com/sirupsen/logrus"]
|
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/ArthurHlt/go-eureka-client"
|
name = "github.com/ArthurHlt/go-eureka-client"
|
||||||
|
@ -96,6 +94,11 @@ ignored = ["github.com/sirupsen/logrus"]
|
||||||
name = "github.com/go-check/check"
|
name = "github.com/go-check/check"
|
||||||
source = "github.com/containous/check"
|
source = "github.com/containous/check"
|
||||||
|
|
||||||
|
[[override]]
|
||||||
|
branch = "fork-containous"
|
||||||
|
name = "github.com/go-check/check"
|
||||||
|
source = "github.com/containous/check"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/go-kit/kit"
|
name = "github.com/go-kit/kit"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
@ -137,8 +140,9 @@ ignored = ["github.com/sirupsen/logrus"]
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
branch = "master"
|
branch = "containous-fork"
|
||||||
name = "github.com/rancher/go-rancher-metadata"
|
name = "github.com/rancher/go-rancher-metadata"
|
||||||
|
source = "github.com/containous/go-rancher-metadata"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
@ -165,9 +169,8 @@ ignored = ["github.com/sirupsen/logrus"]
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
branch = "containous-fork"
|
branch = "master"
|
||||||
name = "github.com/vulcand/oxy"
|
name = "github.com/vulcand/oxy"
|
||||||
source = "https://github.com/containous/oxy.git"
|
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
@ -185,9 +188,45 @@ ignored = ["github.com/sirupsen/logrus"]
|
||||||
name = "k8s.io/client-go"
|
name = "k8s.io/client-go"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/vulcand/vulcand"
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/libkermit/docker"
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/libkermit/docker-check"
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/libkermit/compose"
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
name = "github.com/docker/docker"
|
||||||
|
revision = "7848b8beb9d38a98a78b75f78e05f8d2255f9dfe"
|
||||||
|
|
||||||
|
[[override]]
|
||||||
|
name = "github.com/docker/docker"
|
||||||
|
revision = "7848b8beb9d38a98a78b75f78e05f8d2255f9dfe"
|
||||||
|
|
||||||
|
[[override]]
|
||||||
|
name = "github.com/docker/cli"
|
||||||
|
revision = "6b63d7b96a41055baddc3fa71f381c7f60bd5d8e"
|
||||||
|
|
||||||
|
[[override]]
|
||||||
|
name = "github.com/docker/distribution"
|
||||||
|
revision = "edc3ab29cdff8694dd6feb85cfeb4b5f1b38ed9c"
|
||||||
|
|
||||||
|
[[override]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/docker/libcompose"
|
||||||
|
|
||||||
[[override]]
|
[[override]]
|
||||||
name = "github.com/Nvveen/Gotty"
|
name = "github.com/Nvveen/Gotty"
|
||||||
revision = "6018b68f96b839edfbe3fb48668853f5dbad88a3"
|
revision = "a8b993ba6abdb0e0c12b0125c603323a71c7790c"
|
||||||
source = "github.com/ijc25/Gotty"
|
source = "github.com/ijc25/Gotty"
|
||||||
|
|
||||||
[[override]]
|
[[override]]
|
||||||
|
@ -198,8 +237,3 @@ ignored = ["github.com/sirupsen/logrus"]
|
||||||
# ALWAYS keep this override
|
# ALWAYS keep this override
|
||||||
name = "github.com/mailgun/timetools"
|
name = "github.com/mailgun/timetools"
|
||||||
revision = "7e6055773c5137efbeb3bd2410d705fe10ab6bfd"
|
revision = "7e6055773c5137efbeb3bd2410d705fe10ab6bfd"
|
||||||
|
|
||||||
# Must be remove when logrus migration happen
|
|
||||||
[[override]]
|
|
||||||
name = "github.com/vulcand/predicate"
|
|
||||||
revision = "19b9dde14240d94c804ae5736ad0e1de10bf8fe6"
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"github.com/cenk/backoff"
|
"github.com/cenk/backoff"
|
||||||
"github.com/containous/flaeg"
|
"github.com/containous/flaeg"
|
||||||
"github.com/containous/staert"
|
"github.com/containous/staert"
|
||||||
|
@ -28,6 +27,7 @@ import (
|
||||||
"github.com/containous/traefik/types"
|
"github.com/containous/traefik/types"
|
||||||
"github.com/containous/traefik/version"
|
"github.com/containous/traefik/version"
|
||||||
"github.com/coreos/go-systemd/daemon"
|
"github.com/coreos/go-systemd/daemon"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -68,7 +68,7 @@ func (s *SimpleSuite) TestDefaultEntryPoints(c *check.C) {
|
||||||
defer cmd.Process.Kill()
|
defer cmd.Process.Kill()
|
||||||
|
|
||||||
err = try.Do(500*time.Millisecond, func() error {
|
err = try.Do(500*time.Millisecond, func() error {
|
||||||
expected := "\"DefaultEntryPoints\":[\"http\"]"
|
expected := `\"DefaultEntryPoints\":[\"http\"]`
|
||||||
actual := output.String()
|
actual := output.String()
|
||||||
|
|
||||||
if !strings.Contains(actual, expected) {
|
if !strings.Contains(actual, expected) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -12,8 +12,8 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"github.com/containous/traefik/types"
|
"github.com/containous/traefik/types"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type key string
|
type key string
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// default format for time presentation
|
// default format for time presentation
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"github.com/cenk/backoff"
|
"github.com/cenk/backoff"
|
||||||
"github.com/containous/flaeg"
|
"github.com/containous/flaeg"
|
||||||
"github.com/containous/traefik/job"
|
"github.com/containous/traefik/job"
|
||||||
|
@ -14,6 +13,7 @@ import (
|
||||||
"github.com/containous/traefik/safe"
|
"github.com/containous/traefik/safe"
|
||||||
"github.com/containous/traefik/types"
|
"github.com/containous/traefik/types"
|
||||||
"github.com/gambol99/go-marathon"
|
"github.com/gambol99/go-marathon"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -5,12 +5,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"github.com/cenk/backoff"
|
"github.com/cenk/backoff"
|
||||||
"github.com/containous/traefik/job"
|
"github.com/containous/traefik/job"
|
||||||
"github.com/containous/traefik/log"
|
"github.com/containous/traefik/log"
|
||||||
"github.com/containous/traefik/safe"
|
"github.com/containous/traefik/safe"
|
||||||
"github.com/containous/traefik/types"
|
"github.com/containous/traefik/types"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
rancher "github.com/rancher/go-rancher-metadata/metadata"
|
rancher "github.com/rancher/go-rancher-metadata/metadata"
|
||||||
)
|
)
|
||||||
|
|
|
@ -23,7 +23,8 @@ find vendor -type f \( ! -iname 'licen[cs]e*' \
|
||||||
-a ! -iname 'thirdparty*' \
|
-a ! -iname 'thirdparty*' \
|
||||||
-a ! -iname '*.go' \
|
-a ! -iname '*.go' \
|
||||||
-a ! -iname '*.c' \
|
-a ! -iname '*.c' \
|
||||||
-a ! -iname '*.S' \
|
-a ! -iname '*.s' \
|
||||||
|
-a ! -iname '*.pl' \
|
||||||
-a ! -iname '*.cc' \
|
-a ! -iname '*.cc' \
|
||||||
-a ! -iname '*.cpp' \
|
-a ! -iname '*.cpp' \
|
||||||
-a ! -iname '*.cxx' \
|
-a ! -iname '*.cxx' \
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"github.com/armon/go-proxyproto"
|
"github.com/armon/go-proxyproto"
|
||||||
"github.com/containous/mux"
|
"github.com/containous/mux"
|
||||||
"github.com/containous/traefik/cluster"
|
"github.com/containous/traefik/cluster"
|
||||||
|
@ -40,6 +39,7 @@ import (
|
||||||
"github.com/containous/traefik/types"
|
"github.com/containous/traefik/types"
|
||||||
"github.com/containous/traefik/whitelist"
|
"github.com/containous/traefik/whitelist"
|
||||||
"github.com/eapache/channels"
|
"github.com/eapache/channels"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
thoas_stats "github.com/thoas/stats"
|
thoas_stats "github.com/thoas/stats"
|
||||||
"github.com/urfave/negroni"
|
"github.com/urfave/negroni"
|
||||||
"github.com/vulcand/oxy/connlimit"
|
"github.com/vulcand/oxy/connlimit"
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"github.com/containous/traefik/log"
|
"github.com/containous/traefik/log"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
40
vendor/github.com/Nvveen/Gotty/gotty.go
generated
vendored
40
vendor/github.com/Nvveen/Gotty/gotty.go
generated
vendored
|
@ -13,6 +13,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -22,33 +23,30 @@ import (
|
||||||
// If something went wrong reading the terminfo database file, an error is
|
// If something went wrong reading the terminfo database file, an error is
|
||||||
// returned.
|
// returned.
|
||||||
func OpenTermInfo(termName string) (*TermInfo, error) {
|
func OpenTermInfo(termName string) (*TermInfo, error) {
|
||||||
var term *TermInfo
|
if len(termName) == 0 {
|
||||||
var err error
|
return nil, errors.New("No termname given")
|
||||||
|
}
|
||||||
// Find the environment variables
|
// Find the environment variables
|
||||||
termloc := os.Getenv("TERMINFO")
|
if termloc := os.Getenv("TERMINFO"); len(termloc) > 0 {
|
||||||
if len(termloc) == 0 {
|
return readTermInfo(path.Join(termloc, string(termName[0]), termName))
|
||||||
|
} else {
|
||||||
// Search like ncurses
|
// Search like ncurses
|
||||||
locations := []string{os.Getenv("HOME") + "/.terminfo/", "/etc/terminfo/",
|
locations := []string{}
|
||||||
"/lib/terminfo/", "/usr/share/terminfo/"}
|
if h := os.Getenv("HOME"); len(h) > 0 {
|
||||||
var path string
|
locations = append(locations, path.Join(h, ".terminfo"))
|
||||||
|
}
|
||||||
|
locations = append(locations,
|
||||||
|
"/etc/terminfo/",
|
||||||
|
"/lib/terminfo/",
|
||||||
|
"/usr/share/terminfo/")
|
||||||
for _, str := range locations {
|
for _, str := range locations {
|
||||||
// Construct path
|
term, err := readTermInfo(path.Join(str, string(termName[0]), termName))
|
||||||
path = str + string(termName[0]) + "/" + termName
|
if err == nil {
|
||||||
// Check if path can be opened
|
return term, nil
|
||||||
file, _ := os.Open(path)
|
|
||||||
if file != nil {
|
|
||||||
// Path can open, fall out and use current path
|
|
||||||
file.Close()
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(path) > 0 {
|
return nil, errors.New("No terminfo file(-location) found")
|
||||||
term, err = readTermInfo(path)
|
|
||||||
} else {
|
|
||||||
err = errors.New(fmt.Sprintf("No terminfo file(-location) found"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return term, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open a terminfo file from the environment variable containing the current
|
// Open a terminfo file from the environment variable containing the current
|
||||||
|
|
10
vendor/github.com/Sirupsen/logrus/terminal_appengine.go
generated
vendored
10
vendor/github.com/Sirupsen/logrus/terminal_appengine.go
generated
vendored
|
@ -1,10 +0,0 @@
|
||||||
// +build appengine
|
|
||||||
|
|
||||||
package logrus
|
|
||||||
|
|
||||||
import "io"
|
|
||||||
|
|
||||||
// IsTerminal returns true if stderr's file descriptor is a terminal.
|
|
||||||
func IsTerminal(f io.Writer) bool {
|
|
||||||
return true
|
|
||||||
}
|
|
10
vendor/github.com/Sirupsen/logrus/terminal_bsd.go
generated
vendored
10
vendor/github.com/Sirupsen/logrus/terminal_bsd.go
generated
vendored
|
@ -1,10 +0,0 @@
|
||||||
// +build darwin freebsd openbsd netbsd dragonfly
|
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package logrus
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
const ioctlReadTermios = syscall.TIOCGETA
|
|
||||||
|
|
||||||
type Termios syscall.Termios
|
|
28
vendor/github.com/Sirupsen/logrus/terminal_notwindows.go
generated
vendored
28
vendor/github.com/Sirupsen/logrus/terminal_notwindows.go
generated
vendored
|
@ -1,28 +0,0 @@
|
||||||
// Based on ssh/terminal:
|
|
||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build linux darwin freebsd openbsd netbsd dragonfly
|
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package logrus
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// IsTerminal returns true if stderr's file descriptor is a terminal.
|
|
||||||
func IsTerminal(f io.Writer) bool {
|
|
||||||
var termios Termios
|
|
||||||
switch v := f.(type) {
|
|
||||||
case *os.File:
|
|
||||||
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(v.Fd()), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
|
|
||||||
return err == 0
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
21
vendor/github.com/Sirupsen/logrus/terminal_solaris.go
generated
vendored
21
vendor/github.com/Sirupsen/logrus/terminal_solaris.go
generated
vendored
|
@ -1,21 +0,0 @@
|
||||||
// +build solaris,!appengine
|
|
||||||
|
|
||||||
package logrus
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
|
||||||
|
|
||||||
// IsTerminal returns true if the given file descriptor is a terminal.
|
|
||||||
func IsTerminal(f io.Writer) bool {
|
|
||||||
switch v := f.(type) {
|
|
||||||
case *os.File:
|
|
||||||
_, err := unix.IoctlGetTermios(int(v.Fd()), unix.TCGETA)
|
|
||||||
return err == nil
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
33
vendor/github.com/Sirupsen/logrus/terminal_windows.go
generated
vendored
33
vendor/github.com/Sirupsen/logrus/terminal_windows.go
generated
vendored
|
@ -1,33 +0,0 @@
|
||||||
// Based on ssh/terminal:
|
|
||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows,!appengine
|
|
||||||
|
|
||||||
package logrus
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
var kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
|
||||||
|
|
||||||
var (
|
|
||||||
procGetConsoleMode = kernel32.NewProc("GetConsoleMode")
|
|
||||||
)
|
|
||||||
|
|
||||||
// IsTerminal returns true if stderr's file descriptor is a terminal.
|
|
||||||
func IsTerminal(f io.Writer) bool {
|
|
||||||
switch v := f.(type) {
|
|
||||||
case *os.File:
|
|
||||||
var st uint32
|
|
||||||
r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(v.Fd()), uintptr(unsafe.Pointer(&st)), 0)
|
|
||||||
return r != 0 && e == 0
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
28
vendor/github.com/codegangsta/cli/LICENSE
generated
vendored
28
vendor/github.com/codegangsta/cli/LICENSE
generated
vendored
|
@ -1,21 +1,21 @@
|
||||||
Copyright (C) 2013 Jeremy Saenz
|
MIT License
|
||||||
All Rights Reserved.
|
|
||||||
|
|
||||||
MIT LICENSE
|
Copyright (c) 2016 Jeremy Saenz & Contributors
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
the Software without restriction, including without limitation the rights to
|
in the Software without restriction, including without limitation the rights
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
390
vendor/github.com/codegangsta/cli/app.go
generated
vendored
390
vendor/github.com/codegangsta/cli/app.go
generated
vendored
|
@ -5,20 +5,40 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
"path/filepath"
|
||||||
"text/template"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// App is the main structure of a cli application. It is recomended that
|
var (
|
||||||
// and app be created with the cli.NewApp() function
|
changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md"
|
||||||
|
appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL)
|
||||||
|
runAndExitOnErrorDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-runandexitonerror", changeLogURL)
|
||||||
|
|
||||||
|
contactSysadmin = "This is an error in the application. Please contact the distributor of this application if this is not you."
|
||||||
|
|
||||||
|
errInvalidActionType = NewExitError("ERROR invalid Action type. "+
|
||||||
|
fmt.Sprintf("Must be `func(*Context`)` or `func(*Context) error). %s", contactSysadmin)+
|
||||||
|
fmt.Sprintf("See %s", appActionDeprecationURL), 2)
|
||||||
|
)
|
||||||
|
|
||||||
|
// App is the main structure of a cli application. It is recommended that
|
||||||
|
// an app be created with the cli.NewApp() function
|
||||||
type App struct {
|
type App struct {
|
||||||
// The name of the program. Defaults to os.Args[0]
|
// The name of the program. Defaults to path.Base(os.Args[0])
|
||||||
Name string
|
Name string
|
||||||
|
// Full name of command for help, defaults to Name
|
||||||
|
HelpName string
|
||||||
// Description of the program.
|
// Description of the program.
|
||||||
Usage string
|
Usage string
|
||||||
|
// Text to override the USAGE section of help
|
||||||
|
UsageText string
|
||||||
|
// Description of the program argument format.
|
||||||
|
ArgsUsage string
|
||||||
// Version of the program
|
// Version of the program
|
||||||
Version string
|
Version string
|
||||||
|
// Description of the program
|
||||||
|
Description string
|
||||||
// List of commands to execute
|
// List of commands to execute
|
||||||
Commands []Command
|
Commands []Command
|
||||||
// List of flags to parse
|
// List of flags to parse
|
||||||
|
@ -27,25 +47,52 @@ type App struct {
|
||||||
EnableBashCompletion bool
|
EnableBashCompletion bool
|
||||||
// Boolean to hide built-in help command
|
// Boolean to hide built-in help command
|
||||||
HideHelp bool
|
HideHelp bool
|
||||||
// Boolean to hide built-in version flag
|
// Boolean to hide built-in version flag and the VERSION section of help
|
||||||
HideVersion bool
|
HideVersion bool
|
||||||
|
// Populate on app startup, only gettable through method Categories()
|
||||||
|
categories CommandCategories
|
||||||
// An action to execute when the bash-completion flag is set
|
// An action to execute when the bash-completion flag is set
|
||||||
BashComplete func(context *Context)
|
BashComplete BashCompleteFunc
|
||||||
// An action to execute before any subcommands are run, but after the context is ready
|
// An action to execute before any subcommands are run, but after the context is ready
|
||||||
// If a non-nil error is returned, no subcommands are run
|
// If a non-nil error is returned, no subcommands are run
|
||||||
Before func(context *Context) error
|
Before BeforeFunc
|
||||||
|
// An action to execute after any subcommands are run, but after the subcommand has finished
|
||||||
|
// It is run even if Action() panics
|
||||||
|
After AfterFunc
|
||||||
|
|
||||||
// The action to execute when no subcommands are specified
|
// The action to execute when no subcommands are specified
|
||||||
Action func(context *Context)
|
// Expects a `cli.ActionFunc` but will accept the *deprecated* signature of `func(*cli.Context) {}`
|
||||||
|
// *Note*: support for the deprecated `Action` signature will be removed in a future version
|
||||||
|
Action interface{}
|
||||||
|
|
||||||
// Execute this function if the proper command cannot be found
|
// Execute this function if the proper command cannot be found
|
||||||
CommandNotFound func(context *Context, command string)
|
CommandNotFound CommandNotFoundFunc
|
||||||
|
// Execute this function if an usage error occurs
|
||||||
|
OnUsageError OnUsageErrorFunc
|
||||||
// Compilation date
|
// Compilation date
|
||||||
Compiled time.Time
|
Compiled time.Time
|
||||||
// Author
|
// List of all authors who contributed
|
||||||
|
Authors []Author
|
||||||
|
// Copyright of the binary if any
|
||||||
|
Copyright string
|
||||||
|
// Name of Author (Note: Use App.Authors, this is deprecated)
|
||||||
Author string
|
Author string
|
||||||
// Author e-mail
|
// Email of Author (Note: Use App.Authors, this is deprecated)
|
||||||
Email string
|
Email string
|
||||||
// Writer writer to write output to
|
// Writer writer to write output to
|
||||||
Writer io.Writer
|
Writer io.Writer
|
||||||
|
// ErrWriter writes error output
|
||||||
|
ErrWriter io.Writer
|
||||||
|
// Other custom info
|
||||||
|
Metadata map[string]interface{}
|
||||||
|
// Carries a function which returns app specific info.
|
||||||
|
ExtraInfo func() map[string]string
|
||||||
|
// CustomAppHelpTemplate the text template for app help topic.
|
||||||
|
// cli.go uses text/template to render templates. You can
|
||||||
|
// render custom help text by setting this variable.
|
||||||
|
CustomAppHelpTemplate string
|
||||||
|
|
||||||
|
didSetup bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tries to find out when this binary was compiled.
|
// Tries to find out when this binary was compiled.
|
||||||
|
@ -58,40 +105,45 @@ func compileTime() time.Time {
|
||||||
return info.ModTime()
|
return info.ModTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new cli Application with some reasonable defaults for Name, Usage, Version and Action.
|
// NewApp creates a new cli Application with some reasonable defaults for Name,
|
||||||
|
// Usage, Version and Action.
|
||||||
func NewApp() *App {
|
func NewApp() *App {
|
||||||
return &App{
|
return &App{
|
||||||
Name: os.Args[0],
|
Name: filepath.Base(os.Args[0]),
|
||||||
|
HelpName: filepath.Base(os.Args[0]),
|
||||||
Usage: "A new cli application",
|
Usage: "A new cli application",
|
||||||
|
UsageText: "",
|
||||||
Version: "0.0.0",
|
Version: "0.0.0",
|
||||||
BashComplete: DefaultAppComplete,
|
BashComplete: DefaultAppComplete,
|
||||||
Action: helpCommand.Action,
|
Action: helpCommand.Action,
|
||||||
Compiled: compileTime(),
|
Compiled: compileTime(),
|
||||||
Author: "Author",
|
|
||||||
Email: "unknown@email",
|
|
||||||
Writer: os.Stdout,
|
Writer: os.Stdout,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entry point to the cli app. Parses the arguments slice and routes to the proper flag/args combination
|
// Setup runs initialization code to ensure all data structures are ready for
|
||||||
func (a *App) Run(arguments []string) error {
|
// `Run` or inspection prior to `Run`. It is internally called by `Run`, but
|
||||||
if HelpPrinter == nil {
|
// will return early if setup has already happened.
|
||||||
defer func() {
|
func (a *App) Setup() {
|
||||||
HelpPrinter = nil
|
if a.didSetup {
|
||||||
}()
|
return
|
||||||
|
|
||||||
HelpPrinter = func(templ string, data interface{}) {
|
|
||||||
w := tabwriter.NewWriter(a.Writer, 0, 8, 1, '\t', 0)
|
|
||||||
t := template.Must(template.New("help").Parse(templ))
|
|
||||||
err := t.Execute(w, data)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
w.Flush()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// append help to commands
|
a.didSetup = true
|
||||||
|
|
||||||
|
if a.Author != "" || a.Email != "" {
|
||||||
|
a.Authors = append(a.Authors, Author{Name: a.Author, Email: a.Email})
|
||||||
|
}
|
||||||
|
|
||||||
|
newCmds := []Command{}
|
||||||
|
for _, c := range a.Commands {
|
||||||
|
if c.HelpName == "" {
|
||||||
|
c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name)
|
||||||
|
}
|
||||||
|
newCmds = append(newCmds, c)
|
||||||
|
}
|
||||||
|
a.Commands = newCmds
|
||||||
|
|
||||||
if a.Command(helpCommand.Name) == nil && !a.HideHelp {
|
if a.Command(helpCommand.Name) == nil && !a.HideHelp {
|
||||||
a.Commands = append(a.Commands, helpCommand)
|
a.Commands = append(a.Commands, helpCommand)
|
||||||
if (HelpFlag != BoolFlag{}) {
|
if (HelpFlag != BoolFlag{}) {
|
||||||
|
@ -99,51 +151,98 @@ func (a *App) Run(arguments []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//append version/help flags
|
|
||||||
if a.EnableBashCompletion {
|
|
||||||
a.appendFlag(BashCompletionFlag)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !a.HideVersion {
|
if !a.HideVersion {
|
||||||
a.appendFlag(VersionFlag)
|
a.appendFlag(VersionFlag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse flags
|
a.categories = CommandCategories{}
|
||||||
set := flagSet(a.Name, a.Flags)
|
for _, command := range a.Commands {
|
||||||
set.SetOutput(ioutil.Discard)
|
a.categories = a.categories.AddCommand(command.Category, command)
|
||||||
err := set.Parse(arguments[1:])
|
|
||||||
nerr := normalizeFlags(a.Flags, set)
|
|
||||||
if nerr != nil {
|
|
||||||
fmt.Fprintln(a.Writer, nerr)
|
|
||||||
context := NewContext(a, set, set)
|
|
||||||
ShowAppHelp(context)
|
|
||||||
fmt.Fprintln(a.Writer)
|
|
||||||
return nerr
|
|
||||||
}
|
}
|
||||||
context := NewContext(a, set, set)
|
sort.Sort(a.categories)
|
||||||
|
|
||||||
|
if a.Metadata == nil {
|
||||||
|
a.Metadata = make(map[string]interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
if a.Writer == nil {
|
||||||
|
a.Writer = os.Stdout
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run is the entry point to the cli app. Parses the arguments slice and routes
|
||||||
|
// to the proper flag/args combination
|
||||||
|
func (a *App) Run(arguments []string) (err error) {
|
||||||
|
a.Setup()
|
||||||
|
|
||||||
|
// handle the completion flag separately from the flagset since
|
||||||
|
// completion could be attempted after a flag, but before its value was put
|
||||||
|
// on the command line. this causes the flagset to interpret the completion
|
||||||
|
// flag name as the value of the flag before it which is undesirable
|
||||||
|
// note that we can only do this because the shell autocomplete function
|
||||||
|
// always appends the completion flag at the end of the command
|
||||||
|
shellComplete, arguments := checkShellCompleteFlag(a, arguments)
|
||||||
|
|
||||||
|
// parse flags
|
||||||
|
set, err := flagSet(a.Name, a.Flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(a.Writer, "Incorrect Usage.\n\n")
|
|
||||||
ShowAppHelp(context)
|
|
||||||
fmt.Fprintln(a.Writer)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set.SetOutput(ioutil.Discard)
|
||||||
|
err = set.Parse(arguments[1:])
|
||||||
|
nerr := normalizeFlags(a.Flags, set)
|
||||||
|
context := NewContext(a, set, nil)
|
||||||
|
if nerr != nil {
|
||||||
|
fmt.Fprintln(a.Writer, nerr)
|
||||||
|
ShowAppHelp(context)
|
||||||
|
return nerr
|
||||||
|
}
|
||||||
|
context.shellComplete = shellComplete
|
||||||
|
|
||||||
if checkCompletions(context) {
|
if checkCompletions(context) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if checkHelp(context) {
|
if err != nil {
|
||||||
|
if a.OnUsageError != nil {
|
||||||
|
err := a.OnUsageError(context, err, false)
|
||||||
|
HandleExitCoder(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
|
||||||
|
ShowAppHelp(context)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !a.HideHelp && checkHelp(context) {
|
||||||
|
ShowAppHelp(context)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if checkVersion(context) {
|
if !a.HideVersion && checkVersion(context) {
|
||||||
|
ShowVersion(context)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if a.After != nil {
|
||||||
|
defer func() {
|
||||||
|
if afterErr := a.After(context); afterErr != nil {
|
||||||
|
if err != nil {
|
||||||
|
err = NewMultiError(err, afterErr)
|
||||||
|
} else {
|
||||||
|
err = afterErr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
if a.Before != nil {
|
if a.Before != nil {
|
||||||
err := a.Before(context)
|
beforeErr := a.Before(context)
|
||||||
if err != nil {
|
if beforeErr != nil {
|
||||||
|
ShowAppHelp(context)
|
||||||
|
HandleExitCoder(beforeErr)
|
||||||
|
err = beforeErr
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,21 +256,32 @@ func (a *App) Run(arguments []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if a.Action == nil {
|
||||||
|
a.Action = helpCommand.Action
|
||||||
|
}
|
||||||
|
|
||||||
// Run default Action
|
// Run default Action
|
||||||
a.Action(context)
|
err = HandleAction(a.Action, context)
|
||||||
return nil
|
|
||||||
|
HandleExitCoder(err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Another entry point to the cli app, takes care of passing arguments and error handling
|
// RunAndExitOnError calls .Run() and exits non-zero if an error was returned
|
||||||
|
//
|
||||||
|
// Deprecated: instead you should return an error that fulfills cli.ExitCoder
|
||||||
|
// to cli.App.Run. This will cause the application to exit with the given eror
|
||||||
|
// code in the cli.ExitCoder
|
||||||
func (a *App) RunAndExitOnError() {
|
func (a *App) RunAndExitOnError() {
|
||||||
if err := a.Run(os.Args); err != nil {
|
if err := a.Run(os.Args); err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(a.errWriter(), err)
|
||||||
os.Exit(1)
|
OsExiter(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invokes the subcommand given the context, parses ctx.Args() to generate command-specific flags
|
// RunAsSubcommand invokes the subcommand given the context, parses ctx.Args() to
|
||||||
func (a *App) RunAsSubcommand(ctx *Context) error {
|
// generate command-specific flags
|
||||||
|
func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
||||||
// append help to commands
|
// append help to commands
|
||||||
if len(a.Commands) > 0 {
|
if len(a.Commands) > 0 {
|
||||||
if a.Command(helpCommand.Name) == nil && !a.HideHelp {
|
if a.Command(helpCommand.Name) == nil && !a.HideHelp {
|
||||||
|
@ -182,39 +292,52 @@ func (a *App) RunAsSubcommand(ctx *Context) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// append flags
|
newCmds := []Command{}
|
||||||
if a.EnableBashCompletion {
|
for _, c := range a.Commands {
|
||||||
a.appendFlag(BashCompletionFlag)
|
if c.HelpName == "" {
|
||||||
|
c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name)
|
||||||
|
}
|
||||||
|
newCmds = append(newCmds, c)
|
||||||
}
|
}
|
||||||
|
a.Commands = newCmds
|
||||||
|
|
||||||
// parse flags
|
// parse flags
|
||||||
set := flagSet(a.Name, a.Flags)
|
set, err := flagSet(a.Name, a.Flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
set.SetOutput(ioutil.Discard)
|
set.SetOutput(ioutil.Discard)
|
||||||
err := set.Parse(ctx.Args().Tail())
|
err = set.Parse(ctx.Args().Tail())
|
||||||
nerr := normalizeFlags(a.Flags, set)
|
nerr := normalizeFlags(a.Flags, set)
|
||||||
context := NewContext(a, set, ctx.globalSet)
|
context := NewContext(a, set, ctx)
|
||||||
|
|
||||||
if nerr != nil {
|
if nerr != nil {
|
||||||
fmt.Fprintln(a.Writer, nerr)
|
fmt.Fprintln(a.Writer, nerr)
|
||||||
|
fmt.Fprintln(a.Writer)
|
||||||
if len(a.Commands) > 0 {
|
if len(a.Commands) > 0 {
|
||||||
ShowSubcommandHelp(context)
|
ShowSubcommandHelp(context)
|
||||||
} else {
|
} else {
|
||||||
ShowCommandHelp(ctx, context.Args().First())
|
ShowCommandHelp(ctx, context.Args().First())
|
||||||
}
|
}
|
||||||
fmt.Fprintln(a.Writer)
|
|
||||||
return nerr
|
return nerr
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(a.Writer, "Incorrect Usage.\n\n")
|
|
||||||
ShowSubcommandHelp(context)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if checkCompletions(context) {
|
if checkCompletions(context) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if a.OnUsageError != nil {
|
||||||
|
err = a.OnUsageError(context, err, true)
|
||||||
|
HandleExitCoder(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
|
||||||
|
ShowSubcommandHelp(context)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if len(a.Commands) > 0 {
|
if len(a.Commands) > 0 {
|
||||||
if checkSubcommandHelp(context) {
|
if checkSubcommandHelp(context) {
|
||||||
return nil
|
return nil
|
||||||
|
@ -225,9 +348,25 @@ func (a *App) RunAsSubcommand(ctx *Context) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if a.After != nil {
|
||||||
|
defer func() {
|
||||||
|
afterErr := a.After(context)
|
||||||
|
if afterErr != nil {
|
||||||
|
HandleExitCoder(err)
|
||||||
|
if err != nil {
|
||||||
|
err = NewMultiError(err, afterErr)
|
||||||
|
} else {
|
||||||
|
err = afterErr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
if a.Before != nil {
|
if a.Before != nil {
|
||||||
err := a.Before(context)
|
beforeErr := a.Before(context)
|
||||||
if err != nil {
|
if beforeErr != nil {
|
||||||
|
HandleExitCoder(beforeErr)
|
||||||
|
err = beforeErr
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,16 +381,13 @@ func (a *App) RunAsSubcommand(ctx *Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run default Action
|
// Run default Action
|
||||||
if len(a.Commands) > 0 {
|
err = HandleAction(a.Action, context)
|
||||||
a.Action(context)
|
|
||||||
} else {
|
|
||||||
a.Action(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
HandleExitCoder(err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the named command on App. Returns nil if the command does not exist
|
// Command returns the named command on App. Returns nil if the command does not exist
|
||||||
func (a *App) Command(name string) *Command {
|
func (a *App) Command(name string) *Command {
|
||||||
for _, c := range a.Commands {
|
for _, c := range a.Commands {
|
||||||
if c.HasName(name) {
|
if c.HasName(name) {
|
||||||
|
@ -262,6 +398,46 @@ func (a *App) Command(name string) *Command {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Categories returns a slice containing all the categories with the commands they contain
|
||||||
|
func (a *App) Categories() CommandCategories {
|
||||||
|
return a.categories
|
||||||
|
}
|
||||||
|
|
||||||
|
// VisibleCategories returns a slice of categories and commands that are
|
||||||
|
// Hidden=false
|
||||||
|
func (a *App) VisibleCategories() []*CommandCategory {
|
||||||
|
ret := []*CommandCategory{}
|
||||||
|
for _, category := range a.categories {
|
||||||
|
if visible := func() *CommandCategory {
|
||||||
|
for _, command := range category.Commands {
|
||||||
|
if !command.Hidden {
|
||||||
|
return category
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); visible != nil {
|
||||||
|
ret = append(ret, visible)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
// VisibleCommands returns a slice of the Commands with Hidden=false
|
||||||
|
func (a *App) VisibleCommands() []Command {
|
||||||
|
ret := []Command{}
|
||||||
|
for _, command := range a.Commands {
|
||||||
|
if !command.Hidden {
|
||||||
|
ret = append(ret, command)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
// VisibleFlags returns a slice of the Flags with Hidden=false
|
||||||
|
func (a *App) VisibleFlags() []Flag {
|
||||||
|
return visibleFlags(a.Flags)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) hasFlag(flag Flag) bool {
|
func (a *App) hasFlag(flag Flag) bool {
|
||||||
for _, f := range a.Flags {
|
for _, f := range a.Flags {
|
||||||
if flag == f {
|
if flag == f {
|
||||||
|
@ -272,8 +448,50 @@ func (a *App) hasFlag(flag Flag) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) errWriter() io.Writer {
|
||||||
|
|
||||||
|
// When the app ErrWriter is nil use the package level one.
|
||||||
|
if a.ErrWriter == nil {
|
||||||
|
return ErrWriter
|
||||||
|
}
|
||||||
|
|
||||||
|
return a.ErrWriter
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) appendFlag(flag Flag) {
|
func (a *App) appendFlag(flag Flag) {
|
||||||
if !a.hasFlag(flag) {
|
if !a.hasFlag(flag) {
|
||||||
a.Flags = append(a.Flags, flag)
|
a.Flags = append(a.Flags, flag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Author represents someone who has contributed to a cli project.
|
||||||
|
type Author struct {
|
||||||
|
Name string // The Authors name
|
||||||
|
Email string // The Authors email
|
||||||
|
}
|
||||||
|
|
||||||
|
// String makes Author comply to the Stringer interface, to allow an easy print in the templating process
|
||||||
|
func (a Author) String() string {
|
||||||
|
e := ""
|
||||||
|
if a.Email != "" {
|
||||||
|
e = " <" + a.Email + ">"
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%v%v", a.Name, e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleAction attempts to figure out which Action signature was used. If
|
||||||
|
// it's an ActionFunc or a func with the legacy signature for Action, the func
|
||||||
|
// is run!
|
||||||
|
func HandleAction(action interface{}, context *Context) (err error) {
|
||||||
|
if a, ok := action.(ActionFunc); ok {
|
||||||
|
return a(context)
|
||||||
|
} else if a, ok := action.(func(*Context) error); ok {
|
||||||
|
return a(context)
|
||||||
|
} else if a, ok := action.(func(*Context)); ok { // deprecated function signature
|
||||||
|
a(context)
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return errInvalidActionType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
44
vendor/github.com/codegangsta/cli/category.go
generated
vendored
Normal file
44
vendor/github.com/codegangsta/cli/category.go
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package cli
|
||||||
|
|
||||||
|
// CommandCategories is a slice of *CommandCategory.
|
||||||
|
type CommandCategories []*CommandCategory
|
||||||
|
|
||||||
|
// CommandCategory is a category containing commands.
|
||||||
|
type CommandCategory struct {
|
||||||
|
Name string
|
||||||
|
Commands Commands
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c CommandCategories) Less(i, j int) bool {
|
||||||
|
return c[i].Name < c[j].Name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c CommandCategories) Len() int {
|
||||||
|
return len(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c CommandCategories) Swap(i, j int) {
|
||||||
|
c[i], c[j] = c[j], c[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCommand adds a command to a category.
|
||||||
|
func (c CommandCategories) AddCommand(category string, command Command) CommandCategories {
|
||||||
|
for _, commandCategory := range c {
|
||||||
|
if commandCategory.Name == category {
|
||||||
|
commandCategory.Commands = append(commandCategory.Commands, command)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return append(c, &CommandCategory{Name: category, Commands: []Command{command}})
|
||||||
|
}
|
||||||
|
|
||||||
|
// VisibleCommands returns a slice of the Commands with Hidden=false
|
||||||
|
func (c *CommandCategory) VisibleCommands() []Command {
|
||||||
|
ret := []Command{}
|
||||||
|
for _, command := range c.Commands {
|
||||||
|
if !command.Hidden {
|
||||||
|
ret = append(ret, command)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
5
vendor/github.com/codegangsta/cli/cli.go
generated
vendored
5
vendor/github.com/codegangsta/cli/cli.go
generated
vendored
|
@ -10,10 +10,13 @@
|
||||||
// app := cli.NewApp()
|
// app := cli.NewApp()
|
||||||
// app.Name = "greet"
|
// app.Name = "greet"
|
||||||
// app.Usage = "say a greeting"
|
// app.Usage = "say a greeting"
|
||||||
// app.Action = func(c *cli.Context) {
|
// app.Action = func(c *cli.Context) error {
|
||||||
// println("Greetings")
|
// println("Greetings")
|
||||||
|
// return nil
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// app.Run(os.Args)
|
// app.Run(os.Args)
|
||||||
// }
|
// }
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
|
//go:generate python ./generate-flag-types cli -i flag-types.json -o flag_generated.go
|
||||||
|
|
250
vendor/github.com/codegangsta/cli/command.go
generated
vendored
250
vendor/github.com/codegangsta/cli/command.go
generated
vendored
|
@ -3,6 +3,7 @@ package cli
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -10,33 +11,90 @@ import (
|
||||||
type Command struct {
|
type Command struct {
|
||||||
// The name of the command
|
// The name of the command
|
||||||
Name string
|
Name string
|
||||||
// short name of the command. Typically one character
|
// short name of the command. Typically one character (deprecated, use `Aliases`)
|
||||||
ShortName string
|
ShortName string
|
||||||
|
// A list of aliases for the command
|
||||||
|
Aliases []string
|
||||||
// A short description of the usage of this command
|
// A short description of the usage of this command
|
||||||
Usage string
|
Usage string
|
||||||
|
// Custom text to show on USAGE section of help
|
||||||
|
UsageText string
|
||||||
// A longer explanation of how the command works
|
// A longer explanation of how the command works
|
||||||
Description string
|
Description string
|
||||||
|
// A short description of the arguments of this command
|
||||||
|
ArgsUsage string
|
||||||
|
// The category the command is part of
|
||||||
|
Category string
|
||||||
// The function to call when checking for bash command completions
|
// The function to call when checking for bash command completions
|
||||||
BashComplete func(context *Context)
|
BashComplete BashCompleteFunc
|
||||||
// An action to execute before any sub-subcommands are run, but after the context is ready
|
// An action to execute before any sub-subcommands are run, but after the context is ready
|
||||||
// If a non-nil error is returned, no sub-subcommands are run
|
// If a non-nil error is returned, no sub-subcommands are run
|
||||||
Before func(context *Context) error
|
Before BeforeFunc
|
||||||
|
// An action to execute after any subcommands are run, but after the subcommand has finished
|
||||||
|
// It is run even if Action() panics
|
||||||
|
After AfterFunc
|
||||||
// The function to call when this command is invoked
|
// The function to call when this command is invoked
|
||||||
Action func(context *Context)
|
Action interface{}
|
||||||
|
// TODO: replace `Action: interface{}` with `Action: ActionFunc` once some kind
|
||||||
|
// of deprecation period has passed, maybe?
|
||||||
|
|
||||||
|
// Execute this function if a usage error occurs.
|
||||||
|
OnUsageError OnUsageErrorFunc
|
||||||
// List of child commands
|
// List of child commands
|
||||||
Subcommands []Command
|
Subcommands Commands
|
||||||
// List of flags to parse
|
// List of flags to parse
|
||||||
Flags []Flag
|
Flags []Flag
|
||||||
// Treat all flags as normal arguments if true
|
// Treat all flags as normal arguments if true
|
||||||
SkipFlagParsing bool
|
SkipFlagParsing bool
|
||||||
|
// Skip argument reordering which attempts to move flags before arguments,
|
||||||
|
// but only works if all flags appear after all arguments. This behavior was
|
||||||
|
// removed n version 2 since it only works under specific conditions so we
|
||||||
|
// backport here by exposing it as an option for compatibility.
|
||||||
|
SkipArgReorder bool
|
||||||
// Boolean to hide built-in help command
|
// Boolean to hide built-in help command
|
||||||
HideHelp bool
|
HideHelp bool
|
||||||
|
// Boolean to hide this command from help or completion
|
||||||
|
Hidden bool
|
||||||
|
|
||||||
|
// Full name of command for help, defaults to full command name, including parent commands.
|
||||||
|
HelpName string
|
||||||
|
commandNamePath []string
|
||||||
|
|
||||||
|
// CustomHelpTemplate the text template for the command help topic.
|
||||||
|
// cli.go uses text/template to render templates. You can
|
||||||
|
// render custom help text by setting this variable.
|
||||||
|
CustomHelpTemplate string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invokes the command given the context, parses ctx.Args() to generate command-specific flags
|
type CommandsByName []Command
|
||||||
func (c Command) Run(ctx *Context) error {
|
|
||||||
|
|
||||||
if len(c.Subcommands) > 0 || c.Before != nil {
|
func (c CommandsByName) Len() int {
|
||||||
|
return len(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c CommandsByName) Less(i, j int) bool {
|
||||||
|
return c[i].Name < c[j].Name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c CommandsByName) Swap(i, j int) {
|
||||||
|
c[i], c[j] = c[j], c[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
// FullName returns the full name of the command.
|
||||||
|
// For subcommands this ensures that parent commands are part of the command path
|
||||||
|
func (c Command) FullName() string {
|
||||||
|
if c.commandNamePath == nil {
|
||||||
|
return c.Name
|
||||||
|
}
|
||||||
|
return strings.Join(c.commandNamePath, " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commands is a slice of Command
|
||||||
|
type Commands []Command
|
||||||
|
|
||||||
|
// Run invokes the command given the context, parses ctx.Args() to generate command-specific flags
|
||||||
|
func (c Command) Run(ctx *Context) (err error) {
|
||||||
|
if len(c.Subcommands) > 0 {
|
||||||
return c.startApp(ctx)
|
return c.startApp(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,96 +106,175 @@ func (c Command) Run(ctx *Context) error {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.App.EnableBashCompletion {
|
set, err := flagSet(c.Name, c.Flags)
|
||||||
c.Flags = append(c.Flags, BashCompletionFlag)
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
set := flagSet(c.Name, c.Flags)
|
|
||||||
set.SetOutput(ioutil.Discard)
|
set.SetOutput(ioutil.Discard)
|
||||||
|
|
||||||
firstFlagIndex := -1
|
if c.SkipFlagParsing {
|
||||||
terminatorIndex := -1
|
err = set.Parse(append([]string{"--"}, ctx.Args().Tail()...))
|
||||||
for index, arg := range ctx.Args() {
|
} else if !c.SkipArgReorder {
|
||||||
if arg == "--" {
|
firstFlagIndex := -1
|
||||||
terminatorIndex = index
|
terminatorIndex := -1
|
||||||
break
|
for index, arg := range ctx.Args() {
|
||||||
} else if strings.HasPrefix(arg, "-") && firstFlagIndex == -1 {
|
if arg == "--" {
|
||||||
firstFlagIndex = index
|
terminatorIndex = index
|
||||||
|
break
|
||||||
|
} else if arg == "-" {
|
||||||
|
// Do nothing. A dash alone is not really a flag.
|
||||||
|
continue
|
||||||
|
} else if strings.HasPrefix(arg, "-") && firstFlagIndex == -1 {
|
||||||
|
firstFlagIndex = index
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var err error
|
if firstFlagIndex > -1 {
|
||||||
if firstFlagIndex > -1 && !c.SkipFlagParsing {
|
args := ctx.Args()
|
||||||
args := ctx.Args()
|
regularArgs := make([]string, len(args[1:firstFlagIndex]))
|
||||||
regularArgs := make([]string, len(args[1:firstFlagIndex]))
|
copy(regularArgs, args[1:firstFlagIndex])
|
||||||
copy(regularArgs, args[1:firstFlagIndex])
|
|
||||||
|
|
||||||
var flagArgs []string
|
var flagArgs []string
|
||||||
if terminatorIndex > -1 {
|
if terminatorIndex > -1 {
|
||||||
flagArgs = args[firstFlagIndex:terminatorIndex]
|
flagArgs = args[firstFlagIndex:terminatorIndex]
|
||||||
regularArgs = append(regularArgs, args[terminatorIndex:]...)
|
regularArgs = append(regularArgs, args[terminatorIndex:]...)
|
||||||
|
} else {
|
||||||
|
flagArgs = args[firstFlagIndex:]
|
||||||
|
}
|
||||||
|
|
||||||
|
err = set.Parse(append(flagArgs, regularArgs...))
|
||||||
} else {
|
} else {
|
||||||
flagArgs = args[firstFlagIndex:]
|
err = set.Parse(ctx.Args().Tail())
|
||||||
}
|
}
|
||||||
|
|
||||||
err = set.Parse(append(flagArgs, regularArgs...))
|
|
||||||
} else {
|
} else {
|
||||||
err = set.Parse(ctx.Args().Tail())
|
err = set.Parse(ctx.Args().Tail())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprint(ctx.App.Writer, "Incorrect Usage.\n\n")
|
|
||||||
ShowCommandHelp(ctx, c.Name)
|
|
||||||
fmt.Fprintln(ctx.App.Writer)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
nerr := normalizeFlags(c.Flags, set)
|
nerr := normalizeFlags(c.Flags, set)
|
||||||
if nerr != nil {
|
if nerr != nil {
|
||||||
fmt.Fprintln(ctx.App.Writer, nerr)
|
fmt.Fprintln(ctx.App.Writer, nerr)
|
||||||
fmt.Fprintln(ctx.App.Writer)
|
fmt.Fprintln(ctx.App.Writer)
|
||||||
ShowCommandHelp(ctx, c.Name)
|
ShowCommandHelp(ctx, c.Name)
|
||||||
fmt.Fprintln(ctx.App.Writer)
|
|
||||||
return nerr
|
return nerr
|
||||||
}
|
}
|
||||||
context := NewContext(ctx.App, set, ctx.globalSet)
|
|
||||||
|
|
||||||
|
context := NewContext(ctx.App, set, ctx)
|
||||||
|
context.Command = c
|
||||||
if checkCommandCompletions(context, c.Name) {
|
if checkCommandCompletions(context, c.Name) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if c.OnUsageError != nil {
|
||||||
|
err := c.OnUsageError(context, err, false)
|
||||||
|
HandleExitCoder(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error())
|
||||||
|
fmt.Fprintln(context.App.Writer)
|
||||||
|
ShowCommandHelp(context, c.Name)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if checkCommandHelp(context, c.Name) {
|
if checkCommandHelp(context, c.Name) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
context.Command = c
|
|
||||||
c.Action(context)
|
if c.After != nil {
|
||||||
return nil
|
defer func() {
|
||||||
|
afterErr := c.After(context)
|
||||||
|
if afterErr != nil {
|
||||||
|
HandleExitCoder(err)
|
||||||
|
if err != nil {
|
||||||
|
err = NewMultiError(err, afterErr)
|
||||||
|
} else {
|
||||||
|
err = afterErr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Before != nil {
|
||||||
|
err = c.Before(context)
|
||||||
|
if err != nil {
|
||||||
|
ShowCommandHelp(context, c.Name)
|
||||||
|
HandleExitCoder(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Action == nil {
|
||||||
|
c.Action = helpSubcommand.Action
|
||||||
|
}
|
||||||
|
|
||||||
|
err = HandleAction(c.Action, context)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
HandleExitCoder(err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if Command.Name or Command.ShortName matches given name
|
// Names returns the names including short names and aliases.
|
||||||
|
func (c Command) Names() []string {
|
||||||
|
names := []string{c.Name}
|
||||||
|
|
||||||
|
if c.ShortName != "" {
|
||||||
|
names = append(names, c.ShortName)
|
||||||
|
}
|
||||||
|
|
||||||
|
return append(names, c.Aliases...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasName returns true if Command.Name or Command.ShortName matches given name
|
||||||
func (c Command) HasName(name string) bool {
|
func (c Command) HasName(name string) bool {
|
||||||
return c.Name == name || c.ShortName == name
|
for _, n := range c.Names() {
|
||||||
|
if n == name {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Command) startApp(ctx *Context) error {
|
func (c Command) startApp(ctx *Context) error {
|
||||||
app := NewApp()
|
app := NewApp()
|
||||||
|
app.Metadata = ctx.App.Metadata
|
||||||
// set the name and usage
|
// set the name and usage
|
||||||
app.Name = fmt.Sprintf("%s %s", ctx.App.Name, c.Name)
|
app.Name = fmt.Sprintf("%s %s", ctx.App.Name, c.Name)
|
||||||
if c.Description != "" {
|
if c.HelpName == "" {
|
||||||
app.Usage = c.Description
|
app.HelpName = c.HelpName
|
||||||
} else {
|
} else {
|
||||||
app.Usage = c.Usage
|
app.HelpName = app.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.Usage = c.Usage
|
||||||
|
app.Description = c.Description
|
||||||
|
app.ArgsUsage = c.ArgsUsage
|
||||||
|
|
||||||
// set CommandNotFound
|
// set CommandNotFound
|
||||||
app.CommandNotFound = ctx.App.CommandNotFound
|
app.CommandNotFound = ctx.App.CommandNotFound
|
||||||
|
app.CustomAppHelpTemplate = c.CustomHelpTemplate
|
||||||
|
|
||||||
// set the flags and commands
|
// set the flags and commands
|
||||||
app.Commands = c.Subcommands
|
app.Commands = c.Subcommands
|
||||||
app.Flags = c.Flags
|
app.Flags = c.Flags
|
||||||
app.HideHelp = c.HideHelp
|
app.HideHelp = c.HideHelp
|
||||||
|
|
||||||
|
app.Version = ctx.App.Version
|
||||||
|
app.HideVersion = ctx.App.HideVersion
|
||||||
|
app.Compiled = ctx.App.Compiled
|
||||||
|
app.Author = ctx.App.Author
|
||||||
|
app.Email = ctx.App.Email
|
||||||
|
app.Writer = ctx.App.Writer
|
||||||
|
app.ErrWriter = ctx.App.ErrWriter
|
||||||
|
|
||||||
|
app.categories = CommandCategories{}
|
||||||
|
for _, command := range c.Subcommands {
|
||||||
|
app.categories = app.categories.AddCommand(command.Category, command)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Sort(app.categories)
|
||||||
|
|
||||||
// bash completion
|
// bash completion
|
||||||
app.EnableBashCompletion = ctx.App.EnableBashCompletion
|
app.EnableBashCompletion = ctx.App.EnableBashCompletion
|
||||||
if c.BashComplete != nil {
|
if c.BashComplete != nil {
|
||||||
|
@ -146,11 +283,22 @@ func (c Command) startApp(ctx *Context) error {
|
||||||
|
|
||||||
// set the actions
|
// set the actions
|
||||||
app.Before = c.Before
|
app.Before = c.Before
|
||||||
|
app.After = c.After
|
||||||
if c.Action != nil {
|
if c.Action != nil {
|
||||||
app.Action = c.Action
|
app.Action = c.Action
|
||||||
} else {
|
} else {
|
||||||
app.Action = helpSubcommand.Action
|
app.Action = helpSubcommand.Action
|
||||||
}
|
}
|
||||||
|
app.OnUsageError = c.OnUsageError
|
||||||
|
|
||||||
|
for index, cc := range app.Commands {
|
||||||
|
app.Commands[index].commandNamePath = []string{c.Name, cc.Name}
|
||||||
|
}
|
||||||
|
|
||||||
return app.RunAsSubcommand(ctx)
|
return app.RunAsSubcommand(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VisibleFlags returns a slice of the Flags with Hidden=false
|
||||||
|
func (c Command) VisibleFlags() []Flag {
|
||||||
|
return visibleFlags(c.Flags)
|
||||||
|
}
|
||||||
|
|
337
vendor/github.com/codegangsta/cli/context.go
generated
vendored
337
vendor/github.com/codegangsta/cli/context.go
generated
vendored
|
@ -3,9 +3,9 @@ package cli
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"strconv"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Context is a type that is passed through to
|
// Context is a type that is passed through to
|
||||||
|
@ -13,125 +13,124 @@ import (
|
||||||
// can be used to retrieve context-specific Args and
|
// can be used to retrieve context-specific Args and
|
||||||
// parsed command-line options.
|
// parsed command-line options.
|
||||||
type Context struct {
|
type Context struct {
|
||||||
App *App
|
App *App
|
||||||
Command Command
|
Command Command
|
||||||
flagSet *flag.FlagSet
|
shellComplete bool
|
||||||
globalSet *flag.FlagSet
|
flagSet *flag.FlagSet
|
||||||
setFlags map[string]bool
|
setFlags map[string]bool
|
||||||
globalSetFlags map[string]bool
|
parentContext *Context
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new context. For use in when invoking an App or Command action.
|
// NewContext creates a new context. For use in when invoking an App or Command action.
|
||||||
func NewContext(app *App, set *flag.FlagSet, globalSet *flag.FlagSet) *Context {
|
func NewContext(app *App, set *flag.FlagSet, parentCtx *Context) *Context {
|
||||||
return &Context{App: app, flagSet: set, globalSet: globalSet}
|
c := &Context{App: app, flagSet: set, parentContext: parentCtx}
|
||||||
|
|
||||||
|
if parentCtx != nil {
|
||||||
|
c.shellComplete = parentCtx.shellComplete
|
||||||
|
}
|
||||||
|
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Looks up the value of a local int flag, returns 0 if no int flag exists
|
// NumFlags returns the number of flags set
|
||||||
func (c *Context) Int(name string) int {
|
func (c *Context) NumFlags() int {
|
||||||
return lookupInt(name, c.flagSet)
|
return c.flagSet.NFlag()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Looks up the value of a local time.Duration flag, returns 0 if no time.Duration flag exists
|
// Set sets a context flag to a value.
|
||||||
func (c *Context) Duration(name string) time.Duration {
|
func (c *Context) Set(name, value string) error {
|
||||||
return lookupDuration(name, c.flagSet)
|
c.setFlags = nil
|
||||||
|
return c.flagSet.Set(name, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Looks up the value of a local float64 flag, returns 0 if no float64 flag exists
|
// GlobalSet sets a context flag to a value on the global flagset
|
||||||
func (c *Context) Float64(name string) float64 {
|
func (c *Context) GlobalSet(name, value string) error {
|
||||||
return lookupFloat64(name, c.flagSet)
|
globalContext(c).setFlags = nil
|
||||||
|
return globalContext(c).flagSet.Set(name, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Looks up the value of a local bool flag, returns false if no bool flag exists
|
// IsSet determines if the flag was actually set
|
||||||
func (c *Context) Bool(name string) bool {
|
|
||||||
return lookupBool(name, c.flagSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Looks up the value of a local boolT flag, returns false if no bool flag exists
|
|
||||||
func (c *Context) BoolT(name string) bool {
|
|
||||||
return lookupBoolT(name, c.flagSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Looks up the value of a local string flag, returns "" if no string flag exists
|
|
||||||
func (c *Context) String(name string) string {
|
|
||||||
return lookupString(name, c.flagSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Looks up the value of a local string slice flag, returns nil if no string slice flag exists
|
|
||||||
func (c *Context) StringSlice(name string) []string {
|
|
||||||
return lookupStringSlice(name, c.flagSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Looks up the value of a local int slice flag, returns nil if no int slice flag exists
|
|
||||||
func (c *Context) IntSlice(name string) []int {
|
|
||||||
return lookupIntSlice(name, c.flagSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Looks up the value of a local generic flag, returns nil if no generic flag exists
|
|
||||||
func (c *Context) Generic(name string) interface{} {
|
|
||||||
return lookupGeneric(name, c.flagSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Looks up the value of a global int flag, returns 0 if no int flag exists
|
|
||||||
func (c *Context) GlobalInt(name string) int {
|
|
||||||
return lookupInt(name, c.globalSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Looks up the value of a global time.Duration flag, returns 0 if no time.Duration flag exists
|
|
||||||
func (c *Context) GlobalDuration(name string) time.Duration {
|
|
||||||
return lookupDuration(name, c.globalSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Looks up the value of a global bool flag, returns false if no bool flag exists
|
|
||||||
func (c *Context) GlobalBool(name string) bool {
|
|
||||||
return lookupBool(name, c.globalSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Looks up the value of a global string flag, returns "" if no string flag exists
|
|
||||||
func (c *Context) GlobalString(name string) string {
|
|
||||||
return lookupString(name, c.globalSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Looks up the value of a global string slice flag, returns nil if no string slice flag exists
|
|
||||||
func (c *Context) GlobalStringSlice(name string) []string {
|
|
||||||
return lookupStringSlice(name, c.globalSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Looks up the value of a global int slice flag, returns nil if no int slice flag exists
|
|
||||||
func (c *Context) GlobalIntSlice(name string) []int {
|
|
||||||
return lookupIntSlice(name, c.globalSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Looks up the value of a global generic flag, returns nil if no generic flag exists
|
|
||||||
func (c *Context) GlobalGeneric(name string) interface{} {
|
|
||||||
return lookupGeneric(name, c.globalSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determines if the flag was actually set
|
|
||||||
func (c *Context) IsSet(name string) bool {
|
func (c *Context) IsSet(name string) bool {
|
||||||
if c.setFlags == nil {
|
if c.setFlags == nil {
|
||||||
c.setFlags = make(map[string]bool)
|
c.setFlags = make(map[string]bool)
|
||||||
|
|
||||||
c.flagSet.Visit(func(f *flag.Flag) {
|
c.flagSet.Visit(func(f *flag.Flag) {
|
||||||
c.setFlags[f.Name] = true
|
c.setFlags[f.Name] = true
|
||||||
})
|
})
|
||||||
}
|
|
||||||
return c.setFlags[name] == true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determines if the global flag was actually set
|
c.flagSet.VisitAll(func(f *flag.Flag) {
|
||||||
func (c *Context) GlobalIsSet(name string) bool {
|
if _, ok := c.setFlags[f.Name]; ok {
|
||||||
if c.globalSetFlags == nil {
|
return
|
||||||
c.globalSetFlags = make(map[string]bool)
|
}
|
||||||
c.globalSet.Visit(func(f *flag.Flag) {
|
c.setFlags[f.Name] = false
|
||||||
c.globalSetFlags[f.Name] = true
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// XXX hack to support IsSet for flags with EnvVar
|
||||||
|
//
|
||||||
|
// There isn't an easy way to do this with the current implementation since
|
||||||
|
// whether a flag was set via an environment variable is very difficult to
|
||||||
|
// determine here. Instead, we intend to introduce a backwards incompatible
|
||||||
|
// change in version 2 to add `IsSet` to the Flag interface to push the
|
||||||
|
// responsibility closer to where the information required to determine
|
||||||
|
// whether a flag is set by non-standard means such as environment
|
||||||
|
// variables is avaliable.
|
||||||
|
//
|
||||||
|
// See https://github.com/urfave/cli/issues/294 for additional discussion
|
||||||
|
flags := c.Command.Flags
|
||||||
|
if c.Command.Name == "" { // cannot == Command{} since it contains slice types
|
||||||
|
if c.App != nil {
|
||||||
|
flags = c.App.Flags
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range flags {
|
||||||
|
eachName(f.GetName(), func(name string) {
|
||||||
|
if isSet, ok := c.setFlags[name]; isSet || !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val := reflect.ValueOf(f)
|
||||||
|
if val.Kind() == reflect.Ptr {
|
||||||
|
val = val.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
envVarValue := val.FieldByName("EnvVar")
|
||||||
|
if !envVarValue.IsValid() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
eachName(envVarValue.String(), func(envVar string) {
|
||||||
|
envVar = strings.TrimSpace(envVar)
|
||||||
|
if _, ok := syscall.Getenv(envVar); ok {
|
||||||
|
c.setFlags[name] = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return c.globalSetFlags[name] == true
|
|
||||||
|
return c.setFlags[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a slice of flag names used in this context.
|
// GlobalIsSet determines if the global flag was actually set
|
||||||
|
func (c *Context) GlobalIsSet(name string) bool {
|
||||||
|
ctx := c
|
||||||
|
if ctx.parentContext != nil {
|
||||||
|
ctx = ctx.parentContext
|
||||||
|
}
|
||||||
|
|
||||||
|
for ; ctx != nil; ctx = ctx.parentContext {
|
||||||
|
if ctx.IsSet(name) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// FlagNames returns a slice of flag names used in this context.
|
||||||
func (c *Context) FlagNames() (names []string) {
|
func (c *Context) FlagNames() (names []string) {
|
||||||
for _, flag := range c.Command.Flags {
|
for _, flag := range c.Command.Flags {
|
||||||
name := strings.Split(flag.getName(), ",")[0]
|
name := strings.Split(flag.GetName(), ",")[0]
|
||||||
if name == "help" {
|
if name == "help" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -140,10 +139,10 @@ func (c *Context) FlagNames() (names []string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a slice of global flag names used by the app.
|
// GlobalFlagNames returns a slice of global flag names used by the app.
|
||||||
func (c *Context) GlobalFlagNames() (names []string) {
|
func (c *Context) GlobalFlagNames() (names []string) {
|
||||||
for _, flag := range c.App.Flags {
|
for _, flag := range c.App.Flags {
|
||||||
name := strings.Split(flag.getName(), ",")[0]
|
name := strings.Split(flag.GetName(), ",")[0]
|
||||||
if name == "help" || name == "version" {
|
if name == "help" || name == "version" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -152,15 +151,31 @@ func (c *Context) GlobalFlagNames() (names []string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parent returns the parent context, if any
|
||||||
|
func (c *Context) Parent() *Context {
|
||||||
|
return c.parentContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// value returns the value of the flag coressponding to `name`
|
||||||
|
func (c *Context) value(name string) interface{} {
|
||||||
|
return c.flagSet.Lookup(name).Value.(flag.Getter).Get()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Args contains apps console arguments
|
||||||
type Args []string
|
type Args []string
|
||||||
|
|
||||||
// Returns the command line arguments associated with the context.
|
// Args returns the command line arguments associated with the context.
|
||||||
func (c *Context) Args() Args {
|
func (c *Context) Args() Args {
|
||||||
args := Args(c.flagSet.Args())
|
args := Args(c.flagSet.Args())
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the nth argument, or else a blank string
|
// NArg returns the number of the command line arguments.
|
||||||
|
func (c *Context) NArg() int {
|
||||||
|
return len(c.Args())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns the nth argument, or else a blank string
|
||||||
func (a Args) Get(n int) string {
|
func (a Args) Get(n int) string {
|
||||||
if len(a) > n {
|
if len(a) > n {
|
||||||
return a[n]
|
return a[n]
|
||||||
|
@ -168,12 +183,12 @@ func (a Args) Get(n int) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the first argument, or else a blank string
|
// First returns the first argument, or else a blank string
|
||||||
func (a Args) First() string {
|
func (a Args) First() string {
|
||||||
return a.Get(0)
|
return a.Get(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the rest of the arguments (not the first one)
|
// Tail returns the rest of the arguments (not the first one)
|
||||||
// or else an empty string slice
|
// or else an empty string slice
|
||||||
func (a Args) Tail() []string {
|
func (a Args) Tail() []string {
|
||||||
if len(a) >= 2 {
|
if len(a) >= 2 {
|
||||||
|
@ -182,12 +197,12 @@ func (a Args) Tail() []string {
|
||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if there are any arguments present
|
// Present checks if there are any arguments present
|
||||||
func (a Args) Present() bool {
|
func (a Args) Present() bool {
|
||||||
return len(a) != 0
|
return len(a) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swaps arguments at the given indexes
|
// Swap swaps arguments at the given indexes
|
||||||
func (a Args) Swap(from, to int) error {
|
func (a Args) Swap(from, to int) error {
|
||||||
if from >= len(a) || to >= len(a) {
|
if from >= len(a) || to >= len(a) {
|
||||||
return errors.New("index out of range")
|
return errors.New("index out of range")
|
||||||
|
@ -196,107 +211,31 @@ func (a Args) Swap(from, to int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookupInt(name string, set *flag.FlagSet) int {
|
func globalContext(ctx *Context) *Context {
|
||||||
f := set.Lookup(name)
|
if ctx == nil {
|
||||||
if f != nil {
|
return nil
|
||||||
val, err := strconv.Atoi(f.Value.String())
|
}
|
||||||
if err != nil {
|
|
||||||
return 0
|
for {
|
||||||
|
if ctx.parentContext == nil {
|
||||||
|
return ctx
|
||||||
}
|
}
|
||||||
return val
|
ctx = ctx.parentContext
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookupDuration(name string, set *flag.FlagSet) time.Duration {
|
func lookupGlobalFlagSet(name string, ctx *Context) *flag.FlagSet {
|
||||||
f := set.Lookup(name)
|
if ctx.parentContext != nil {
|
||||||
if f != nil {
|
ctx = ctx.parentContext
|
||||||
val, err := time.ParseDuration(f.Value.String())
|
}
|
||||||
if err == nil {
|
for ; ctx != nil; ctx = ctx.parentContext {
|
||||||
return val
|
if f := ctx.flagSet.Lookup(name); f != nil {
|
||||||
|
return ctx.flagSet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func lookupFloat64(name string, set *flag.FlagSet) float64 {
|
|
||||||
f := set.Lookup(name)
|
|
||||||
if f != nil {
|
|
||||||
val, err := strconv.ParseFloat(f.Value.String(), 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return val
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func lookupString(name string, set *flag.FlagSet) string {
|
|
||||||
f := set.Lookup(name)
|
|
||||||
if f != nil {
|
|
||||||
return f.Value.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func lookupStringSlice(name string, set *flag.FlagSet) []string {
|
|
||||||
f := set.Lookup(name)
|
|
||||||
if f != nil {
|
|
||||||
return (f.Value.(*StringSlice)).Value()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func lookupIntSlice(name string, set *flag.FlagSet) []int {
|
|
||||||
f := set.Lookup(name)
|
|
||||||
if f != nil {
|
|
||||||
return (f.Value.(*IntSlice)).Value()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func lookupGeneric(name string, set *flag.FlagSet) interface{} {
|
|
||||||
f := set.Lookup(name)
|
|
||||||
if f != nil {
|
|
||||||
return f.Value
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookupBool(name string, set *flag.FlagSet) bool {
|
|
||||||
f := set.Lookup(name)
|
|
||||||
if f != nil {
|
|
||||||
val, err := strconv.ParseBool(f.Value.String())
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return val
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func lookupBoolT(name string, set *flag.FlagSet) bool {
|
|
||||||
f := set.Lookup(name)
|
|
||||||
if f != nil {
|
|
||||||
val, err := strconv.ParseBool(f.Value.String())
|
|
||||||
if err != nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return val
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) {
|
func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) {
|
||||||
switch ff.Value.(type) {
|
switch ff.Value.(type) {
|
||||||
case *StringSlice:
|
case *StringSlice:
|
||||||
|
@ -311,7 +250,7 @@ func normalizeFlags(flags []Flag, set *flag.FlagSet) error {
|
||||||
visited[f.Name] = true
|
visited[f.Name] = true
|
||||||
})
|
})
|
||||||
for _, f := range flags {
|
for _, f := range flags {
|
||||||
parts := strings.Split(f.getName(), ",")
|
parts := strings.Split(f.GetName(), ",")
|
||||||
if len(parts) == 1 {
|
if len(parts) == 1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
115
vendor/github.com/codegangsta/cli/errors.go
generated
vendored
Normal file
115
vendor/github.com/codegangsta/cli/errors.go
generated
vendored
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// OsExiter is the function used when the app exits. If not set defaults to os.Exit.
|
||||||
|
var OsExiter = os.Exit
|
||||||
|
|
||||||
|
// ErrWriter is used to write errors to the user. This can be anything
|
||||||
|
// implementing the io.Writer interface and defaults to os.Stderr.
|
||||||
|
var ErrWriter io.Writer = os.Stderr
|
||||||
|
|
||||||
|
// MultiError is an error that wraps multiple errors.
|
||||||
|
type MultiError struct {
|
||||||
|
Errors []error
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMultiError creates a new MultiError. Pass in one or more errors.
|
||||||
|
func NewMultiError(err ...error) MultiError {
|
||||||
|
return MultiError{Errors: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (m MultiError) Error() string {
|
||||||
|
errs := make([]string, len(m.Errors))
|
||||||
|
for i, err := range m.Errors {
|
||||||
|
errs[i] = err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(errs, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
type ErrorFormatter interface {
|
||||||
|
Format(s fmt.State, verb rune)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExitCoder is the interface checked by `App` and `Command` for a custom exit
|
||||||
|
// code
|
||||||
|
type ExitCoder interface {
|
||||||
|
error
|
||||||
|
ExitCode() int
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExitError fulfills both the builtin `error` interface and `ExitCoder`
|
||||||
|
type ExitError struct {
|
||||||
|
exitCode int
|
||||||
|
message interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewExitError makes a new *ExitError
|
||||||
|
func NewExitError(message interface{}, exitCode int) *ExitError {
|
||||||
|
return &ExitError{
|
||||||
|
exitCode: exitCode,
|
||||||
|
message: message,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error returns the string message, fulfilling the interface required by
|
||||||
|
// `error`
|
||||||
|
func (ee *ExitError) Error() string {
|
||||||
|
return fmt.Sprintf("%v", ee.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExitCode returns the exit code, fulfilling the interface required by
|
||||||
|
// `ExitCoder`
|
||||||
|
func (ee *ExitError) ExitCode() int {
|
||||||
|
return ee.exitCode
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleExitCoder checks if the error fulfills the ExitCoder interface, and if
|
||||||
|
// so prints the error to stderr (if it is non-empty) and calls OsExiter with the
|
||||||
|
// given exit code. If the given error is a MultiError, then this func is
|
||||||
|
// called on all members of the Errors slice and calls OsExiter with the last exit code.
|
||||||
|
func HandleExitCoder(err error) {
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if exitErr, ok := err.(ExitCoder); ok {
|
||||||
|
if err.Error() != "" {
|
||||||
|
if _, ok := exitErr.(ErrorFormatter); ok {
|
||||||
|
fmt.Fprintf(ErrWriter, "%+v\n", err)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintln(ErrWriter, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OsExiter(exitErr.ExitCode())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if multiErr, ok := err.(MultiError); ok {
|
||||||
|
code := handleMultiError(multiErr)
|
||||||
|
OsExiter(code)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMultiError(multiErr MultiError) int {
|
||||||
|
code := 1
|
||||||
|
for _, merr := range multiErr.Errors {
|
||||||
|
if multiErr2, ok := merr.(MultiError); ok {
|
||||||
|
code = handleMultiError(multiErr2)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintln(ErrWriter, merr)
|
||||||
|
if exitErr, ok := merr.(ExitCoder); ok {
|
||||||
|
code = exitErr.ExitCode()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return code
|
||||||
|
}
|
791
vendor/github.com/codegangsta/cli/flag.go
generated
vendored
791
vendor/github.com/codegangsta/cli/flag.go
generated
vendored
|
@ -3,48 +3,88 @@ package cli
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"reflect"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This flag enables bash-completion for all commands and subcommands
|
const defaultPlaceholder = "value"
|
||||||
var BashCompletionFlag = BoolFlag{
|
|
||||||
Name: "generate-bash-completion",
|
// BashCompletionFlag enables bash-completion for all commands and subcommands
|
||||||
|
var BashCompletionFlag Flag = BoolFlag{
|
||||||
|
Name: "generate-bash-completion",
|
||||||
|
Hidden: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// This flag prints the version for the application
|
// VersionFlag prints the version for the application
|
||||||
var VersionFlag = BoolFlag{
|
var VersionFlag Flag = BoolFlag{
|
||||||
Name: "version, v",
|
Name: "version, v",
|
||||||
Usage: "print the version",
|
Usage: "print the version",
|
||||||
}
|
}
|
||||||
|
|
||||||
// This flag prints the help for all commands and subcommands
|
// HelpFlag prints the help for all commands and subcommands
|
||||||
// Set to the zero value (BoolFlag{}) to disable flag -- keeps subcommand
|
// Set to the zero value (BoolFlag{}) to disable flag -- keeps subcommand
|
||||||
// unless HideHelp is set to true)
|
// unless HideHelp is set to true)
|
||||||
var HelpFlag = BoolFlag{
|
var HelpFlag Flag = BoolFlag{
|
||||||
Name: "help, h",
|
Name: "help, h",
|
||||||
Usage: "show help",
|
Usage: "show help",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FlagStringer converts a flag definition to a string. This is used by help
|
||||||
|
// to display a flag.
|
||||||
|
var FlagStringer FlagStringFunc = stringifyFlag
|
||||||
|
|
||||||
|
// FlagsByName is a slice of Flag.
|
||||||
|
type FlagsByName []Flag
|
||||||
|
|
||||||
|
func (f FlagsByName) Len() int {
|
||||||
|
return len(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f FlagsByName) Less(i, j int) bool {
|
||||||
|
return f[i].GetName() < f[j].GetName()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f FlagsByName) Swap(i, j int) {
|
||||||
|
f[i], f[j] = f[j], f[i]
|
||||||
|
}
|
||||||
|
|
||||||
// Flag is a common interface related to parsing flags in cli.
|
// Flag is a common interface related to parsing flags in cli.
|
||||||
// For more advanced flag parsing techniques, it is recomended that
|
// For more advanced flag parsing techniques, it is recommended that
|
||||||
// this interface be implemented.
|
// this interface be implemented.
|
||||||
type Flag interface {
|
type Flag interface {
|
||||||
fmt.Stringer
|
fmt.Stringer
|
||||||
// Apply Flag settings to the given flag set
|
// Apply Flag settings to the given flag set
|
||||||
Apply(*flag.FlagSet)
|
Apply(*flag.FlagSet)
|
||||||
getName() string
|
GetName() string
|
||||||
}
|
}
|
||||||
|
|
||||||
func flagSet(name string, flags []Flag) *flag.FlagSet {
|
// errorableFlag is an interface that allows us to return errors during apply
|
||||||
|
// it allows flags defined in this library to return errors in a fashion backwards compatible
|
||||||
|
// TODO remove in v2 and modify the existing Flag interface to return errors
|
||||||
|
type errorableFlag interface {
|
||||||
|
Flag
|
||||||
|
|
||||||
|
ApplyWithError(*flag.FlagSet) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func flagSet(name string, flags []Flag) (*flag.FlagSet, error) {
|
||||||
set := flag.NewFlagSet(name, flag.ContinueOnError)
|
set := flag.NewFlagSet(name, flag.ContinueOnError)
|
||||||
|
|
||||||
for _, f := range flags {
|
for _, f := range flags {
|
||||||
f.Apply(set)
|
//TODO remove in v2 when errorableFlag is removed
|
||||||
|
if ef, ok := f.(errorableFlag); ok {
|
||||||
|
if err := ef.ApplyWithError(set); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
f.Apply(set)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return set
|
return set, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func eachName(longName string, fn func(string)) {
|
func eachName(longName string, fn func(string)) {
|
||||||
|
@ -61,30 +101,24 @@ type Generic interface {
|
||||||
String() string
|
String() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenericFlag is the flag type for types implementing Generic
|
|
||||||
type GenericFlag struct {
|
|
||||||
Name string
|
|
||||||
Value Generic
|
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns the string representation of the generic flag to display the
|
|
||||||
// help text to the user (uses the String() method of the generic flag to show
|
|
||||||
// the value)
|
|
||||||
func (f GenericFlag) String() string {
|
|
||||||
return withEnvHint(f.EnvVar, fmt.Sprintf("%s%s \"%v\"\t%v", prefixFor(f.Name), f.Name, f.Value, f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply takes the flagset and calls Set on the generic flag with the value
|
// Apply takes the flagset and calls Set on the generic flag with the value
|
||||||
// provided by the user for parsing by the flag
|
// provided by the user for parsing by the flag
|
||||||
|
// Ignores parsing errors
|
||||||
func (f GenericFlag) Apply(set *flag.FlagSet) {
|
func (f GenericFlag) Apply(set *flag.FlagSet) {
|
||||||
|
f.ApplyWithError(set)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyWithError takes the flagset and calls Set on the generic flag with the value
|
||||||
|
// provided by the user for parsing by the flag
|
||||||
|
func (f GenericFlag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
val := f.Value
|
val := f.Value
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
envVar = strings.TrimSpace(envVar)
|
envVar = strings.TrimSpace(envVar)
|
||||||
if envVal := os.Getenv(envVar); envVal != "" {
|
if envVal, ok := syscall.Getenv(envVar); ok {
|
||||||
val.Set(envVal)
|
if err := val.Set(envVal); err != nil {
|
||||||
|
return fmt.Errorf("could not parse %s as value for flag %s: %s", envVal, f.Name, err)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,110 +127,51 @@ func (f GenericFlag) Apply(set *flag.FlagSet) {
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
set.Var(f.Value, name, f.Usage)
|
set.Var(f.Value, name, f.Usage)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f GenericFlag) getName() string {
|
// StringSlice is an opaque type for []string to satisfy flag.Value and flag.Getter
|
||||||
return f.Name
|
|
||||||
}
|
|
||||||
|
|
||||||
type StringSlice []string
|
type StringSlice []string
|
||||||
|
|
||||||
|
// Set appends the string value to the list of values
|
||||||
func (f *StringSlice) Set(value string) error {
|
func (f *StringSlice) Set(value string) error {
|
||||||
*f = append(*f, value)
|
*f = append(*f, value)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns a readable representation of this value (for usage defaults)
|
||||||
func (f *StringSlice) String() string {
|
func (f *StringSlice) String() string {
|
||||||
return fmt.Sprintf("%s", *f)
|
return fmt.Sprintf("%s", *f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Value returns the slice of strings set by this flag
|
||||||
func (f *StringSlice) Value() []string {
|
func (f *StringSlice) Value() []string {
|
||||||
return *f
|
return *f
|
||||||
}
|
}
|
||||||
|
|
||||||
type StringSliceFlag struct {
|
// Get returns the slice of strings set by this flag
|
||||||
Name string
|
func (f *StringSlice) Get() interface{} {
|
||||||
Value *StringSlice
|
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f StringSliceFlag) String() string {
|
|
||||||
firstName := strings.Trim(strings.Split(f.Name, ",")[0], " ")
|
|
||||||
pref := prefixFor(firstName)
|
|
||||||
return withEnvHint(f.EnvVar, fmt.Sprintf("%s [%v]\t%v", prefixedNames(f.Name), pref+firstName+" option "+pref+firstName+" option", f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f StringSliceFlag) Apply(set *flag.FlagSet) {
|
|
||||||
if f.EnvVar != "" {
|
|
||||||
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
|
||||||
envVar = strings.TrimSpace(envVar)
|
|
||||||
if envVal := os.Getenv(envVar); envVal != "" {
|
|
||||||
newVal := &StringSlice{}
|
|
||||||
for _, s := range strings.Split(envVal, ",") {
|
|
||||||
s = strings.TrimSpace(s)
|
|
||||||
newVal.Set(s)
|
|
||||||
}
|
|
||||||
f.Value = newVal
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eachName(f.Name, func(name string) {
|
|
||||||
set.Var(f.Value, name, f.Usage)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f StringSliceFlag) getName() string {
|
|
||||||
return f.Name
|
|
||||||
}
|
|
||||||
|
|
||||||
type IntSlice []int
|
|
||||||
|
|
||||||
func (f *IntSlice) Set(value string) error {
|
|
||||||
|
|
||||||
tmp, err := strconv.Atoi(value)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
} else {
|
|
||||||
*f = append(*f, tmp)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *IntSlice) String() string {
|
|
||||||
return fmt.Sprintf("%d", *f)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *IntSlice) Value() []int {
|
|
||||||
return *f
|
return *f
|
||||||
}
|
}
|
||||||
|
|
||||||
type IntSliceFlag struct {
|
// Apply populates the flag given the flag set and environment
|
||||||
Name string
|
// Ignores errors
|
||||||
Value *IntSlice
|
func (f StringSliceFlag) Apply(set *flag.FlagSet) {
|
||||||
Usage string
|
f.ApplyWithError(set)
|
||||||
EnvVar string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f IntSliceFlag) String() string {
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
firstName := strings.Trim(strings.Split(f.Name, ",")[0], " ")
|
func (f StringSliceFlag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
pref := prefixFor(firstName)
|
|
||||||
return withEnvHint(f.EnvVar, fmt.Sprintf("%s [%v]\t%v", prefixedNames(f.Name), pref+firstName+" option "+pref+firstName+" option", f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f IntSliceFlag) Apply(set *flag.FlagSet) {
|
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
envVar = strings.TrimSpace(envVar)
|
envVar = strings.TrimSpace(envVar)
|
||||||
if envVal := os.Getenv(envVar); envVal != "" {
|
if envVal, ok := syscall.Getenv(envVar); ok {
|
||||||
newVal := &IntSlice{}
|
newVal := &StringSlice{}
|
||||||
for _, s := range strings.Split(envVal, ",") {
|
for _, s := range strings.Split(envVal, ",") {
|
||||||
s = strings.TrimSpace(s)
|
s = strings.TrimSpace(s)
|
||||||
err := newVal.Set(s)
|
if err := newVal.Set(s); err != nil {
|
||||||
if err != nil {
|
return fmt.Errorf("could not parse %s as string value for flag %s: %s", envVal, f.Name, err)
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.Value = newVal
|
f.Value = newVal
|
||||||
|
@ -206,107 +181,232 @@ func (f IntSliceFlag) Apply(set *flag.FlagSet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
|
if f.Value == nil {
|
||||||
|
f.Value = &StringSlice{}
|
||||||
|
}
|
||||||
set.Var(f.Value, name, f.Usage)
|
set.Var(f.Value, name, f.Usage)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f IntSliceFlag) getName() string {
|
// IntSlice is an opaque type for []int to satisfy flag.Value and flag.Getter
|
||||||
return f.Name
|
type IntSlice []int
|
||||||
|
|
||||||
|
// Set parses the value into an integer and appends it to the list of values
|
||||||
|
func (f *IntSlice) Set(value string) error {
|
||||||
|
tmp, err := strconv.Atoi(value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*f = append(*f, tmp)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type BoolFlag struct {
|
// String returns a readable representation of this value (for usage defaults)
|
||||||
Name string
|
func (f *IntSlice) String() string {
|
||||||
Usage string
|
return fmt.Sprintf("%#v", *f)
|
||||||
EnvVar string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f BoolFlag) String() string {
|
// Value returns the slice of ints set by this flag
|
||||||
return withEnvHint(f.EnvVar, fmt.Sprintf("%s\t%v", prefixedNames(f.Name), f.Usage))
|
func (f *IntSlice) Value() []int {
|
||||||
|
return *f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f BoolFlag) Apply(set *flag.FlagSet) {
|
// Get returns the slice of ints set by this flag
|
||||||
val := false
|
func (f *IntSlice) Get() interface{} {
|
||||||
|
return *f
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply populates the flag given the flag set and environment
|
||||||
|
// Ignores errors
|
||||||
|
func (f IntSliceFlag) Apply(set *flag.FlagSet) {
|
||||||
|
f.ApplyWithError(set)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
|
func (f IntSliceFlag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
envVar = strings.TrimSpace(envVar)
|
envVar = strings.TrimSpace(envVar)
|
||||||
if envVal := os.Getenv(envVar); envVal != "" {
|
if envVal, ok := syscall.Getenv(envVar); ok {
|
||||||
envValBool, err := strconv.ParseBool(envVal)
|
newVal := &IntSlice{}
|
||||||
if err == nil {
|
for _, s := range strings.Split(envVal, ",") {
|
||||||
val = envValBool
|
s = strings.TrimSpace(s)
|
||||||
|
if err := newVal.Set(s); err != nil {
|
||||||
|
return fmt.Errorf("could not parse %s as int slice value for flag %s: %s", envVal, f.Name, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
f.Value = newVal
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
set.Bool(name, val, f.Usage)
|
if f.Value == nil {
|
||||||
|
f.Value = &IntSlice{}
|
||||||
|
}
|
||||||
|
set.Var(f.Value, name, f.Usage)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f BoolFlag) getName() string {
|
// Int64Slice is an opaque type for []int to satisfy flag.Value and flag.Getter
|
||||||
return f.Name
|
type Int64Slice []int64
|
||||||
|
|
||||||
|
// Set parses the value into an integer and appends it to the list of values
|
||||||
|
func (f *Int64Slice) Set(value string) error {
|
||||||
|
tmp, err := strconv.ParseInt(value, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*f = append(*f, tmp)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type BoolTFlag struct {
|
// String returns a readable representation of this value (for usage defaults)
|
||||||
Name string
|
func (f *Int64Slice) String() string {
|
||||||
Usage string
|
return fmt.Sprintf("%#v", *f)
|
||||||
EnvVar string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f BoolTFlag) String() string {
|
// Value returns the slice of ints set by this flag
|
||||||
return withEnvHint(f.EnvVar, fmt.Sprintf("%s\t%v", prefixedNames(f.Name), f.Usage))
|
func (f *Int64Slice) Value() []int64 {
|
||||||
|
return *f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f BoolTFlag) Apply(set *flag.FlagSet) {
|
// Get returns the slice of ints set by this flag
|
||||||
val := true
|
func (f *Int64Slice) Get() interface{} {
|
||||||
|
return *f
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply populates the flag given the flag set and environment
|
||||||
|
// Ignores errors
|
||||||
|
func (f Int64SliceFlag) Apply(set *flag.FlagSet) {
|
||||||
|
f.ApplyWithError(set)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
|
func (f Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
envVar = strings.TrimSpace(envVar)
|
envVar = strings.TrimSpace(envVar)
|
||||||
if envVal := os.Getenv(envVar); envVal != "" {
|
if envVal, ok := syscall.Getenv(envVar); ok {
|
||||||
envValBool, err := strconv.ParseBool(envVal)
|
newVal := &Int64Slice{}
|
||||||
if err == nil {
|
for _, s := range strings.Split(envVal, ",") {
|
||||||
val = envValBool
|
s = strings.TrimSpace(s)
|
||||||
break
|
if err := newVal.Set(s); err != nil {
|
||||||
|
return fmt.Errorf("could not parse %s as int64 slice value for flag %s: %s", envVal, f.Name, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
f.Value = newVal
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
set.Bool(name, val, f.Usage)
|
if f.Value == nil {
|
||||||
|
f.Value = &Int64Slice{}
|
||||||
|
}
|
||||||
|
set.Var(f.Value, name, f.Usage)
|
||||||
})
|
})
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f BoolTFlag) getName() string {
|
// Apply populates the flag given the flag set and environment
|
||||||
return f.Name
|
// Ignores errors
|
||||||
|
func (f BoolFlag) Apply(set *flag.FlagSet) {
|
||||||
|
f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
type StringFlag struct {
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
Name string
|
func (f BoolFlag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
Value string
|
val := false
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f StringFlag) String() string {
|
|
||||||
var fmtString string
|
|
||||||
fmtString = "%s %v\t%v"
|
|
||||||
|
|
||||||
if len(f.Value) > 0 {
|
|
||||||
fmtString = "%s \"%v\"\t%v"
|
|
||||||
} else {
|
|
||||||
fmtString = "%s %v\t%v"
|
|
||||||
}
|
|
||||||
|
|
||||||
return withEnvHint(f.EnvVar, fmt.Sprintf(fmtString, prefixedNames(f.Name), f.Value, f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f StringFlag) Apply(set *flag.FlagSet) {
|
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
envVar = strings.TrimSpace(envVar)
|
envVar = strings.TrimSpace(envVar)
|
||||||
if envVal := os.Getenv(envVar); envVal != "" {
|
if envVal, ok := syscall.Getenv(envVar); ok {
|
||||||
|
if envVal == "" {
|
||||||
|
val = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
envValBool, err := strconv.ParseBool(envVal)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
val = envValBool
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eachName(f.Name, func(name string) {
|
||||||
|
if f.Destination != nil {
|
||||||
|
set.BoolVar(f.Destination, name, val, f.Usage)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
set.Bool(name, val, f.Usage)
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply populates the flag given the flag set and environment
|
||||||
|
// Ignores errors
|
||||||
|
func (f BoolTFlag) Apply(set *flag.FlagSet) {
|
||||||
|
f.ApplyWithError(set)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
|
func (f BoolTFlag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
|
val := true
|
||||||
|
if f.EnvVar != "" {
|
||||||
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
|
envVar = strings.TrimSpace(envVar)
|
||||||
|
if envVal, ok := syscall.Getenv(envVar); ok {
|
||||||
|
if envVal == "" {
|
||||||
|
val = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
envValBool, err := strconv.ParseBool(envVal)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
val = envValBool
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eachName(f.Name, func(name string) {
|
||||||
|
if f.Destination != nil {
|
||||||
|
set.BoolVar(f.Destination, name, val, f.Usage)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
set.Bool(name, val, f.Usage)
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply populates the flag given the flag set and environment
|
||||||
|
// Ignores errors
|
||||||
|
func (f StringFlag) Apply(set *flag.FlagSet) {
|
||||||
|
f.ApplyWithError(set)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
|
func (f StringFlag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
|
if f.EnvVar != "" {
|
||||||
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
|
envVar = strings.TrimSpace(envVar)
|
||||||
|
if envVal, ok := syscall.Getenv(envVar); ok {
|
||||||
f.Value = envVal
|
f.Value = envVal
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -314,113 +414,228 @@ func (f StringFlag) Apply(set *flag.FlagSet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
|
if f.Destination != nil {
|
||||||
|
set.StringVar(f.Destination, name, f.Value, f.Usage)
|
||||||
|
return
|
||||||
|
}
|
||||||
set.String(name, f.Value, f.Usage)
|
set.String(name, f.Value, f.Usage)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f StringFlag) getName() string {
|
// Apply populates the flag given the flag set and environment
|
||||||
return f.Name
|
// Ignores errors
|
||||||
}
|
|
||||||
|
|
||||||
type IntFlag struct {
|
|
||||||
Name string
|
|
||||||
Value int
|
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f IntFlag) String() string {
|
|
||||||
return withEnvHint(f.EnvVar, fmt.Sprintf("%s \"%v\"\t%v", prefixedNames(f.Name), f.Value, f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f IntFlag) Apply(set *flag.FlagSet) {
|
func (f IntFlag) Apply(set *flag.FlagSet) {
|
||||||
|
f.ApplyWithError(set)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
|
func (f IntFlag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
envVar = strings.TrimSpace(envVar)
|
envVar = strings.TrimSpace(envVar)
|
||||||
if envVal := os.Getenv(envVar); envVal != "" {
|
if envVal, ok := syscall.Getenv(envVar); ok {
|
||||||
envValInt, err := strconv.ParseInt(envVal, 0, 64)
|
envValInt, err := strconv.ParseInt(envVal, 0, 64)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
f.Value = int(envValInt)
|
return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err)
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
f.Value = int(envValInt)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
|
if f.Destination != nil {
|
||||||
|
set.IntVar(f.Destination, name, f.Value, f.Usage)
|
||||||
|
return
|
||||||
|
}
|
||||||
set.Int(name, f.Value, f.Usage)
|
set.Int(name, f.Value, f.Usage)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f IntFlag) getName() string {
|
// Apply populates the flag given the flag set and environment
|
||||||
return f.Name
|
// Ignores errors
|
||||||
|
func (f Int64Flag) Apply(set *flag.FlagSet) {
|
||||||
|
f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
type DurationFlag struct {
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
Name string
|
func (f Int64Flag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
Value time.Duration
|
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f DurationFlag) String() string {
|
|
||||||
return withEnvHint(f.EnvVar, fmt.Sprintf("%s \"%v\"\t%v", prefixedNames(f.Name), f.Value, f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f DurationFlag) Apply(set *flag.FlagSet) {
|
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
envVar = strings.TrimSpace(envVar)
|
envVar = strings.TrimSpace(envVar)
|
||||||
if envVal := os.Getenv(envVar); envVal != "" {
|
if envVal, ok := syscall.Getenv(envVar); ok {
|
||||||
envValDuration, err := time.ParseDuration(envVal)
|
envValInt, err := strconv.ParseInt(envVal, 0, 64)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
f.Value = envValDuration
|
return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err)
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f.Value = envValInt
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
|
if f.Destination != nil {
|
||||||
|
set.Int64Var(f.Destination, name, f.Value, f.Usage)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
set.Int64(name, f.Value, f.Usage)
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply populates the flag given the flag set and environment
|
||||||
|
// Ignores errors
|
||||||
|
func (f UintFlag) Apply(set *flag.FlagSet) {
|
||||||
|
f.ApplyWithError(set)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
|
func (f UintFlag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
|
if f.EnvVar != "" {
|
||||||
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
|
envVar = strings.TrimSpace(envVar)
|
||||||
|
if envVal, ok := syscall.Getenv(envVar); ok {
|
||||||
|
envValInt, err := strconv.ParseUint(envVal, 0, 64)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not parse %s as uint value for flag %s: %s", envVal, f.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
f.Value = uint(envValInt)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eachName(f.Name, func(name string) {
|
||||||
|
if f.Destination != nil {
|
||||||
|
set.UintVar(f.Destination, name, f.Value, f.Usage)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
set.Uint(name, f.Value, f.Usage)
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply populates the flag given the flag set and environment
|
||||||
|
// Ignores errors
|
||||||
|
func (f Uint64Flag) Apply(set *flag.FlagSet) {
|
||||||
|
f.ApplyWithError(set)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
|
func (f Uint64Flag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
|
if f.EnvVar != "" {
|
||||||
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
|
envVar = strings.TrimSpace(envVar)
|
||||||
|
if envVal, ok := syscall.Getenv(envVar); ok {
|
||||||
|
envValInt, err := strconv.ParseUint(envVal, 0, 64)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not parse %s as uint64 value for flag %s: %s", envVal, f.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
f.Value = uint64(envValInt)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eachName(f.Name, func(name string) {
|
||||||
|
if f.Destination != nil {
|
||||||
|
set.Uint64Var(f.Destination, name, f.Value, f.Usage)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
set.Uint64(name, f.Value, f.Usage)
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply populates the flag given the flag set and environment
|
||||||
|
// Ignores errors
|
||||||
|
func (f DurationFlag) Apply(set *flag.FlagSet) {
|
||||||
|
f.ApplyWithError(set)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
|
func (f DurationFlag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
|
if f.EnvVar != "" {
|
||||||
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
|
envVar = strings.TrimSpace(envVar)
|
||||||
|
if envVal, ok := syscall.Getenv(envVar); ok {
|
||||||
|
envValDuration, err := time.ParseDuration(envVal)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not parse %s as duration for flag %s: %s", envVal, f.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
f.Value = envValDuration
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eachName(f.Name, func(name string) {
|
||||||
|
if f.Destination != nil {
|
||||||
|
set.DurationVar(f.Destination, name, f.Value, f.Usage)
|
||||||
|
return
|
||||||
|
}
|
||||||
set.Duration(name, f.Value, f.Usage)
|
set.Duration(name, f.Value, f.Usage)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f DurationFlag) getName() string {
|
// Apply populates the flag given the flag set and environment
|
||||||
return f.Name
|
// Ignores errors
|
||||||
}
|
|
||||||
|
|
||||||
type Float64Flag struct {
|
|
||||||
Name string
|
|
||||||
Value float64
|
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f Float64Flag) String() string {
|
|
||||||
return withEnvHint(f.EnvVar, fmt.Sprintf("%s \"%v\"\t%v", prefixedNames(f.Name), f.Value, f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f Float64Flag) Apply(set *flag.FlagSet) {
|
func (f Float64Flag) Apply(set *flag.FlagSet) {
|
||||||
|
f.ApplyWithError(set)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
|
func (f Float64Flag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
envVar = strings.TrimSpace(envVar)
|
envVar = strings.TrimSpace(envVar)
|
||||||
if envVal := os.Getenv(envVar); envVal != "" {
|
if envVal, ok := syscall.Getenv(envVar); ok {
|
||||||
envValFloat, err := strconv.ParseFloat(envVal, 10)
|
envValFloat, err := strconv.ParseFloat(envVal, 10)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
f.Value = float64(envValFloat)
|
return fmt.Errorf("could not parse %s as float64 value for flag %s: %s", envVal, f.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f.Value = float64(envValFloat)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
|
if f.Destination != nil {
|
||||||
|
set.Float64Var(f.Destination, name, f.Value, f.Usage)
|
||||||
|
return
|
||||||
|
}
|
||||||
set.Float64(name, f.Value, f.Usage)
|
set.Float64(name, f.Value, f.Usage)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Float64Flag) getName() string {
|
func visibleFlags(fl []Flag) []Flag {
|
||||||
return f.Name
|
visible := []Flag{}
|
||||||
|
for _, flag := range fl {
|
||||||
|
field := flagValue(flag).FieldByName("Hidden")
|
||||||
|
if !field.IsValid() || !field.Bool() {
|
||||||
|
visible = append(visible, flag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return visible
|
||||||
}
|
}
|
||||||
|
|
||||||
func prefixFor(name string) (prefix string) {
|
func prefixFor(name string) (prefix string) {
|
||||||
|
@ -433,22 +648,152 @@ func prefixFor(name string) (prefix string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func prefixedNames(fullName string) (prefixed string) {
|
// Returns the placeholder, if any, and the unquoted usage string.
|
||||||
|
func unquoteUsage(usage string) (string, string) {
|
||||||
|
for i := 0; i < len(usage); i++ {
|
||||||
|
if usage[i] == '`' {
|
||||||
|
for j := i + 1; j < len(usage); j++ {
|
||||||
|
if usage[j] == '`' {
|
||||||
|
name := usage[i+1 : j]
|
||||||
|
usage = usage[:i] + name + usage[j+1:]
|
||||||
|
return name, usage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", usage
|
||||||
|
}
|
||||||
|
|
||||||
|
func prefixedNames(fullName, placeholder string) string {
|
||||||
|
var prefixed string
|
||||||
parts := strings.Split(fullName, ",")
|
parts := strings.Split(fullName, ",")
|
||||||
for i, name := range parts {
|
for i, name := range parts {
|
||||||
name = strings.Trim(name, " ")
|
name = strings.Trim(name, " ")
|
||||||
prefixed += prefixFor(name) + name
|
prefixed += prefixFor(name) + name
|
||||||
|
if placeholder != "" {
|
||||||
|
prefixed += " " + placeholder
|
||||||
|
}
|
||||||
if i < len(parts)-1 {
|
if i < len(parts)-1 {
|
||||||
prefixed += ", "
|
prefixed += ", "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return prefixed
|
||||||
}
|
}
|
||||||
|
|
||||||
func withEnvHint(envVar, str string) string {
|
func withEnvHint(envVar, str string) string {
|
||||||
envText := ""
|
envText := ""
|
||||||
if envVar != "" {
|
if envVar != "" {
|
||||||
envText = fmt.Sprintf(" [$%s]", strings.Join(strings.Split(envVar, ","), ", $"))
|
prefix := "$"
|
||||||
|
suffix := ""
|
||||||
|
sep := ", $"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
prefix = "%"
|
||||||
|
suffix = "%"
|
||||||
|
sep = "%, %"
|
||||||
|
}
|
||||||
|
envText = fmt.Sprintf(" [%s%s%s]", prefix, strings.Join(strings.Split(envVar, ","), sep), suffix)
|
||||||
}
|
}
|
||||||
return str + envText
|
return str + envText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func flagValue(f Flag) reflect.Value {
|
||||||
|
fv := reflect.ValueOf(f)
|
||||||
|
for fv.Kind() == reflect.Ptr {
|
||||||
|
fv = reflect.Indirect(fv)
|
||||||
|
}
|
||||||
|
return fv
|
||||||
|
}
|
||||||
|
|
||||||
|
func stringifyFlag(f Flag) string {
|
||||||
|
fv := flagValue(f)
|
||||||
|
|
||||||
|
switch f.(type) {
|
||||||
|
case IntSliceFlag:
|
||||||
|
return withEnvHint(fv.FieldByName("EnvVar").String(),
|
||||||
|
stringifyIntSliceFlag(f.(IntSliceFlag)))
|
||||||
|
case Int64SliceFlag:
|
||||||
|
return withEnvHint(fv.FieldByName("EnvVar").String(),
|
||||||
|
stringifyInt64SliceFlag(f.(Int64SliceFlag)))
|
||||||
|
case StringSliceFlag:
|
||||||
|
return withEnvHint(fv.FieldByName("EnvVar").String(),
|
||||||
|
stringifyStringSliceFlag(f.(StringSliceFlag)))
|
||||||
|
}
|
||||||
|
|
||||||
|
placeholder, usage := unquoteUsage(fv.FieldByName("Usage").String())
|
||||||
|
|
||||||
|
needsPlaceholder := false
|
||||||
|
defaultValueString := ""
|
||||||
|
|
||||||
|
if val := fv.FieldByName("Value"); val.IsValid() {
|
||||||
|
needsPlaceholder = true
|
||||||
|
defaultValueString = fmt.Sprintf(" (default: %v)", val.Interface())
|
||||||
|
|
||||||
|
if val.Kind() == reflect.String && val.String() != "" {
|
||||||
|
defaultValueString = fmt.Sprintf(" (default: %q)", val.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if defaultValueString == " (default: )" {
|
||||||
|
defaultValueString = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if needsPlaceholder && placeholder == "" {
|
||||||
|
placeholder = defaultPlaceholder
|
||||||
|
}
|
||||||
|
|
||||||
|
usageWithDefault := strings.TrimSpace(fmt.Sprintf("%s%s", usage, defaultValueString))
|
||||||
|
|
||||||
|
return withEnvHint(fv.FieldByName("EnvVar").String(),
|
||||||
|
fmt.Sprintf("%s\t%s", prefixedNames(fv.FieldByName("Name").String(), placeholder), usageWithDefault))
|
||||||
|
}
|
||||||
|
|
||||||
|
func stringifyIntSliceFlag(f IntSliceFlag) string {
|
||||||
|
defaultVals := []string{}
|
||||||
|
if f.Value != nil && len(f.Value.Value()) > 0 {
|
||||||
|
for _, i := range f.Value.Value() {
|
||||||
|
defaultVals = append(defaultVals, fmt.Sprintf("%d", i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringifySliceFlag(f.Usage, f.Name, defaultVals)
|
||||||
|
}
|
||||||
|
|
||||||
|
func stringifyInt64SliceFlag(f Int64SliceFlag) string {
|
||||||
|
defaultVals := []string{}
|
||||||
|
if f.Value != nil && len(f.Value.Value()) > 0 {
|
||||||
|
for _, i := range f.Value.Value() {
|
||||||
|
defaultVals = append(defaultVals, fmt.Sprintf("%d", i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringifySliceFlag(f.Usage, f.Name, defaultVals)
|
||||||
|
}
|
||||||
|
|
||||||
|
func stringifyStringSliceFlag(f StringSliceFlag) string {
|
||||||
|
defaultVals := []string{}
|
||||||
|
if f.Value != nil && len(f.Value.Value()) > 0 {
|
||||||
|
for _, s := range f.Value.Value() {
|
||||||
|
if len(s) > 0 {
|
||||||
|
defaultVals = append(defaultVals, fmt.Sprintf("%q", s))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringifySliceFlag(f.Usage, f.Name, defaultVals)
|
||||||
|
}
|
||||||
|
|
||||||
|
func stringifySliceFlag(usage, name string, defaultVals []string) string {
|
||||||
|
placeholder, usage := unquoteUsage(usage)
|
||||||
|
if placeholder == "" {
|
||||||
|
placeholder = defaultPlaceholder
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultVal := ""
|
||||||
|
if len(defaultVals) > 0 {
|
||||||
|
defaultVal = fmt.Sprintf(" (default: %s)", strings.Join(defaultVals, ", "))
|
||||||
|
}
|
||||||
|
|
||||||
|
usageWithDefault := strings.TrimSpace(fmt.Sprintf("%s%s", usage, defaultVal))
|
||||||
|
return fmt.Sprintf("%s\t%s", prefixedNames(name, placeholder), usageWithDefault)
|
||||||
|
}
|
||||||
|
|
627
vendor/github.com/codegangsta/cli/flag_generated.go
generated
vendored
Normal file
627
vendor/github.com/codegangsta/cli/flag_generated.go
generated
vendored
Normal file
|
@ -0,0 +1,627 @@
|
||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WARNING: This file is generated!
|
||||||
|
|
||||||
|
// BoolFlag is a flag with type bool
|
||||||
|
type BoolFlag struct {
|
||||||
|
Name string
|
||||||
|
Usage string
|
||||||
|
EnvVar string
|
||||||
|
Hidden bool
|
||||||
|
Destination *bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a readable representation of this value
|
||||||
|
// (for usage defaults)
|
||||||
|
func (f BoolFlag) String() string {
|
||||||
|
return FlagStringer(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the name of the flag
|
||||||
|
func (f BoolFlag) GetName() string {
|
||||||
|
return f.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bool looks up the value of a local BoolFlag, returns
|
||||||
|
// false if not found
|
||||||
|
func (c *Context) Bool(name string) bool {
|
||||||
|
return lookupBool(name, c.flagSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlobalBool looks up the value of a global BoolFlag, returns
|
||||||
|
// false if not found
|
||||||
|
func (c *Context) GlobalBool(name string) bool {
|
||||||
|
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||||
|
return lookupBool(name, fs)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookupBool(name string, set *flag.FlagSet) bool {
|
||||||
|
f := set.Lookup(name)
|
||||||
|
if f != nil {
|
||||||
|
parsed, err := strconv.ParseBool(f.Value.String())
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolTFlag is a flag with type bool that is true by default
|
||||||
|
type BoolTFlag struct {
|
||||||
|
Name string
|
||||||
|
Usage string
|
||||||
|
EnvVar string
|
||||||
|
Hidden bool
|
||||||
|
Destination *bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a readable representation of this value
|
||||||
|
// (for usage defaults)
|
||||||
|
func (f BoolTFlag) String() string {
|
||||||
|
return FlagStringer(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the name of the flag
|
||||||
|
func (f BoolTFlag) GetName() string {
|
||||||
|
return f.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolT looks up the value of a local BoolTFlag, returns
|
||||||
|
// false if not found
|
||||||
|
func (c *Context) BoolT(name string) bool {
|
||||||
|
return lookupBoolT(name, c.flagSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlobalBoolT looks up the value of a global BoolTFlag, returns
|
||||||
|
// false if not found
|
||||||
|
func (c *Context) GlobalBoolT(name string) bool {
|
||||||
|
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||||
|
return lookupBoolT(name, fs)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookupBoolT(name string, set *flag.FlagSet) bool {
|
||||||
|
f := set.Lookup(name)
|
||||||
|
if f != nil {
|
||||||
|
parsed, err := strconv.ParseBool(f.Value.String())
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// DurationFlag is a flag with type time.Duration (see https://golang.org/pkg/time/#ParseDuration)
|
||||||
|
type DurationFlag struct {
|
||||||
|
Name string
|
||||||
|
Usage string
|
||||||
|
EnvVar string
|
||||||
|
Hidden bool
|
||||||
|
Value time.Duration
|
||||||
|
Destination *time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a readable representation of this value
|
||||||
|
// (for usage defaults)
|
||||||
|
func (f DurationFlag) String() string {
|
||||||
|
return FlagStringer(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the name of the flag
|
||||||
|
func (f DurationFlag) GetName() string {
|
||||||
|
return f.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Duration looks up the value of a local DurationFlag, returns
|
||||||
|
// 0 if not found
|
||||||
|
func (c *Context) Duration(name string) time.Duration {
|
||||||
|
return lookupDuration(name, c.flagSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlobalDuration looks up the value of a global DurationFlag, returns
|
||||||
|
// 0 if not found
|
||||||
|
func (c *Context) GlobalDuration(name string) time.Duration {
|
||||||
|
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||||
|
return lookupDuration(name, fs)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookupDuration(name string, set *flag.FlagSet) time.Duration {
|
||||||
|
f := set.Lookup(name)
|
||||||
|
if f != nil {
|
||||||
|
parsed, err := time.ParseDuration(f.Value.String())
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64Flag is a flag with type float64
|
||||||
|
type Float64Flag struct {
|
||||||
|
Name string
|
||||||
|
Usage string
|
||||||
|
EnvVar string
|
||||||
|
Hidden bool
|
||||||
|
Value float64
|
||||||
|
Destination *float64
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a readable representation of this value
|
||||||
|
// (for usage defaults)
|
||||||
|
func (f Float64Flag) String() string {
|
||||||
|
return FlagStringer(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the name of the flag
|
||||||
|
func (f Float64Flag) GetName() string {
|
||||||
|
return f.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 looks up the value of a local Float64Flag, returns
|
||||||
|
// 0 if not found
|
||||||
|
func (c *Context) Float64(name string) float64 {
|
||||||
|
return lookupFloat64(name, c.flagSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlobalFloat64 looks up the value of a global Float64Flag, returns
|
||||||
|
// 0 if not found
|
||||||
|
func (c *Context) GlobalFloat64(name string) float64 {
|
||||||
|
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||||
|
return lookupFloat64(name, fs)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookupFloat64(name string, set *flag.FlagSet) float64 {
|
||||||
|
f := set.Lookup(name)
|
||||||
|
if f != nil {
|
||||||
|
parsed, err := strconv.ParseFloat(f.Value.String(), 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenericFlag is a flag with type Generic
|
||||||
|
type GenericFlag struct {
|
||||||
|
Name string
|
||||||
|
Usage string
|
||||||
|
EnvVar string
|
||||||
|
Hidden bool
|
||||||
|
Value Generic
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a readable representation of this value
|
||||||
|
// (for usage defaults)
|
||||||
|
func (f GenericFlag) String() string {
|
||||||
|
return FlagStringer(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the name of the flag
|
||||||
|
func (f GenericFlag) GetName() string {
|
||||||
|
return f.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generic looks up the value of a local GenericFlag, returns
|
||||||
|
// nil if not found
|
||||||
|
func (c *Context) Generic(name string) interface{} {
|
||||||
|
return lookupGeneric(name, c.flagSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlobalGeneric looks up the value of a global GenericFlag, returns
|
||||||
|
// nil if not found
|
||||||
|
func (c *Context) GlobalGeneric(name string) interface{} {
|
||||||
|
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||||
|
return lookupGeneric(name, fs)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookupGeneric(name string, set *flag.FlagSet) interface{} {
|
||||||
|
f := set.Lookup(name)
|
||||||
|
if f != nil {
|
||||||
|
parsed, err := f.Value, error(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64Flag is a flag with type int64
|
||||||
|
type Int64Flag struct {
|
||||||
|
Name string
|
||||||
|
Usage string
|
||||||
|
EnvVar string
|
||||||
|
Hidden bool
|
||||||
|
Value int64
|
||||||
|
Destination *int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a readable representation of this value
|
||||||
|
// (for usage defaults)
|
||||||
|
func (f Int64Flag) String() string {
|
||||||
|
return FlagStringer(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the name of the flag
|
||||||
|
func (f Int64Flag) GetName() string {
|
||||||
|
return f.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64 looks up the value of a local Int64Flag, returns
|
||||||
|
// 0 if not found
|
||||||
|
func (c *Context) Int64(name string) int64 {
|
||||||
|
return lookupInt64(name, c.flagSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlobalInt64 looks up the value of a global Int64Flag, returns
|
||||||
|
// 0 if not found
|
||||||
|
func (c *Context) GlobalInt64(name string) int64 {
|
||||||
|
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||||
|
return lookupInt64(name, fs)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookupInt64(name string, set *flag.FlagSet) int64 {
|
||||||
|
f := set.Lookup(name)
|
||||||
|
if f != nil {
|
||||||
|
parsed, err := strconv.ParseInt(f.Value.String(), 0, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntFlag is a flag with type int
|
||||||
|
type IntFlag struct {
|
||||||
|
Name string
|
||||||
|
Usage string
|
||||||
|
EnvVar string
|
||||||
|
Hidden bool
|
||||||
|
Value int
|
||||||
|
Destination *int
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a readable representation of this value
|
||||||
|
// (for usage defaults)
|
||||||
|
func (f IntFlag) String() string {
|
||||||
|
return FlagStringer(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the name of the flag
|
||||||
|
func (f IntFlag) GetName() string {
|
||||||
|
return f.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int looks up the value of a local IntFlag, returns
|
||||||
|
// 0 if not found
|
||||||
|
func (c *Context) Int(name string) int {
|
||||||
|
return lookupInt(name, c.flagSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlobalInt looks up the value of a global IntFlag, returns
|
||||||
|
// 0 if not found
|
||||||
|
func (c *Context) GlobalInt(name string) int {
|
||||||
|
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||||
|
return lookupInt(name, fs)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookupInt(name string, set *flag.FlagSet) int {
|
||||||
|
f := set.Lookup(name)
|
||||||
|
if f != nil {
|
||||||
|
parsed, err := strconv.ParseInt(f.Value.String(), 0, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return int(parsed)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntSliceFlag is a flag with type *IntSlice
|
||||||
|
type IntSliceFlag struct {
|
||||||
|
Name string
|
||||||
|
Usage string
|
||||||
|
EnvVar string
|
||||||
|
Hidden bool
|
||||||
|
Value *IntSlice
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a readable representation of this value
|
||||||
|
// (for usage defaults)
|
||||||
|
func (f IntSliceFlag) String() string {
|
||||||
|
return FlagStringer(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the name of the flag
|
||||||
|
func (f IntSliceFlag) GetName() string {
|
||||||
|
return f.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntSlice looks up the value of a local IntSliceFlag, returns
|
||||||
|
// nil if not found
|
||||||
|
func (c *Context) IntSlice(name string) []int {
|
||||||
|
return lookupIntSlice(name, c.flagSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlobalIntSlice looks up the value of a global IntSliceFlag, returns
|
||||||
|
// nil if not found
|
||||||
|
func (c *Context) GlobalIntSlice(name string) []int {
|
||||||
|
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||||
|
return lookupIntSlice(name, fs)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookupIntSlice(name string, set *flag.FlagSet) []int {
|
||||||
|
f := set.Lookup(name)
|
||||||
|
if f != nil {
|
||||||
|
parsed, err := (f.Value.(*IntSlice)).Value(), error(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64SliceFlag is a flag with type *Int64Slice
|
||||||
|
type Int64SliceFlag struct {
|
||||||
|
Name string
|
||||||
|
Usage string
|
||||||
|
EnvVar string
|
||||||
|
Hidden bool
|
||||||
|
Value *Int64Slice
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a readable representation of this value
|
||||||
|
// (for usage defaults)
|
||||||
|
func (f Int64SliceFlag) String() string {
|
||||||
|
return FlagStringer(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the name of the flag
|
||||||
|
func (f Int64SliceFlag) GetName() string {
|
||||||
|
return f.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64Slice looks up the value of a local Int64SliceFlag, returns
|
||||||
|
// nil if not found
|
||||||
|
func (c *Context) Int64Slice(name string) []int64 {
|
||||||
|
return lookupInt64Slice(name, c.flagSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlobalInt64Slice looks up the value of a global Int64SliceFlag, returns
|
||||||
|
// nil if not found
|
||||||
|
func (c *Context) GlobalInt64Slice(name string) []int64 {
|
||||||
|
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||||
|
return lookupInt64Slice(name, fs)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookupInt64Slice(name string, set *flag.FlagSet) []int64 {
|
||||||
|
f := set.Lookup(name)
|
||||||
|
if f != nil {
|
||||||
|
parsed, err := (f.Value.(*Int64Slice)).Value(), error(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringFlag is a flag with type string
|
||||||
|
type StringFlag struct {
|
||||||
|
Name string
|
||||||
|
Usage string
|
||||||
|
EnvVar string
|
||||||
|
Hidden bool
|
||||||
|
Value string
|
||||||
|
Destination *string
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a readable representation of this value
|
||||||
|
// (for usage defaults)
|
||||||
|
func (f StringFlag) String() string {
|
||||||
|
return FlagStringer(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the name of the flag
|
||||||
|
func (f StringFlag) GetName() string {
|
||||||
|
return f.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// String looks up the value of a local StringFlag, returns
|
||||||
|
// "" if not found
|
||||||
|
func (c *Context) String(name string) string {
|
||||||
|
return lookupString(name, c.flagSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlobalString looks up the value of a global StringFlag, returns
|
||||||
|
// "" if not found
|
||||||
|
func (c *Context) GlobalString(name string) string {
|
||||||
|
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||||
|
return lookupString(name, fs)
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookupString(name string, set *flag.FlagSet) string {
|
||||||
|
f := set.Lookup(name)
|
||||||
|
if f != nil {
|
||||||
|
parsed, err := f.Value.String(), error(nil)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringSliceFlag is a flag with type *StringSlice
|
||||||
|
type StringSliceFlag struct {
|
||||||
|
Name string
|
||||||
|
Usage string
|
||||||
|
EnvVar string
|
||||||
|
Hidden bool
|
||||||
|
Value *StringSlice
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a readable representation of this value
|
||||||
|
// (for usage defaults)
|
||||||
|
func (f StringSliceFlag) String() string {
|
||||||
|
return FlagStringer(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the name of the flag
|
||||||
|
func (f StringSliceFlag) GetName() string {
|
||||||
|
return f.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringSlice looks up the value of a local StringSliceFlag, returns
|
||||||
|
// nil if not found
|
||||||
|
func (c *Context) StringSlice(name string) []string {
|
||||||
|
return lookupStringSlice(name, c.flagSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlobalStringSlice looks up the value of a global StringSliceFlag, returns
|
||||||
|
// nil if not found
|
||||||
|
func (c *Context) GlobalStringSlice(name string) []string {
|
||||||
|
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||||
|
return lookupStringSlice(name, fs)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookupStringSlice(name string, set *flag.FlagSet) []string {
|
||||||
|
f := set.Lookup(name)
|
||||||
|
if f != nil {
|
||||||
|
parsed, err := (f.Value.(*StringSlice)).Value(), error(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uint64Flag is a flag with type uint64
|
||||||
|
type Uint64Flag struct {
|
||||||
|
Name string
|
||||||
|
Usage string
|
||||||
|
EnvVar string
|
||||||
|
Hidden bool
|
||||||
|
Value uint64
|
||||||
|
Destination *uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a readable representation of this value
|
||||||
|
// (for usage defaults)
|
||||||
|
func (f Uint64Flag) String() string {
|
||||||
|
return FlagStringer(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the name of the flag
|
||||||
|
func (f Uint64Flag) GetName() string {
|
||||||
|
return f.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uint64 looks up the value of a local Uint64Flag, returns
|
||||||
|
// 0 if not found
|
||||||
|
func (c *Context) Uint64(name string) uint64 {
|
||||||
|
return lookupUint64(name, c.flagSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlobalUint64 looks up the value of a global Uint64Flag, returns
|
||||||
|
// 0 if not found
|
||||||
|
func (c *Context) GlobalUint64(name string) uint64 {
|
||||||
|
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||||
|
return lookupUint64(name, fs)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookupUint64(name string, set *flag.FlagSet) uint64 {
|
||||||
|
f := set.Lookup(name)
|
||||||
|
if f != nil {
|
||||||
|
parsed, err := strconv.ParseUint(f.Value.String(), 0, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// UintFlag is a flag with type uint
|
||||||
|
type UintFlag struct {
|
||||||
|
Name string
|
||||||
|
Usage string
|
||||||
|
EnvVar string
|
||||||
|
Hidden bool
|
||||||
|
Value uint
|
||||||
|
Destination *uint
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a readable representation of this value
|
||||||
|
// (for usage defaults)
|
||||||
|
func (f UintFlag) String() string {
|
||||||
|
return FlagStringer(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the name of the flag
|
||||||
|
func (f UintFlag) GetName() string {
|
||||||
|
return f.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uint looks up the value of a local UintFlag, returns
|
||||||
|
// 0 if not found
|
||||||
|
func (c *Context) Uint(name string) uint {
|
||||||
|
return lookupUint(name, c.flagSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GlobalUint looks up the value of a global UintFlag, returns
|
||||||
|
// 0 if not found
|
||||||
|
func (c *Context) GlobalUint(name string) uint {
|
||||||
|
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
||||||
|
return lookupUint(name, fs)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookupUint(name string, set *flag.FlagSet) uint {
|
||||||
|
f := set.Lookup(name)
|
||||||
|
if f != nil {
|
||||||
|
parsed, err := strconv.ParseUint(f.Value.String(), 0, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return uint(parsed)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
28
vendor/github.com/codegangsta/cli/funcs.go
generated
vendored
Normal file
28
vendor/github.com/codegangsta/cli/funcs.go
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package cli
|
||||||
|
|
||||||
|
// BashCompleteFunc is an action to execute when the bash-completion flag is set
|
||||||
|
type BashCompleteFunc func(*Context)
|
||||||
|
|
||||||
|
// BeforeFunc is an action to execute before any subcommands are run, but after
|
||||||
|
// the context is ready if a non-nil error is returned, no subcommands are run
|
||||||
|
type BeforeFunc func(*Context) error
|
||||||
|
|
||||||
|
// AfterFunc is an action to execute after any subcommands are run, but after the
|
||||||
|
// subcommand has finished it is run even if Action() panics
|
||||||
|
type AfterFunc func(*Context) error
|
||||||
|
|
||||||
|
// ActionFunc is the action to execute when no subcommands are specified
|
||||||
|
type ActionFunc func(*Context) error
|
||||||
|
|
||||||
|
// CommandNotFoundFunc is executed if the proper command cannot be found
|
||||||
|
type CommandNotFoundFunc func(*Context, string)
|
||||||
|
|
||||||
|
// OnUsageErrorFunc is executed if an usage error occurs. This is useful for displaying
|
||||||
|
// customized usage error messages. This function is able to replace the
|
||||||
|
// original error messages. If this function is not set, the "Incorrect usage"
|
||||||
|
// is displayed and the execution is interrupted.
|
||||||
|
type OnUsageErrorFunc func(context *Context, err error, isSubcommand bool) error
|
||||||
|
|
||||||
|
// FlagStringFunc is used by the help generation to display a flag, which is
|
||||||
|
// expected to be a single line.
|
||||||
|
type FlagStringFunc func(Flag) string
|
289
vendor/github.com/codegangsta/cli/help.go
generated
vendored
289
vendor/github.com/codegangsta/cli/help.go
generated
vendored
|
@ -1,137 +1,207 @@
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"text/tabwriter"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
// The text template for the Default help topic.
|
// AppHelpTemplate is the text template for the Default help topic.
|
||||||
// cli.go uses text/template to render templates. You can
|
// cli.go uses text/template to render templates. You can
|
||||||
// render custom help text by setting this variable.
|
// render custom help text by setting this variable.
|
||||||
var AppHelpTemplate = `NAME:
|
var AppHelpTemplate = `NAME:
|
||||||
{{.Name}} - {{.Usage}}
|
{{.Name}}{{if .Usage}} - {{.Usage}}{{end}}
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
{{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...]
|
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}
|
||||||
|
|
||||||
VERSION:
|
VERSION:
|
||||||
{{.Version}}{{if or .Author .Email}}
|
{{.Version}}{{end}}{{end}}{{if .Description}}
|
||||||
|
|
||||||
AUTHOR:{{if .Author}}
|
DESCRIPTION:
|
||||||
{{.Author}}{{if .Email}} - <{{.Email}}>{{end}}{{else}}
|
{{.Description}}{{end}}{{if len .Authors}}
|
||||||
{{.Email}}{{end}}{{end}}
|
|
||||||
|
AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
|
||||||
|
{{range $index, $author := .Authors}}{{if $index}}
|
||||||
|
{{end}}{{$author}}{{end}}{{end}}{{if .VisibleCommands}}
|
||||||
|
|
||||||
|
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
|
||||||
|
{{.Name}}:{{end}}{{range .VisibleCommands}}
|
||||||
|
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
|
||||||
|
|
||||||
COMMANDS:
|
|
||||||
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
|
||||||
{{end}}{{if .Flags}}
|
|
||||||
GLOBAL OPTIONS:
|
GLOBAL OPTIONS:
|
||||||
{{range .Flags}}{{.}}
|
{{range $index, $option := .VisibleFlags}}{{if $index}}
|
||||||
{{end}}{{end}}
|
{{end}}{{$option}}{{end}}{{end}}{{if .Copyright}}
|
||||||
|
|
||||||
|
COPYRIGHT:
|
||||||
|
{{.Copyright}}{{end}}
|
||||||
`
|
`
|
||||||
|
|
||||||
// The text template for the command help topic.
|
// CommandHelpTemplate is the text template for the command help topic.
|
||||||
// cli.go uses text/template to render templates. You can
|
// cli.go uses text/template to render templates. You can
|
||||||
// render custom help text by setting this variable.
|
// render custom help text by setting this variable.
|
||||||
var CommandHelpTemplate = `NAME:
|
var CommandHelpTemplate = `NAME:
|
||||||
{{.Name}} - {{.Usage}}
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
command {{.Name}}{{if .Flags}} [command options]{{end}} [arguments...]{{if .Description}}
|
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}}
|
||||||
|
|
||||||
|
CATEGORY:
|
||||||
|
{{.Category}}{{end}}{{if .Description}}
|
||||||
|
|
||||||
DESCRIPTION:
|
DESCRIPTION:
|
||||||
{{.Description}}{{end}}{{if .Flags}}
|
{{.Description}}{{end}}{{if .VisibleFlags}}
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
{{range .Flags}}{{.}}
|
{{range .VisibleFlags}}{{.}}
|
||||||
{{end}}{{ end }}
|
{{end}}{{end}}
|
||||||
`
|
`
|
||||||
|
|
||||||
// The text template for the subcommand help topic.
|
// SubcommandHelpTemplate is the text template for the subcommand help topic.
|
||||||
// cli.go uses text/template to render templates. You can
|
// cli.go uses text/template to render templates. You can
|
||||||
// render custom help text by setting this variable.
|
// render custom help text by setting this variable.
|
||||||
var SubcommandHelpTemplate = `NAME:
|
var SubcommandHelpTemplate = `NAME:
|
||||||
{{.Name}} - {{.Usage}}
|
{{.HelpName}} - {{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}}
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
{{.Name}} command{{if .Flags}} [command options]{{end}} [arguments...]
|
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}
|
||||||
|
|
||||||
COMMANDS:
|
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
|
||||||
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
{{.Name}}:{{end}}{{range .VisibleCommands}}
|
||||||
{{end}}{{if .Flags}}
|
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}
|
||||||
|
{{end}}{{if .VisibleFlags}}
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
{{range .Flags}}{{.}}
|
{{range .VisibleFlags}}{{.}}
|
||||||
{{end}}{{end}}
|
{{end}}{{end}}
|
||||||
`
|
`
|
||||||
|
|
||||||
var helpCommand = Command{
|
var helpCommand = Command{
|
||||||
Name: "help",
|
Name: "help",
|
||||||
ShortName: "h",
|
Aliases: []string{"h"},
|
||||||
Usage: "Shows a list of commands or help for one command",
|
Usage: "Shows a list of commands or help for one command",
|
||||||
Action: func(c *Context) {
|
ArgsUsage: "[command]",
|
||||||
|
Action: func(c *Context) error {
|
||||||
args := c.Args()
|
args := c.Args()
|
||||||
if args.Present() {
|
if args.Present() {
|
||||||
ShowCommandHelp(c, args.First())
|
return ShowCommandHelp(c, args.First())
|
||||||
} else {
|
|
||||||
ShowAppHelp(c)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ShowAppHelp(c)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var helpSubcommand = Command{
|
var helpSubcommand = Command{
|
||||||
Name: "help",
|
Name: "help",
|
||||||
ShortName: "h",
|
Aliases: []string{"h"},
|
||||||
Usage: "Shows a list of commands or help for one command",
|
Usage: "Shows a list of commands or help for one command",
|
||||||
Action: func(c *Context) {
|
ArgsUsage: "[command]",
|
||||||
|
Action: func(c *Context) error {
|
||||||
args := c.Args()
|
args := c.Args()
|
||||||
if args.Present() {
|
if args.Present() {
|
||||||
ShowCommandHelp(c, args.First())
|
return ShowCommandHelp(c, args.First())
|
||||||
} else {
|
|
||||||
ShowSubcommandHelp(c)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ShowSubcommandHelp(c)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints help for the App
|
// Prints help for the App or Command
|
||||||
type helpPrinter func(templ string, data interface{})
|
type helpPrinter func(w io.Writer, templ string, data interface{})
|
||||||
|
|
||||||
var HelpPrinter helpPrinter = nil
|
// Prints help for the App or Command with custom template function.
|
||||||
|
type helpPrinterCustom func(w io.Writer, templ string, data interface{}, customFunc map[string]interface{})
|
||||||
|
|
||||||
// Prints version for the App
|
// HelpPrinter is a function that writes the help output. If not set a default
|
||||||
|
// is used. The function signature is:
|
||||||
|
// func(w io.Writer, templ string, data interface{})
|
||||||
|
var HelpPrinter helpPrinter = printHelp
|
||||||
|
|
||||||
|
// HelpPrinterCustom is same as HelpPrinter but
|
||||||
|
// takes a custom function for template function map.
|
||||||
|
var HelpPrinterCustom helpPrinterCustom = printHelpCustom
|
||||||
|
|
||||||
|
// VersionPrinter prints the version for the App
|
||||||
var VersionPrinter = printVersion
|
var VersionPrinter = printVersion
|
||||||
|
|
||||||
func ShowAppHelp(c *Context) {
|
// ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code.
|
||||||
HelpPrinter(AppHelpTemplate, c.App)
|
func ShowAppHelpAndExit(c *Context, exitCode int) {
|
||||||
|
ShowAppHelp(c)
|
||||||
|
os.Exit(exitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the list of subcommands as the default app completion method
|
// ShowAppHelp is an action that displays the help.
|
||||||
|
func ShowAppHelp(c *Context) (err error) {
|
||||||
|
if c.App.CustomAppHelpTemplate == "" {
|
||||||
|
HelpPrinter(c.App.Writer, AppHelpTemplate, c.App)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
customAppData := func() map[string]interface{} {
|
||||||
|
if c.App.ExtraInfo == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return map[string]interface{}{
|
||||||
|
"ExtraInfo": c.App.ExtraInfo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HelpPrinterCustom(c.App.Writer, c.App.CustomAppHelpTemplate, c.App, customAppData())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultAppComplete prints the list of subcommands as the default app completion method
|
||||||
func DefaultAppComplete(c *Context) {
|
func DefaultAppComplete(c *Context) {
|
||||||
for _, command := range c.App.Commands {
|
for _, command := range c.App.Commands {
|
||||||
fmt.Fprintln(c.App.Writer, command.Name)
|
if command.Hidden {
|
||||||
if command.ShortName != "" {
|
continue
|
||||||
fmt.Fprintln(c.App.Writer, command.ShortName)
|
}
|
||||||
|
for _, name := range command.Names() {
|
||||||
|
fmt.Fprintln(c.App.Writer, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints help for the given command
|
// ShowCommandHelpAndExit - exits with code after showing help
|
||||||
func ShowCommandHelp(c *Context, command string) {
|
func ShowCommandHelpAndExit(c *Context, command string, code int) {
|
||||||
for _, c := range c.App.Commands {
|
ShowCommandHelp(c, command)
|
||||||
|
os.Exit(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShowCommandHelp prints help for the given command
|
||||||
|
func ShowCommandHelp(ctx *Context, command string) error {
|
||||||
|
// show the subcommand help for a command with subcommands
|
||||||
|
if command == "" {
|
||||||
|
HelpPrinter(ctx.App.Writer, SubcommandHelpTemplate, ctx.App)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range ctx.App.Commands {
|
||||||
if c.HasName(command) {
|
if c.HasName(command) {
|
||||||
HelpPrinter(CommandHelpTemplate, c)
|
if c.CustomHelpTemplate != "" {
|
||||||
return
|
HelpPrinterCustom(ctx.App.Writer, c.CustomHelpTemplate, c, nil)
|
||||||
|
} else {
|
||||||
|
HelpPrinter(ctx.App.Writer, CommandHelpTemplate, c)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.App.CommandNotFound != nil {
|
if ctx.App.CommandNotFound == nil {
|
||||||
c.App.CommandNotFound(c, command)
|
return NewExitError(fmt.Sprintf("No help topic for '%v'", command), 3)
|
||||||
} else {
|
|
||||||
fmt.Fprintf(c.App.Writer, "No help topic for '%v'\n", command)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.App.CommandNotFound(ctx, command)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints help for the given subcommand
|
// ShowSubcommandHelp prints help for the given subcommand
|
||||||
func ShowSubcommandHelp(c *Context) {
|
func ShowSubcommandHelp(c *Context) error {
|
||||||
ShowCommandHelp(c, c.Command.Name)
|
return ShowCommandHelp(c, c.Command.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the version number of the App
|
// ShowVersion prints the version number of the App
|
||||||
func ShowVersion(c *Context) {
|
func ShowVersion(c *Context) {
|
||||||
VersionPrinter(c)
|
VersionPrinter(c)
|
||||||
}
|
}
|
||||||
|
@ -140,7 +210,7 @@ func printVersion(c *Context) {
|
||||||
fmt.Fprintf(c.App.Writer, "%v version %v\n", c.App.Name, c.App.Version)
|
fmt.Fprintf(c.App.Writer, "%v version %v\n", c.App.Name, c.App.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the lists of commands within a given context
|
// ShowCompletions prints the lists of commands within a given context
|
||||||
func ShowCompletions(c *Context) {
|
func ShowCompletions(c *Context) {
|
||||||
a := c.App
|
a := c.App
|
||||||
if a != nil && a.BashComplete != nil {
|
if a != nil && a.BashComplete != nil {
|
||||||
|
@ -148,7 +218,7 @@ func ShowCompletions(c *Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the custom completions for a given command
|
// ShowCommandCompletions prints the custom completions for a given command
|
||||||
func ShowCommandCompletions(ctx *Context, command string) {
|
func ShowCommandCompletions(ctx *Context, command string) {
|
||||||
c := ctx.App.Command(command)
|
c := ctx.App.Command(command)
|
||||||
if c != nil && c.BashComplete != nil {
|
if c != nil && c.BashComplete != nil {
|
||||||
|
@ -156,22 +226,56 @@ func ShowCommandCompletions(ctx *Context, command string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkVersion(c *Context) bool {
|
func printHelpCustom(out io.Writer, templ string, data interface{}, customFunc map[string]interface{}) {
|
||||||
if c.GlobalBool("version") {
|
funcMap := template.FuncMap{
|
||||||
ShowVersion(c)
|
"join": strings.Join,
|
||||||
return true
|
}
|
||||||
|
if customFunc != nil {
|
||||||
|
for key, value := range customFunc {
|
||||||
|
funcMap[key] = value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0)
|
||||||
|
t := template.Must(template.New("help").Funcs(funcMap).Parse(templ))
|
||||||
|
err := t.Execute(w, data)
|
||||||
|
if err != nil {
|
||||||
|
// If the writer is closed, t.Execute will fail, and there's nothing
|
||||||
|
// we can do to recover.
|
||||||
|
if os.Getenv("CLI_TEMPLATE_ERROR_DEBUG") != "" {
|
||||||
|
fmt.Fprintf(ErrWriter, "CLI TEMPLATE ERROR: %#v\n", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
func printHelp(out io.Writer, templ string, data interface{}) {
|
||||||
|
printHelpCustom(out, templ, data, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkVersion(c *Context) bool {
|
||||||
|
found := false
|
||||||
|
if VersionFlag.GetName() != "" {
|
||||||
|
eachName(VersionFlag.GetName(), func(name string) {
|
||||||
|
if c.GlobalBool(name) || c.Bool(name) {
|
||||||
|
found = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return found
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkHelp(c *Context) bool {
|
func checkHelp(c *Context) bool {
|
||||||
if c.GlobalBool("h") || c.GlobalBool("help") {
|
found := false
|
||||||
ShowAppHelp(c)
|
if HelpFlag.GetName() != "" {
|
||||||
return true
|
eachName(HelpFlag.GetName(), func(name string) {
|
||||||
|
if c.GlobalBool(name) || c.Bool(name) {
|
||||||
|
found = true
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
return found
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkCommandHelp(c *Context, name string) bool {
|
func checkCommandHelp(c *Context, name string) bool {
|
||||||
|
@ -184,7 +288,7 @@ func checkCommandHelp(c *Context, name string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkSubcommandHelp(c *Context) bool {
|
func checkSubcommandHelp(c *Context) bool {
|
||||||
if c.GlobalBool("h") || c.GlobalBool("help") {
|
if c.Bool("h") || c.Bool("help") {
|
||||||
ShowSubcommandHelp(c)
|
ShowSubcommandHelp(c)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -192,20 +296,43 @@ func checkSubcommandHelp(c *Context) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkCompletions(c *Context) bool {
|
func checkShellCompleteFlag(a *App, arguments []string) (bool, []string) {
|
||||||
if (c.GlobalBool(BashCompletionFlag.Name) || c.Bool(BashCompletionFlag.Name)) && c.App.EnableBashCompletion {
|
if !a.EnableBashCompletion {
|
||||||
ShowCompletions(c)
|
return false, arguments
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
pos := len(arguments) - 1
|
||||||
|
lastArg := arguments[pos]
|
||||||
|
|
||||||
|
if lastArg != "--"+BashCompletionFlag.GetName() {
|
||||||
|
return false, arguments
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, arguments[:pos]
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkCompletions(c *Context) bool {
|
||||||
|
if !c.shellComplete {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if args := c.Args(); args.Present() {
|
||||||
|
name := args.First()
|
||||||
|
if cmd := c.App.Command(name); cmd != nil {
|
||||||
|
// let the command handle the completion
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowCompletions(c)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkCommandCompletions(c *Context, name string) bool {
|
func checkCommandCompletions(c *Context, name string) bool {
|
||||||
if c.Bool(BashCompletionFlag.Name) && c.App.EnableBashCompletion {
|
if !c.shellComplete {
|
||||||
ShowCommandCompletions(c, name)
|
return false
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
ShowCommandCompletions(c, name)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
Apache License
|
Apache License
|
||||||
Version 2.0, January 2004
|
Version 2.0, January 2004
|
||||||
http://www.apache.org/licenses/
|
http://www.apache.org/licenses/
|
||||||
|
@ -176,7 +175,18 @@
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
Copyright 2014 Docker, Inc.
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright {yyyy} {name of copyright owner}
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -189,3 +199,4 @@
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
641
vendor/github.com/containerd/continuity/context.go
generated
vendored
Normal file
641
vendor/github.com/containerd/continuity/context.go
generated
vendored
Normal file
|
@ -0,0 +1,641 @@
|
||||||
|
package continuity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/containerd/continuity/devices"
|
||||||
|
driverpkg "github.com/containerd/continuity/driver"
|
||||||
|
"github.com/containerd/continuity/pathdriver"
|
||||||
|
"github.com/opencontainers/go-digest"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrNotFound = fmt.Errorf("not found")
|
||||||
|
ErrNotSupported = fmt.Errorf("not supported")
|
||||||
|
)
|
||||||
|
|
||||||
|
// Context represents a file system context for accessing resources. The
|
||||||
|
// responsibility of the context is to convert system specific resources to
|
||||||
|
// generic Resource objects. Most of this is safe path manipulation, as well
|
||||||
|
// as extraction of resource details.
|
||||||
|
type Context interface {
|
||||||
|
Apply(Resource) error
|
||||||
|
Verify(Resource) error
|
||||||
|
Resource(string, os.FileInfo) (Resource, error)
|
||||||
|
Walk(filepath.WalkFunc) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// SymlinkPath is intended to give the symlink target value
|
||||||
|
// in a root context. Target and linkname are absolute paths
|
||||||
|
// not under the given root.
|
||||||
|
type SymlinkPath func(root, linkname, target string) (string, error)
|
||||||
|
|
||||||
|
type ContextOptions struct {
|
||||||
|
Digester Digester
|
||||||
|
Driver driverpkg.Driver
|
||||||
|
PathDriver pathdriver.PathDriver
|
||||||
|
Provider ContentProvider
|
||||||
|
}
|
||||||
|
|
||||||
|
// context represents a file system context for accessing resources.
|
||||||
|
// Generally, all path qualified access and system considerations should land
|
||||||
|
// here.
|
||||||
|
type context struct {
|
||||||
|
driver driverpkg.Driver
|
||||||
|
pathDriver pathdriver.PathDriver
|
||||||
|
root string
|
||||||
|
digester Digester
|
||||||
|
provider ContentProvider
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewContext returns a Context associated with root. The default driver will
|
||||||
|
// be used, as returned by NewDriver.
|
||||||
|
func NewContext(root string) (Context, error) {
|
||||||
|
return NewContextWithOptions(root, ContextOptions{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewContextWithOptions returns a Context associate with the root.
|
||||||
|
func NewContextWithOptions(root string, options ContextOptions) (Context, error) {
|
||||||
|
// normalize to absolute path
|
||||||
|
pathDriver := options.PathDriver
|
||||||
|
if pathDriver == nil {
|
||||||
|
pathDriver = pathdriver.LocalPathDriver
|
||||||
|
}
|
||||||
|
|
||||||
|
root = pathDriver.FromSlash(root)
|
||||||
|
root, err := pathDriver.Abs(pathDriver.Clean(root))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
driver := options.Driver
|
||||||
|
if driver == nil {
|
||||||
|
driver, err = driverpkg.NewSystemDriver()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
digester := options.Digester
|
||||||
|
if digester == nil {
|
||||||
|
digester = simpleDigester{digest.Canonical}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the root directory. Need to be a little careful here. We are
|
||||||
|
// allowing a link for now, but this may have odd behavior when
|
||||||
|
// canonicalizing paths. As long as all files are opened through the link
|
||||||
|
// path, this should be okay.
|
||||||
|
fi, err := driver.Stat(root)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !fi.IsDir() {
|
||||||
|
return nil, &os.PathError{Op: "NewContext", Path: root, Err: os.ErrInvalid}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &context{
|
||||||
|
root: root,
|
||||||
|
driver: driver,
|
||||||
|
pathDriver: pathDriver,
|
||||||
|
digester: digester,
|
||||||
|
provider: options.Provider,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resource returns the resource as path p, populating the entry with info
|
||||||
|
// from fi. The path p should be the path of the resource in the context,
|
||||||
|
// typically obtained through Walk or from the value of Resource.Path(). If fi
|
||||||
|
// is nil, it will be resolved.
|
||||||
|
func (c *context) Resource(p string, fi os.FileInfo) (Resource, error) {
|
||||||
|
fp, err := c.fullpath(p)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if fi == nil {
|
||||||
|
fi, err = c.driver.Lstat(fp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
base, err := newBaseResource(p, fi)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
base.xattrs, err = c.resolveXAttrs(fp, fi, base)
|
||||||
|
if err == ErrNotSupported {
|
||||||
|
log.Printf("resolving xattrs on %s not supported", fp)
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(stevvooe): Handle windows alternate data streams.
|
||||||
|
|
||||||
|
if fi.Mode().IsRegular() {
|
||||||
|
dgst, err := c.digest(p)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return newRegularFile(*base, base.paths, fi.Size(), dgst)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fi.Mode().IsDir() {
|
||||||
|
return newDirectory(*base)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fi.Mode()&os.ModeSymlink != 0 {
|
||||||
|
// We handle relative links vs absolute links by including a
|
||||||
|
// beginning slash for absolute links. Effectively, the bundle's
|
||||||
|
// root is treated as the absolute link anchor.
|
||||||
|
target, err := c.driver.Readlink(fp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return newSymLink(*base, target)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fi.Mode()&os.ModeNamedPipe != 0 {
|
||||||
|
return newNamedPipe(*base, base.paths)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fi.Mode()&os.ModeDevice != 0 {
|
||||||
|
deviceDriver, ok := c.driver.(driverpkg.DeviceInfoDriver)
|
||||||
|
if !ok {
|
||||||
|
log.Printf("device extraction not supported %s", fp)
|
||||||
|
return nil, ErrNotSupported
|
||||||
|
}
|
||||||
|
|
||||||
|
// character and block devices merely need to recover the
|
||||||
|
// major/minor device number.
|
||||||
|
major, minor, err := deviceDriver.DeviceInfo(fi)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return newDevice(*base, base.paths, major, minor)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("%q (%v) is not supported", fp, fi.Mode())
|
||||||
|
return nil, ErrNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *context) verifyMetadata(resource, target Resource) error {
|
||||||
|
if target.Mode() != resource.Mode() {
|
||||||
|
return fmt.Errorf("resource %q has incorrect mode: %v != %v", target.Path(), target.Mode(), resource.Mode())
|
||||||
|
}
|
||||||
|
|
||||||
|
if target.UID() != resource.UID() {
|
||||||
|
return fmt.Errorf("unexpected uid for %q: %v != %v", target.Path(), target.UID(), resource.GID())
|
||||||
|
}
|
||||||
|
|
||||||
|
if target.GID() != resource.GID() {
|
||||||
|
return fmt.Errorf("unexpected gid for %q: %v != %v", target.Path(), target.GID(), target.GID())
|
||||||
|
}
|
||||||
|
|
||||||
|
if xattrer, ok := resource.(XAttrer); ok {
|
||||||
|
txattrer, tok := target.(XAttrer)
|
||||||
|
if !tok {
|
||||||
|
return fmt.Errorf("resource %q has xattrs but target does not support them", resource.Path())
|
||||||
|
}
|
||||||
|
|
||||||
|
// For xattrs, only ensure that we have those defined in the resource
|
||||||
|
// and their values match. We can ignore other xattrs. In other words,
|
||||||
|
// we only verify that target has the subset defined by resource.
|
||||||
|
txattrs := txattrer.XAttrs()
|
||||||
|
for attr, value := range xattrer.XAttrs() {
|
||||||
|
tvalue, ok := txattrs[attr]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("resource %q target missing xattr %q", resource.Path(), attr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !bytes.Equal(value, tvalue) {
|
||||||
|
return fmt.Errorf("xattr %q value differs for resource %q", attr, resource.Path())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch r := resource.(type) {
|
||||||
|
case RegularFile:
|
||||||
|
// TODO(stevvooe): Another reason to use a record-based approach. We
|
||||||
|
// have to do another type switch to get this to work. This could be
|
||||||
|
// fixed with an Equal function, but let's study this a little more to
|
||||||
|
// be sure.
|
||||||
|
t, ok := target.(RegularFile)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("resource %q target not a regular file", r.Path())
|
||||||
|
}
|
||||||
|
|
||||||
|
if t.Size() != r.Size() {
|
||||||
|
return fmt.Errorf("resource %q target has incorrect size: %v != %v", t.Path(), t.Size(), r.Size())
|
||||||
|
}
|
||||||
|
case Directory:
|
||||||
|
t, ok := target.(Directory)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("resource %q target not a directory", t.Path())
|
||||||
|
}
|
||||||
|
case SymLink:
|
||||||
|
t, ok := target.(SymLink)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("resource %q target not a symlink", t.Path())
|
||||||
|
}
|
||||||
|
|
||||||
|
if t.Target() != r.Target() {
|
||||||
|
return fmt.Errorf("resource %q target has mismatched target: %q != %q", t.Path(), t.Target(), r.Target())
|
||||||
|
}
|
||||||
|
case Device:
|
||||||
|
t, ok := target.(Device)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("resource %q is not a device", t.Path())
|
||||||
|
}
|
||||||
|
|
||||||
|
if t.Major() != r.Major() || t.Minor() != r.Minor() {
|
||||||
|
return fmt.Errorf("resource %q has mismatched major/minor numbers: %d,%d != %d,%d", t.Path(), t.Major(), t.Minor(), r.Major(), r.Minor())
|
||||||
|
}
|
||||||
|
case NamedPipe:
|
||||||
|
t, ok := target.(NamedPipe)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("resource %q is not a named pipe", t.Path())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("cannot verify resource: %v", resource)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify the resource in the context. An error will be returned a discrepancy
|
||||||
|
// is found.
|
||||||
|
func (c *context) Verify(resource Resource) error {
|
||||||
|
fp, err := c.fullpath(resource.Path())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := c.driver.Lstat(fp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
target, err := c.Resource(resource.Path(), fi)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if target.Path() != resource.Path() {
|
||||||
|
return fmt.Errorf("resource paths do not match: %q != %q", target.Path(), resource.Path())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.verifyMetadata(resource, target); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if h, isHardlinkable := resource.(Hardlinkable); isHardlinkable {
|
||||||
|
hardlinkKey, err := newHardlinkKey(fi)
|
||||||
|
if err == errNotAHardLink {
|
||||||
|
if len(h.Paths()) > 1 {
|
||||||
|
return fmt.Errorf("%q is not a hardlink to %q", h.Paths()[1], resource.Path())
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, path := range h.Paths()[1:] {
|
||||||
|
fpLink, err := c.fullpath(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fiLink, err := c.driver.Lstat(fpLink)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
targetLink, err := c.Resource(path, fiLink)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
hardlinkKeyLink, err := newHardlinkKey(fiLink)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if hardlinkKeyLink != hardlinkKey {
|
||||||
|
return fmt.Errorf("%q is not a hardlink to %q", path, resource.Path())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.verifyMetadata(resource, targetLink); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch r := resource.(type) {
|
||||||
|
case RegularFile:
|
||||||
|
t, ok := target.(RegularFile)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("resource %q target not a regular file", r.Path())
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(stevvooe): This may need to get a little more sophisticated
|
||||||
|
// for digest comparison. We may want to actually calculate the
|
||||||
|
// provided digests, rather than the implementations having an
|
||||||
|
// overlap.
|
||||||
|
if !digestsMatch(t.Digests(), r.Digests()) {
|
||||||
|
return fmt.Errorf("digests for resource %q do not match: %v != %v", t.Path(), t.Digests(), r.Digests())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *context) checkoutFile(fp string, rf RegularFile) error {
|
||||||
|
if c.provider == nil {
|
||||||
|
return fmt.Errorf("no file provider")
|
||||||
|
}
|
||||||
|
var (
|
||||||
|
r io.ReadCloser
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
for _, dgst := range rf.Digests() {
|
||||||
|
r, err = c.provider.Reader(dgst)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("file content could not be provided: %v", err)
|
||||||
|
}
|
||||||
|
defer r.Close()
|
||||||
|
|
||||||
|
return atomicWriteFile(fp, r, rf)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply the resource to the contexts. An error will be returned if the
|
||||||
|
// operation fails. Depending on the resource type, the resource may be
|
||||||
|
// created. For resource that cannot be resolved, an error will be returned.
|
||||||
|
func (c *context) Apply(resource Resource) error {
|
||||||
|
fp, err := c.fullpath(resource.Path())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.HasPrefix(fp, c.root) {
|
||||||
|
return fmt.Errorf("resource %v escapes root", resource)
|
||||||
|
}
|
||||||
|
|
||||||
|
var chmod = true
|
||||||
|
fi, err := c.driver.Lstat(fp)
|
||||||
|
if err != nil {
|
||||||
|
if !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch r := resource.(type) {
|
||||||
|
case RegularFile:
|
||||||
|
if fi == nil {
|
||||||
|
if err := c.checkoutFile(fp, r); err != nil {
|
||||||
|
return fmt.Errorf("error checking out file %q: %v", resource.Path(), err)
|
||||||
|
}
|
||||||
|
chmod = false
|
||||||
|
} else {
|
||||||
|
if !fi.Mode().IsRegular() {
|
||||||
|
return fmt.Errorf("file %q should be a regular file, but is not", resource.Path())
|
||||||
|
}
|
||||||
|
if fi.Size() != r.Size() {
|
||||||
|
if err := c.checkoutFile(fp, r); err != nil {
|
||||||
|
return fmt.Errorf("error checking out file %q: %v", resource.Path(), err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for _, dgst := range r.Digests() {
|
||||||
|
f, err := os.Open(fp)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failure opening file for read %q: %v", resource.Path(), err)
|
||||||
|
}
|
||||||
|
compared, err := dgst.Algorithm().FromReader(f)
|
||||||
|
if err == nil && dgst != compared {
|
||||||
|
if err := c.checkoutFile(fp, r); err != nil {
|
||||||
|
return fmt.Errorf("error checking out file %q: %v", resource.Path(), err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err1 := f.Close(); err == nil {
|
||||||
|
err = err1
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error checking digest for %q: %v", resource.Path(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case Directory:
|
||||||
|
if fi == nil {
|
||||||
|
if err := c.driver.Mkdir(fp, resource.Mode()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if !fi.Mode().IsDir() {
|
||||||
|
return fmt.Errorf("%q should be a directory, but is not", resource.Path())
|
||||||
|
}
|
||||||
|
|
||||||
|
case SymLink:
|
||||||
|
var target string // only possibly set if target resource is a symlink
|
||||||
|
|
||||||
|
if fi != nil {
|
||||||
|
if fi.Mode()&os.ModeSymlink != 0 {
|
||||||
|
target, err = c.driver.Readlink(fp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if target != r.Target() {
|
||||||
|
if fi != nil {
|
||||||
|
if err := c.driver.Remove(fp); err != nil { // RemoveAll in case of directory?
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.driver.Symlink(r.Target(), fp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE(stevvooe): Chmod on symlink is not supported on linux. We
|
||||||
|
// may want to maintain support for other platforms that have it.
|
||||||
|
chmod = false
|
||||||
|
|
||||||
|
case Device:
|
||||||
|
if fi == nil {
|
||||||
|
if err := c.driver.Mknod(fp, resource.Mode(), int(r.Major()), int(r.Minor())); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if (fi.Mode() & os.ModeDevice) == 0 {
|
||||||
|
return fmt.Errorf("%q should be a device, but is not", resource.Path())
|
||||||
|
} else {
|
||||||
|
major, minor, err := devices.DeviceInfo(fi)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if major != r.Major() || minor != r.Minor() {
|
||||||
|
if err := c.driver.Remove(fp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.driver.Mknod(fp, resource.Mode(), int(r.Major()), int(r.Minor())); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case NamedPipe:
|
||||||
|
if fi == nil {
|
||||||
|
if err := c.driver.Mkfifo(fp, resource.Mode()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if (fi.Mode() & os.ModeNamedPipe) == 0 {
|
||||||
|
return fmt.Errorf("%q should be a named pipe, but is not", resource.Path())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if h, isHardlinkable := resource.(Hardlinkable); isHardlinkable {
|
||||||
|
for _, path := range h.Paths() {
|
||||||
|
if path == resource.Path() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
lp, err := c.fullpath(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, fi := c.driver.Lstat(lp); fi == nil {
|
||||||
|
c.driver.Remove(lp)
|
||||||
|
}
|
||||||
|
if err := c.driver.Link(fp, lp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update filemode if file was not created
|
||||||
|
if chmod {
|
||||||
|
if err := c.driver.Lchmod(fp, resource.Mode()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.driver.Lchown(fp, resource.UID(), resource.GID()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if xattrer, ok := resource.(XAttrer); ok {
|
||||||
|
// For xattrs, only ensure that we have those defined in the resource
|
||||||
|
// and their values are set. We can ignore other xattrs. In other words,
|
||||||
|
// we only set xattres defined by resource but never remove.
|
||||||
|
|
||||||
|
if _, ok := resource.(SymLink); ok {
|
||||||
|
lxattrDriver, ok := c.driver.(driverpkg.LXAttrDriver)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unsupported symlink xattr for resource %q", resource.Path())
|
||||||
|
}
|
||||||
|
if err := lxattrDriver.LSetxattr(fp, xattrer.XAttrs()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
xattrDriver, ok := c.driver.(driverpkg.XAttrDriver)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unsupported xattr for resource %q", resource.Path())
|
||||||
|
}
|
||||||
|
if err := xattrDriver.Setxattr(fp, xattrer.XAttrs()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Walk provides a convenience function to call filepath.Walk correctly for
|
||||||
|
// the context. Otherwise identical to filepath.Walk, the path argument is
|
||||||
|
// corrected to be contained within the context.
|
||||||
|
func (c *context) Walk(fn filepath.WalkFunc) error {
|
||||||
|
return c.pathDriver.Walk(c.root, func(p string, fi os.FileInfo, err error) error {
|
||||||
|
contained, err := c.contain(p)
|
||||||
|
return fn(contained, fi, err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// fullpath returns the system path for the resource, joined with the context
|
||||||
|
// root. The path p must be a part of the context.
|
||||||
|
func (c *context) fullpath(p string) (string, error) {
|
||||||
|
p = c.pathDriver.Join(c.root, p)
|
||||||
|
if !strings.HasPrefix(p, c.root) {
|
||||||
|
return "", fmt.Errorf("invalid context path")
|
||||||
|
}
|
||||||
|
|
||||||
|
return p, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// contain cleans and santizes the filesystem path p to be an absolute path,
|
||||||
|
// effectively relative to the context root.
|
||||||
|
func (c *context) contain(p string) (string, error) {
|
||||||
|
sanitized, err := c.pathDriver.Rel(c.root, p)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ZOMBIES(stevvooe): In certain cases, we may want to remap these to a
|
||||||
|
// "containment error", so the caller can decide what to do.
|
||||||
|
return c.pathDriver.Join("/", c.pathDriver.Clean(sanitized)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// digest returns the digest of the file at path p, relative to the root.
|
||||||
|
func (c *context) digest(p string) (digest.Digest, error) {
|
||||||
|
f, err := c.driver.Open(c.pathDriver.Join(c.root, p))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
return c.digester.Digest(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// resolveXAttrs attempts to resolve the extended attributes for the resource
|
||||||
|
// at the path fp, which is the full path to the resource. If the resource
|
||||||
|
// cannot have xattrs, nil will be returned.
|
||||||
|
func (c *context) resolveXAttrs(fp string, fi os.FileInfo, base *resource) (map[string][]byte, error) {
|
||||||
|
if fi.Mode().IsRegular() || fi.Mode().IsDir() {
|
||||||
|
xattrDriver, ok := c.driver.(driverpkg.XAttrDriver)
|
||||||
|
if !ok {
|
||||||
|
log.Println("xattr extraction not supported")
|
||||||
|
return nil, ErrNotSupported
|
||||||
|
}
|
||||||
|
|
||||||
|
return xattrDriver.Getxattr(fp)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fi.Mode()&os.ModeSymlink != 0 {
|
||||||
|
lxattrDriver, ok := c.driver.(driverpkg.LXAttrDriver)
|
||||||
|
if !ok {
|
||||||
|
log.Println("xattr extraction for symlinks not supported")
|
||||||
|
return nil, ErrNotSupported
|
||||||
|
}
|
||||||
|
|
||||||
|
return lxattrDriver.LGetxattr(fp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
88
vendor/github.com/containerd/continuity/digests.go
generated
vendored
Normal file
88
vendor/github.com/containerd/continuity/digests.go
generated
vendored
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
package continuity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/opencontainers/go-digest"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Digester produces a digest for a given read stream
|
||||||
|
type Digester interface {
|
||||||
|
Digest(io.Reader) (digest.Digest, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentProvider produces a read stream for a given digest
|
||||||
|
type ContentProvider interface {
|
||||||
|
Reader(digest.Digest) (io.ReadCloser, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type simpleDigester struct {
|
||||||
|
algorithm digest.Algorithm
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sd simpleDigester) Digest(r io.Reader) (digest.Digest, error) {
|
||||||
|
digester := sd.algorithm.Digester()
|
||||||
|
|
||||||
|
if _, err := io.Copy(digester.Hash(), r); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return digester.Digest(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// uniqifyDigests sorts and uniqifies the provided digest, ensuring that the
|
||||||
|
// digests are not repeated and no two digests with the same algorithm have
|
||||||
|
// different values. Because a stable sort is used, this has the effect of
|
||||||
|
// "zipping" digest collections from multiple resources.
|
||||||
|
func uniqifyDigests(digests ...digest.Digest) ([]digest.Digest, error) {
|
||||||
|
sort.Stable(digestSlice(digests)) // stable sort is important for the behavior here.
|
||||||
|
seen := map[digest.Digest]struct{}{}
|
||||||
|
algs := map[digest.Algorithm][]digest.Digest{} // detect different digests.
|
||||||
|
|
||||||
|
var out []digest.Digest
|
||||||
|
// uniqify the digests
|
||||||
|
for _, d := range digests {
|
||||||
|
if _, ok := seen[d]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
seen[d] = struct{}{}
|
||||||
|
algs[d.Algorithm()] = append(algs[d.Algorithm()], d)
|
||||||
|
|
||||||
|
if len(algs[d.Algorithm()]) > 1 {
|
||||||
|
return nil, fmt.Errorf("conflicting digests for %v found", d.Algorithm())
|
||||||
|
}
|
||||||
|
|
||||||
|
out = append(out, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// digestsMatch compares the two sets of digests to see if they match.
|
||||||
|
func digestsMatch(as, bs []digest.Digest) bool {
|
||||||
|
all := append(as, bs...)
|
||||||
|
|
||||||
|
uniqified, err := uniqifyDigests(all...)
|
||||||
|
if err != nil {
|
||||||
|
// the only error uniqifyDigests returns is when the digests disagree.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
disjoint := len(as) + len(bs)
|
||||||
|
if len(uniqified) == disjoint {
|
||||||
|
// if these two sets have the same cardinality, we know both sides
|
||||||
|
// didn't share any digests.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
type digestSlice []digest.Digest
|
||||||
|
|
||||||
|
func (p digestSlice) Len() int { return len(p) }
|
||||||
|
func (p digestSlice) Less(i, j int) bool { return p[i] < p[j] }
|
||||||
|
func (p digestSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
113
vendor/github.com/containerd/continuity/groups_unix.go
generated
vendored
Normal file
113
vendor/github.com/containerd/continuity/groups_unix.go
generated
vendored
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
package continuity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO(stevvooe): This needs a lot of work before we can call it useful.
|
||||||
|
|
||||||
|
type groupIndex struct {
|
||||||
|
byName map[string]*group
|
||||||
|
byGID map[int]*group
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupIndex() (*groupIndex, error) {
|
||||||
|
f, err := os.Open("/etc/group")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
groups, err := parseGroups(f)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return newGroupIndex(groups), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newGroupIndex(groups []group) *groupIndex {
|
||||||
|
gi := &groupIndex{
|
||||||
|
byName: make(map[string]*group),
|
||||||
|
byGID: make(map[int]*group),
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, group := range groups {
|
||||||
|
gi.byGID[group.gid] = &groups[i]
|
||||||
|
gi.byName[group.name] = &groups[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
return gi
|
||||||
|
}
|
||||||
|
|
||||||
|
type group struct {
|
||||||
|
name string
|
||||||
|
gid int
|
||||||
|
members []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupName(gid int) (string, error) {
|
||||||
|
f, err := os.Open("/etc/group")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
groups, err := parseGroups(f)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, group := range groups {
|
||||||
|
if group.gid == gid {
|
||||||
|
return group.name, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", fmt.Errorf("no group for gid")
|
||||||
|
}
|
||||||
|
|
||||||
|
// parseGroups parses an /etc/group file for group names, ids and membership.
|
||||||
|
// This is unix specific.
|
||||||
|
func parseGroups(rd io.Reader) ([]group, error) {
|
||||||
|
var groups []group
|
||||||
|
scanner := bufio.NewScanner(rd)
|
||||||
|
|
||||||
|
for scanner.Scan() {
|
||||||
|
if strings.HasPrefix(scanner.Text(), "#") {
|
||||||
|
continue // skip comment
|
||||||
|
}
|
||||||
|
|
||||||
|
parts := strings.SplitN(scanner.Text(), ":", 4)
|
||||||
|
|
||||||
|
if len(parts) != 4 {
|
||||||
|
return nil, fmt.Errorf("bad entry: %q", scanner.Text())
|
||||||
|
}
|
||||||
|
|
||||||
|
name, _, sgid, smembers := parts[0], parts[1], parts[2], parts[3]
|
||||||
|
|
||||||
|
gid, err := strconv.Atoi(sgid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("bad gid: %q", gid)
|
||||||
|
}
|
||||||
|
|
||||||
|
members := strings.Split(smembers, ",")
|
||||||
|
|
||||||
|
groups = append(groups, group{
|
||||||
|
name: name,
|
||||||
|
gid: gid,
|
||||||
|
members: members,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if scanner.Err() != nil {
|
||||||
|
return nil, scanner.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
return groups, nil
|
||||||
|
}
|
57
vendor/github.com/containerd/continuity/hardlinks.go
generated
vendored
Normal file
57
vendor/github.com/containerd/continuity/hardlinks.go
generated
vendored
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
package continuity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
errNotAHardLink = fmt.Errorf("invalid hardlink")
|
||||||
|
)
|
||||||
|
|
||||||
|
type hardlinkManager struct {
|
||||||
|
hardlinks map[hardlinkKey][]Resource
|
||||||
|
}
|
||||||
|
|
||||||
|
func newHardlinkManager() *hardlinkManager {
|
||||||
|
return &hardlinkManager{
|
||||||
|
hardlinks: map[hardlinkKey][]Resource{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add attempts to add the resource to the hardlink manager. If the resource
|
||||||
|
// cannot be considered as a hardlink candidate, errNotAHardLink is returned.
|
||||||
|
func (hlm *hardlinkManager) Add(fi os.FileInfo, resource Resource) error {
|
||||||
|
if _, ok := resource.(Hardlinkable); !ok {
|
||||||
|
return errNotAHardLink
|
||||||
|
}
|
||||||
|
|
||||||
|
key, err := newHardlinkKey(fi)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
hlm.hardlinks[key] = append(hlm.hardlinks[key], resource)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge processes the current state of the hardlink manager and merges any
|
||||||
|
// shared nodes into hardlinked resources.
|
||||||
|
func (hlm *hardlinkManager) Merge() ([]Resource, error) {
|
||||||
|
var resources []Resource
|
||||||
|
for key, linked := range hlm.hardlinks {
|
||||||
|
if len(linked) < 1 {
|
||||||
|
return nil, fmt.Errorf("no hardlink entrys for dev, inode pair: %#v", key)
|
||||||
|
}
|
||||||
|
|
||||||
|
merged, err := Merge(linked...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error merging hardlink: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
resources = append(resources, merged)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resources, nil
|
||||||
|
}
|
36
vendor/github.com/containerd/continuity/hardlinks_unix.go
generated
vendored
Normal file
36
vendor/github.com/containerd/continuity/hardlinks_unix.go
generated
vendored
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
// +build linux darwin freebsd solaris
|
||||||
|
|
||||||
|
package continuity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
// hardlinkKey provides a tuple-key for managing hardlinks. This is system-
|
||||||
|
// specific.
|
||||||
|
type hardlinkKey struct {
|
||||||
|
dev uint64
|
||||||
|
inode uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
// newHardlinkKey returns a hardlink key for the provided file info. If the
|
||||||
|
// resource does not represent a possible hardlink, errNotAHardLink will be
|
||||||
|
// returned.
|
||||||
|
func newHardlinkKey(fi os.FileInfo) (hardlinkKey, error) {
|
||||||
|
sys, ok := fi.Sys().(*syscall.Stat_t)
|
||||||
|
if !ok {
|
||||||
|
return hardlinkKey{}, fmt.Errorf("cannot resolve (*syscall.Stat_t) from os.FileInfo")
|
||||||
|
}
|
||||||
|
|
||||||
|
if sys.Nlink < 2 {
|
||||||
|
// NOTE(stevvooe): This is not always true for all filesystems. We
|
||||||
|
// should somehow detect this and provided a slow "polyfill" that
|
||||||
|
// leverages os.SameFile if we detect a filesystem where link counts
|
||||||
|
// is not really supported.
|
||||||
|
return hardlinkKey{}, errNotAHardLink
|
||||||
|
}
|
||||||
|
|
||||||
|
return hardlinkKey{dev: uint64(sys.Dev), inode: uint64(sys.Ino)}, nil
|
||||||
|
}
|
12
vendor/github.com/containerd/continuity/hardlinks_windows.go
generated
vendored
Normal file
12
vendor/github.com/containerd/continuity/hardlinks_windows.go
generated
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package continuity
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
type hardlinkKey struct{}
|
||||||
|
|
||||||
|
func newHardlinkKey(fi os.FileInfo) (hardlinkKey, error) {
|
||||||
|
// NOTE(stevvooe): Obviously, this is not yet implemented. However, the
|
||||||
|
// makings of an implementation are available in src/os/types_windows.go. More
|
||||||
|
// investigation needs to be done to figure out exactly how to do this.
|
||||||
|
return hardlinkKey{}, errNotAHardLink
|
||||||
|
}
|
39
vendor/github.com/containerd/continuity/ioutils.go
generated
vendored
Normal file
39
vendor/github.com/containerd/continuity/ioutils.go
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package continuity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// atomicWriteFile writes data to a file by first writing to a temp
|
||||||
|
// file and calling rename.
|
||||||
|
func atomicWriteFile(filename string, r io.Reader, rf RegularFile) error {
|
||||||
|
f, err := ioutil.TempFile(filepath.Dir(filename), ".tmp-"+filepath.Base(filename))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.Chmod(f.Name(), rf.Mode())
|
||||||
|
if err != nil {
|
||||||
|
f.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
n, err := io.Copy(f, r)
|
||||||
|
if err == nil && n < rf.Size() {
|
||||||
|
f.Close()
|
||||||
|
return io.ErrShortWrite
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
f.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := f.Sync(); err != nil {
|
||||||
|
f.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := f.Close(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return os.Rename(f.Name(), filename)
|
||||||
|
}
|
144
vendor/github.com/containerd/continuity/manifest.go
generated
vendored
Normal file
144
vendor/github.com/containerd/continuity/manifest.go
generated
vendored
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
package continuity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
pb "github.com/containerd/continuity/proto"
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Manifest provides the contents of a manifest. Users of this struct should
|
||||||
|
// not typically modify any fields directly.
|
||||||
|
type Manifest struct {
|
||||||
|
// Resources specifies all the resources for a manifest in order by path.
|
||||||
|
Resources []Resource
|
||||||
|
}
|
||||||
|
|
||||||
|
func Unmarshal(p []byte) (*Manifest, error) {
|
||||||
|
var bm pb.Manifest
|
||||||
|
|
||||||
|
if err := proto.Unmarshal(p, &bm); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var m Manifest
|
||||||
|
for _, b := range bm.Resource {
|
||||||
|
r, err := fromProto(b)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Resources = append(m.Resources, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Marshal(m *Manifest) ([]byte, error) {
|
||||||
|
var bm pb.Manifest
|
||||||
|
for _, resource := range m.Resources {
|
||||||
|
bm.Resource = append(bm.Resource, toProto(resource))
|
||||||
|
}
|
||||||
|
|
||||||
|
return proto.Marshal(&bm)
|
||||||
|
}
|
||||||
|
|
||||||
|
func MarshalText(w io.Writer, m *Manifest) error {
|
||||||
|
var bm pb.Manifest
|
||||||
|
for _, resource := range m.Resources {
|
||||||
|
bm.Resource = append(bm.Resource, toProto(resource))
|
||||||
|
}
|
||||||
|
|
||||||
|
return proto.MarshalText(w, &bm)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuildManifest creates the manifest for the given context
|
||||||
|
func BuildManifest(ctx Context) (*Manifest, error) {
|
||||||
|
resourcesByPath := map[string]Resource{}
|
||||||
|
hardlinks := newHardlinkManager()
|
||||||
|
|
||||||
|
if err := ctx.Walk(func(p string, fi os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error walking %s: %v", p, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if p == "/" {
|
||||||
|
// skip root
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
resource, err := ctx.Resource(p, fi)
|
||||||
|
if err != nil {
|
||||||
|
if err == ErrNotFound {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
log.Printf("error getting resource %q: %v", p, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// add to the hardlink manager
|
||||||
|
if err := hardlinks.Add(fi, resource); err == nil {
|
||||||
|
// Resource has been accepted by hardlink manager so we don't add
|
||||||
|
// it to the resourcesByPath until we merge at the end.
|
||||||
|
return nil
|
||||||
|
} else if err != errNotAHardLink {
|
||||||
|
// handle any other case where we have a proper error.
|
||||||
|
return fmt.Errorf("adding hardlink %s: %v", p, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
resourcesByPath[p] = resource
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// merge and post-process the hardlinks.
|
||||||
|
hardlinked, err := hardlinks.Merge()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, resource := range hardlinked {
|
||||||
|
resourcesByPath[resource.Path()] = resource
|
||||||
|
}
|
||||||
|
|
||||||
|
var resources []Resource
|
||||||
|
for _, resource := range resourcesByPath {
|
||||||
|
resources = append(resources, resource)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Stable(ByPath(resources))
|
||||||
|
|
||||||
|
return &Manifest{
|
||||||
|
Resources: resources,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifyManifest verifies all the resources in a manifest
|
||||||
|
// against files from the given context.
|
||||||
|
func VerifyManifest(ctx Context, manifest *Manifest) error {
|
||||||
|
for _, resource := range manifest.Resources {
|
||||||
|
if err := ctx.Verify(resource); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyManifest applies on the resources in a manifest to
|
||||||
|
// the given context.
|
||||||
|
func ApplyManifest(ctx Context, manifest *Manifest) error {
|
||||||
|
for _, resource := range manifest.Resources {
|
||||||
|
if err := ctx.Apply(resource); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
23
vendor/github.com/containerd/continuity/manifest_test_darwin.go
generated
vendored
Normal file
23
vendor/github.com/containerd/continuity/manifest_test_darwin.go
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
// +build ignore
|
||||||
|
|
||||||
|
package continuity
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
var (
|
||||||
|
devNullResource = resource{
|
||||||
|
kind: chardev,
|
||||||
|
path: "/dev/null",
|
||||||
|
major: 3,
|
||||||
|
minor: 2,
|
||||||
|
mode: 0666 | os.ModeDevice | os.ModeCharDevice,
|
||||||
|
}
|
||||||
|
|
||||||
|
devZeroResource = resource{
|
||||||
|
kind: chardev,
|
||||||
|
path: "/dev/zero",
|
||||||
|
major: 3,
|
||||||
|
minor: 3,
|
||||||
|
mode: 0666 | os.ModeDevice | os.ModeCharDevice,
|
||||||
|
}
|
||||||
|
)
|
85
vendor/github.com/containerd/continuity/pathdriver/path_driver.go
generated
vendored
Normal file
85
vendor/github.com/containerd/continuity/pathdriver/path_driver.go
generated
vendored
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
package pathdriver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PathDriver provides all of the path manipulation functions in a common
|
||||||
|
// interface. The context should call these and never use the `filepath`
|
||||||
|
// package or any other package to manipulate paths.
|
||||||
|
type PathDriver interface {
|
||||||
|
Join(paths ...string) string
|
||||||
|
IsAbs(path string) bool
|
||||||
|
Rel(base, target string) (string, error)
|
||||||
|
Base(path string) string
|
||||||
|
Dir(path string) string
|
||||||
|
Clean(path string) string
|
||||||
|
Split(path string) (dir, file string)
|
||||||
|
Separator() byte
|
||||||
|
Abs(path string) (string, error)
|
||||||
|
Walk(string, filepath.WalkFunc) error
|
||||||
|
FromSlash(path string) string
|
||||||
|
ToSlash(path string) string
|
||||||
|
Match(pattern, name string) (matched bool, err error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// pathDriver is a simple default implementation calls the filepath package.
|
||||||
|
type pathDriver struct{}
|
||||||
|
|
||||||
|
// LocalPathDriver is the exported pathDriver struct for convenience.
|
||||||
|
var LocalPathDriver PathDriver = &pathDriver{}
|
||||||
|
|
||||||
|
func (*pathDriver) Join(paths ...string) string {
|
||||||
|
return filepath.Join(paths...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*pathDriver) IsAbs(path string) bool {
|
||||||
|
return filepath.IsAbs(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*pathDriver) Rel(base, target string) (string, error) {
|
||||||
|
return filepath.Rel(base, target)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*pathDriver) Base(path string) string {
|
||||||
|
return filepath.Base(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*pathDriver) Dir(path string) string {
|
||||||
|
return filepath.Dir(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*pathDriver) Clean(path string) string {
|
||||||
|
return filepath.Clean(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*pathDriver) Split(path string) (dir, file string) {
|
||||||
|
return filepath.Split(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*pathDriver) Separator() byte {
|
||||||
|
return filepath.Separator
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*pathDriver) Abs(path string) (string, error) {
|
||||||
|
return filepath.Abs(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note that filepath.Walk calls os.Stat, so if the context wants to
|
||||||
|
// to call Driver.Stat() for Walk, they need to create a new struct that
|
||||||
|
// overrides this method.
|
||||||
|
func (*pathDriver) Walk(root string, walkFn filepath.WalkFunc) error {
|
||||||
|
return filepath.Walk(root, walkFn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*pathDriver) FromSlash(path string) string {
|
||||||
|
return filepath.FromSlash(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*pathDriver) ToSlash(path string) string {
|
||||||
|
return filepath.ToSlash(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*pathDriver) Match(pattern, name string) (bool, error) {
|
||||||
|
return filepath.Match(pattern, name)
|
||||||
|
}
|
574
vendor/github.com/containerd/continuity/resource.go
generated
vendored
Normal file
574
vendor/github.com/containerd/continuity/resource.go
generated
vendored
Normal file
|
@ -0,0 +1,574 @@
|
||||||
|
package continuity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
pb "github.com/containerd/continuity/proto"
|
||||||
|
"github.com/opencontainers/go-digest"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO(stevvooe): A record based model, somewhat sketched out at the bottom
|
||||||
|
// of this file, will be more flexible. Another possibly is to tie the package
|
||||||
|
// interface directly to the protobuf type. This will have efficiency
|
||||||
|
// advantages at the cost coupling the nasty codegen types to the exported
|
||||||
|
// interface.
|
||||||
|
|
||||||
|
type Resource interface {
|
||||||
|
// Path provides the primary resource path relative to the bundle root. In
|
||||||
|
// cases where resources have more than one path, such as with hard links,
|
||||||
|
// this will return the primary path, which is often just the first entry.
|
||||||
|
Path() string
|
||||||
|
|
||||||
|
// Mode returns the
|
||||||
|
Mode() os.FileMode
|
||||||
|
|
||||||
|
UID() int64
|
||||||
|
GID() int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPath provides the canonical sort order for a set of resources. Use with
|
||||||
|
// sort.Stable for deterministic sorting.
|
||||||
|
type ByPath []Resource
|
||||||
|
|
||||||
|
func (bp ByPath) Len() int { return len(bp) }
|
||||||
|
func (bp ByPath) Swap(i, j int) { bp[i], bp[j] = bp[j], bp[i] }
|
||||||
|
func (bp ByPath) Less(i, j int) bool { return bp[i].Path() < bp[j].Path() }
|
||||||
|
|
||||||
|
type XAttrer interface {
|
||||||
|
XAttrs() map[string][]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hardlinkable is an interface that a resource type satisfies if it can be a
|
||||||
|
// hardlink target.
|
||||||
|
type Hardlinkable interface {
|
||||||
|
// Paths returns all paths of the resource, including the primary path
|
||||||
|
// returned by Resource.Path. If len(Paths()) > 1, the resource is a hard
|
||||||
|
// link.
|
||||||
|
Paths() []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type RegularFile interface {
|
||||||
|
Resource
|
||||||
|
XAttrer
|
||||||
|
Hardlinkable
|
||||||
|
|
||||||
|
Size() int64
|
||||||
|
Digests() []digest.Digest
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge two or more Resources into new file. Typically, this should be
|
||||||
|
// used to merge regular files as hardlinks. If the files are not identical,
|
||||||
|
// other than Paths and Digests, the merge will fail and an error will be
|
||||||
|
// returned.
|
||||||
|
func Merge(fs ...Resource) (Resource, error) {
|
||||||
|
if len(fs) < 1 {
|
||||||
|
return nil, fmt.Errorf("please provide a resource to merge")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(fs) == 1 {
|
||||||
|
return fs[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var paths []string
|
||||||
|
var digests []digest.Digest
|
||||||
|
bypath := map[string][]Resource{}
|
||||||
|
|
||||||
|
// The attributes are all compared against the first to make sure they
|
||||||
|
// agree before adding to the above collections. If any of these don't
|
||||||
|
// correctly validate, the merge fails.
|
||||||
|
prototype := fs[0]
|
||||||
|
xattrs := make(map[string][]byte)
|
||||||
|
|
||||||
|
// initialize xattrs for use below. All files must have same xattrs.
|
||||||
|
if prototypeXAttrer, ok := prototype.(XAttrer); ok {
|
||||||
|
for attr, value := range prototypeXAttrer.XAttrs() {
|
||||||
|
xattrs[attr] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range fs {
|
||||||
|
h, isHardlinkable := f.(Hardlinkable)
|
||||||
|
if !isHardlinkable {
|
||||||
|
return nil, errNotAHardLink
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.Mode() != prototype.Mode() {
|
||||||
|
return nil, fmt.Errorf("modes do not match: %v != %v", f.Mode(), prototype.Mode())
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.UID() != prototype.UID() {
|
||||||
|
return nil, fmt.Errorf("uid does not match: %v != %v", f.UID(), prototype.UID())
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.GID() != prototype.GID() {
|
||||||
|
return nil, fmt.Errorf("gid does not match: %v != %v", f.GID(), prototype.GID())
|
||||||
|
}
|
||||||
|
|
||||||
|
if xattrer, ok := f.(XAttrer); ok {
|
||||||
|
fxattrs := xattrer.XAttrs()
|
||||||
|
if !reflect.DeepEqual(fxattrs, xattrs) {
|
||||||
|
return nil, fmt.Errorf("resource %q xattrs do not match: %v != %v", f, fxattrs, xattrs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range h.Paths() {
|
||||||
|
pfs, ok := bypath[p]
|
||||||
|
if !ok {
|
||||||
|
// ensure paths are unique by only appending on a new path.
|
||||||
|
paths = append(paths, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
bypath[p] = append(pfs, f)
|
||||||
|
}
|
||||||
|
|
||||||
|
if regFile, isRegFile := f.(RegularFile); isRegFile {
|
||||||
|
prototypeRegFile, prototypeIsRegFile := prototype.(RegularFile)
|
||||||
|
if !prototypeIsRegFile {
|
||||||
|
return nil, errors.New("prototype is not a regular file")
|
||||||
|
}
|
||||||
|
|
||||||
|
if regFile.Size() != prototypeRegFile.Size() {
|
||||||
|
return nil, fmt.Errorf("size does not match: %v != %v", regFile.Size(), prototypeRegFile.Size())
|
||||||
|
}
|
||||||
|
|
||||||
|
digests = append(digests, regFile.Digests()...)
|
||||||
|
} else if device, isDevice := f.(Device); isDevice {
|
||||||
|
prototypeDevice, prototypeIsDevice := prototype.(Device)
|
||||||
|
if !prototypeIsDevice {
|
||||||
|
return nil, errors.New("prototype is not a device")
|
||||||
|
}
|
||||||
|
|
||||||
|
if device.Major() != prototypeDevice.Major() {
|
||||||
|
return nil, fmt.Errorf("major number does not match: %v != %v", device.Major(), prototypeDevice.Major())
|
||||||
|
}
|
||||||
|
if device.Minor() != prototypeDevice.Minor() {
|
||||||
|
return nil, fmt.Errorf("minor number does not match: %v != %v", device.Minor(), prototypeDevice.Minor())
|
||||||
|
}
|
||||||
|
} else if _, isNamedPipe := f.(NamedPipe); isNamedPipe {
|
||||||
|
_, prototypeIsNamedPipe := prototype.(NamedPipe)
|
||||||
|
if !prototypeIsNamedPipe {
|
||||||
|
return nil, errors.New("prototype is not a named pipe")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil, errNotAHardLink
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Stable(sort.StringSlice(paths))
|
||||||
|
|
||||||
|
// Choose a "canonical" file. Really, it is just the first file to sort
|
||||||
|
// against. We also effectively select the very first digest as the
|
||||||
|
// "canonical" one for this file.
|
||||||
|
first := bypath[paths[0]][0]
|
||||||
|
|
||||||
|
resource := resource{
|
||||||
|
paths: paths,
|
||||||
|
mode: first.Mode(),
|
||||||
|
uid: first.UID(),
|
||||||
|
gid: first.GID(),
|
||||||
|
xattrs: xattrs,
|
||||||
|
}
|
||||||
|
|
||||||
|
switch typedF := first.(type) {
|
||||||
|
case RegularFile:
|
||||||
|
var err error
|
||||||
|
digests, err = uniqifyDigests(digests...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ®ularFile{
|
||||||
|
resource: resource,
|
||||||
|
size: typedF.Size(),
|
||||||
|
digests: digests,
|
||||||
|
}, nil
|
||||||
|
case Device:
|
||||||
|
return &device{
|
||||||
|
resource: resource,
|
||||||
|
major: typedF.Major(),
|
||||||
|
minor: typedF.Minor(),
|
||||||
|
}, nil
|
||||||
|
|
||||||
|
case NamedPipe:
|
||||||
|
return &namedPipe{
|
||||||
|
resource: resource,
|
||||||
|
}, nil
|
||||||
|
|
||||||
|
default:
|
||||||
|
return nil, errNotAHardLink
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Directory interface {
|
||||||
|
Resource
|
||||||
|
XAttrer
|
||||||
|
|
||||||
|
// Directory is a no-op method to identify directory objects by interface.
|
||||||
|
Directory()
|
||||||
|
}
|
||||||
|
|
||||||
|
type SymLink interface {
|
||||||
|
Resource
|
||||||
|
|
||||||
|
// Target returns the target of the symlink contained in the .
|
||||||
|
Target() string
|
||||||
|
}
|
||||||
|
|
||||||
|
type NamedPipe interface {
|
||||||
|
Resource
|
||||||
|
Hardlinkable
|
||||||
|
XAttrer
|
||||||
|
|
||||||
|
// Pipe is a no-op method to allow consistent resolution of NamedPipe
|
||||||
|
// interface.
|
||||||
|
Pipe()
|
||||||
|
}
|
||||||
|
|
||||||
|
type Device interface {
|
||||||
|
Resource
|
||||||
|
Hardlinkable
|
||||||
|
XAttrer
|
||||||
|
|
||||||
|
Major() uint64
|
||||||
|
Minor() uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
type resource struct {
|
||||||
|
paths []string
|
||||||
|
mode os.FileMode
|
||||||
|
uid, gid int64
|
||||||
|
xattrs map[string][]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ Resource = &resource{}
|
||||||
|
|
||||||
|
func (r *resource) Path() string {
|
||||||
|
if len(r.paths) < 1 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.paths[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *resource) Mode() os.FileMode {
|
||||||
|
return r.mode
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *resource) UID() int64 {
|
||||||
|
return r.uid
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *resource) GID() int64 {
|
||||||
|
return r.gid
|
||||||
|
}
|
||||||
|
|
||||||
|
type regularFile struct {
|
||||||
|
resource
|
||||||
|
size int64
|
||||||
|
digests []digest.Digest
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ RegularFile = ®ularFile{}
|
||||||
|
|
||||||
|
// newRegularFile returns the RegularFile, using the populated base resource
|
||||||
|
// and one or more digests of the content.
|
||||||
|
func newRegularFile(base resource, paths []string, size int64, dgsts ...digest.Digest) (RegularFile, error) {
|
||||||
|
if !base.Mode().IsRegular() {
|
||||||
|
return nil, fmt.Errorf("not a regular file")
|
||||||
|
}
|
||||||
|
|
||||||
|
base.paths = make([]string, len(paths))
|
||||||
|
copy(base.paths, paths)
|
||||||
|
|
||||||
|
// make our own copy of digests
|
||||||
|
ds := make([]digest.Digest, len(dgsts))
|
||||||
|
copy(ds, dgsts)
|
||||||
|
|
||||||
|
return ®ularFile{
|
||||||
|
resource: base,
|
||||||
|
size: size,
|
||||||
|
digests: ds,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rf *regularFile) Paths() []string {
|
||||||
|
paths := make([]string, len(rf.paths))
|
||||||
|
copy(paths, rf.paths)
|
||||||
|
return paths
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rf *regularFile) Size() int64 {
|
||||||
|
return rf.size
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rf *regularFile) Digests() []digest.Digest {
|
||||||
|
digests := make([]digest.Digest, len(rf.digests))
|
||||||
|
copy(digests, rf.digests)
|
||||||
|
return digests
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rf *regularFile) XAttrs() map[string][]byte {
|
||||||
|
xattrs := make(map[string][]byte, len(rf.xattrs))
|
||||||
|
|
||||||
|
for attr, value := range rf.xattrs {
|
||||||
|
xattrs[attr] = append(xattrs[attr], value...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return xattrs
|
||||||
|
}
|
||||||
|
|
||||||
|
type directory struct {
|
||||||
|
resource
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ Directory = &directory{}
|
||||||
|
|
||||||
|
func newDirectory(base resource) (Directory, error) {
|
||||||
|
if !base.Mode().IsDir() {
|
||||||
|
return nil, fmt.Errorf("not a directory")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &directory{
|
||||||
|
resource: base,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *directory) Directory() {}
|
||||||
|
|
||||||
|
func (d *directory) XAttrs() map[string][]byte {
|
||||||
|
xattrs := make(map[string][]byte, len(d.xattrs))
|
||||||
|
|
||||||
|
for attr, value := range d.xattrs {
|
||||||
|
xattrs[attr] = append(xattrs[attr], value...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return xattrs
|
||||||
|
}
|
||||||
|
|
||||||
|
type symLink struct {
|
||||||
|
resource
|
||||||
|
target string
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ SymLink = &symLink{}
|
||||||
|
|
||||||
|
func newSymLink(base resource, target string) (SymLink, error) {
|
||||||
|
if base.Mode()&os.ModeSymlink == 0 {
|
||||||
|
return nil, fmt.Errorf("not a symlink")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &symLink{
|
||||||
|
resource: base,
|
||||||
|
target: target,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *symLink) Target() string {
|
||||||
|
return l.target
|
||||||
|
}
|
||||||
|
|
||||||
|
type namedPipe struct {
|
||||||
|
resource
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ NamedPipe = &namedPipe{}
|
||||||
|
|
||||||
|
func newNamedPipe(base resource, paths []string) (NamedPipe, error) {
|
||||||
|
if base.Mode()&os.ModeNamedPipe == 0 {
|
||||||
|
return nil, fmt.Errorf("not a namedpipe")
|
||||||
|
}
|
||||||
|
|
||||||
|
base.paths = make([]string, len(paths))
|
||||||
|
copy(base.paths, paths)
|
||||||
|
|
||||||
|
return &namedPipe{
|
||||||
|
resource: base,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (np *namedPipe) Pipe() {}
|
||||||
|
|
||||||
|
func (np *namedPipe) Paths() []string {
|
||||||
|
paths := make([]string, len(np.paths))
|
||||||
|
copy(paths, np.paths)
|
||||||
|
return paths
|
||||||
|
}
|
||||||
|
|
||||||
|
func (np *namedPipe) XAttrs() map[string][]byte {
|
||||||
|
xattrs := make(map[string][]byte, len(np.xattrs))
|
||||||
|
|
||||||
|
for attr, value := range np.xattrs {
|
||||||
|
xattrs[attr] = append(xattrs[attr], value...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return xattrs
|
||||||
|
}
|
||||||
|
|
||||||
|
type device struct {
|
||||||
|
resource
|
||||||
|
major, minor uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ Device = &device{}
|
||||||
|
|
||||||
|
func newDevice(base resource, paths []string, major, minor uint64) (Device, error) {
|
||||||
|
if base.Mode()&os.ModeDevice == 0 {
|
||||||
|
return nil, fmt.Errorf("not a device")
|
||||||
|
}
|
||||||
|
|
||||||
|
base.paths = make([]string, len(paths))
|
||||||
|
copy(base.paths, paths)
|
||||||
|
|
||||||
|
return &device{
|
||||||
|
resource: base,
|
||||||
|
major: major,
|
||||||
|
minor: minor,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *device) Paths() []string {
|
||||||
|
paths := make([]string, len(d.paths))
|
||||||
|
copy(paths, d.paths)
|
||||||
|
return paths
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *device) XAttrs() map[string][]byte {
|
||||||
|
xattrs := make(map[string][]byte, len(d.xattrs))
|
||||||
|
|
||||||
|
for attr, value := range d.xattrs {
|
||||||
|
xattrs[attr] = append(xattrs[attr], value...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return xattrs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d device) Major() uint64 {
|
||||||
|
return d.major
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d device) Minor() uint64 {
|
||||||
|
return d.minor
|
||||||
|
}
|
||||||
|
|
||||||
|
// toProto converts a resource to a protobuf record. We'd like to push this
|
||||||
|
// the individual types but we want to keep this all together during
|
||||||
|
// prototyping.
|
||||||
|
func toProto(resource Resource) *pb.Resource {
|
||||||
|
b := &pb.Resource{
|
||||||
|
Path: []string{resource.Path()},
|
||||||
|
Mode: uint32(resource.Mode()),
|
||||||
|
Uid: resource.UID(),
|
||||||
|
Gid: resource.GID(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if xattrer, ok := resource.(XAttrer); ok {
|
||||||
|
// Sorts the XAttrs by name for consistent ordering.
|
||||||
|
keys := []string{}
|
||||||
|
xattrs := xattrer.XAttrs()
|
||||||
|
for k := range xattrs {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
for _, k := range keys {
|
||||||
|
b.Xattr = append(b.Xattr, &pb.XAttr{Name: k, Data: xattrs[k]})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch r := resource.(type) {
|
||||||
|
case RegularFile:
|
||||||
|
b.Path = r.Paths()
|
||||||
|
b.Size = uint64(r.Size())
|
||||||
|
|
||||||
|
for _, dgst := range r.Digests() {
|
||||||
|
b.Digest = append(b.Digest, dgst.String())
|
||||||
|
}
|
||||||
|
case SymLink:
|
||||||
|
b.Target = r.Target()
|
||||||
|
case Device:
|
||||||
|
b.Major, b.Minor = r.Major(), r.Minor()
|
||||||
|
b.Path = r.Paths()
|
||||||
|
case NamedPipe:
|
||||||
|
b.Path = r.Paths()
|
||||||
|
}
|
||||||
|
|
||||||
|
// enforce a few stability guarantees that may not be provided by the
|
||||||
|
// resource implementation.
|
||||||
|
sort.Strings(b.Path)
|
||||||
|
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// fromProto converts from a protobuf Resource to a Resource interface.
|
||||||
|
func fromProto(b *pb.Resource) (Resource, error) {
|
||||||
|
base := &resource{
|
||||||
|
paths: b.Path,
|
||||||
|
mode: os.FileMode(b.Mode),
|
||||||
|
uid: b.Uid,
|
||||||
|
gid: b.Gid,
|
||||||
|
}
|
||||||
|
|
||||||
|
base.xattrs = make(map[string][]byte, len(b.Xattr))
|
||||||
|
|
||||||
|
for _, attr := range b.Xattr {
|
||||||
|
base.xattrs[attr.Name] = attr.Data
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case base.Mode().IsRegular():
|
||||||
|
dgsts := make([]digest.Digest, len(b.Digest))
|
||||||
|
for i, dgst := range b.Digest {
|
||||||
|
// TODO(stevvooe): Should we be validating at this point?
|
||||||
|
dgsts[i] = digest.Digest(dgst)
|
||||||
|
}
|
||||||
|
|
||||||
|
return newRegularFile(*base, b.Path, int64(b.Size), dgsts...)
|
||||||
|
case base.Mode().IsDir():
|
||||||
|
return newDirectory(*base)
|
||||||
|
case base.Mode()&os.ModeSymlink != 0:
|
||||||
|
return newSymLink(*base, b.Target)
|
||||||
|
case base.Mode()&os.ModeNamedPipe != 0:
|
||||||
|
return newNamedPipe(*base, b.Path)
|
||||||
|
case base.Mode()&os.ModeDevice != 0:
|
||||||
|
return newDevice(*base, b.Path, b.Major, b.Minor)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("unknown resource record (%#v): %s", b, base.Mode())
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE(stevvooe): An alternative model that supports inline declaration.
|
||||||
|
// Convenient for unit testing where inline declarations may be desirable but
|
||||||
|
// creates an awkward API for the standard use case.
|
||||||
|
|
||||||
|
// type ResourceKind int
|
||||||
|
|
||||||
|
// const (
|
||||||
|
// ResourceRegularFile = iota + 1
|
||||||
|
// ResourceDirectory
|
||||||
|
// ResourceSymLink
|
||||||
|
// Resource
|
||||||
|
// )
|
||||||
|
|
||||||
|
// type Resource struct {
|
||||||
|
// Kind ResourceKind
|
||||||
|
// Paths []string
|
||||||
|
// Mode os.FileMode
|
||||||
|
// UID string
|
||||||
|
// GID string
|
||||||
|
// Size int64
|
||||||
|
// Digests []digest.Digest
|
||||||
|
// Target string
|
||||||
|
// Major, Minor int
|
||||||
|
// XAttrs map[string][]byte
|
||||||
|
// }
|
||||||
|
|
||||||
|
// type RegularFile struct {
|
||||||
|
// Paths []string
|
||||||
|
// Size int64
|
||||||
|
// Digests []digest.Digest
|
||||||
|
// Perm os.FileMode // os.ModePerm + sticky, setuid, setgid
|
||||||
|
// }
|
37
vendor/github.com/containerd/continuity/resource_unix.go
generated
vendored
Normal file
37
vendor/github.com/containerd/continuity/resource_unix.go
generated
vendored
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
// +build linux darwin freebsd solaris
|
||||||
|
|
||||||
|
package continuity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
// newBaseResource returns a *resource, populated with data from p and fi,
|
||||||
|
// where p will be populated directly.
|
||||||
|
func newBaseResource(p string, fi os.FileInfo) (*resource, error) {
|
||||||
|
// TODO(stevvooe): This need to be resolved for the container's root,
|
||||||
|
// where here we are really getting the host OS's value. We need to allow
|
||||||
|
// this be passed in and fixed up to make these uid/gid mappings portable.
|
||||||
|
// Either this can be part of the driver or we can achieve it through some
|
||||||
|
// other mechanism.
|
||||||
|
sys, ok := fi.Sys().(*syscall.Stat_t)
|
||||||
|
if !ok {
|
||||||
|
// TODO(stevvooe): This may not be a hard error for all platforms. We
|
||||||
|
// may want to move this to the driver.
|
||||||
|
return nil, fmt.Errorf("unable to resolve syscall.Stat_t from (os.FileInfo).Sys(): %#v", fi)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &resource{
|
||||||
|
paths: []string{p},
|
||||||
|
mode: fi.Mode(),
|
||||||
|
|
||||||
|
uid: int64(sys.Uid),
|
||||||
|
gid: int64(sys.Gid),
|
||||||
|
|
||||||
|
// NOTE(stevvooe): Population of shared xattrs field is deferred to
|
||||||
|
// the resource types that populate it. Since they are a property of
|
||||||
|
// the context, they must set there.
|
||||||
|
}, nil
|
||||||
|
}
|
12
vendor/github.com/containerd/continuity/resource_windows.go
generated
vendored
Normal file
12
vendor/github.com/containerd/continuity/resource_windows.go
generated
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package continuity
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
// newBaseResource returns a *resource, populated with data from p and fi,
|
||||||
|
// where p will be populated directly.
|
||||||
|
func newBaseResource(p string, fi os.FileInfo) (*resource, error) {
|
||||||
|
return &resource{
|
||||||
|
paths: []string{p},
|
||||||
|
mode: fi.Mode(),
|
||||||
|
}, nil
|
||||||
|
}
|
14
vendor/github.com/docker/cli/cli/cobra.go
generated
vendored
14
vendor/github.com/docker/cli/cli/cobra.go
generated
vendored
|
@ -17,6 +17,7 @@ func SetupRootCommand(rootCmd *cobra.Command) {
|
||||||
cobra.AddTemplateFunc("operationSubCommands", operationSubCommands)
|
cobra.AddTemplateFunc("operationSubCommands", operationSubCommands)
|
||||||
cobra.AddTemplateFunc("managementSubCommands", managementSubCommands)
|
cobra.AddTemplateFunc("managementSubCommands", managementSubCommands)
|
||||||
cobra.AddTemplateFunc("wrappedFlagUsages", wrappedFlagUsages)
|
cobra.AddTemplateFunc("wrappedFlagUsages", wrappedFlagUsages)
|
||||||
|
cobra.AddTemplateFunc("useLine", UseLine)
|
||||||
|
|
||||||
rootCmd.SetUsageTemplate(usageTemplate)
|
rootCmd.SetUsageTemplate(usageTemplate)
|
||||||
rootCmd.SetHelpTemplate(helpTemplate)
|
rootCmd.SetHelpTemplate(helpTemplate)
|
||||||
|
@ -25,6 +26,7 @@ func SetupRootCommand(rootCmd *cobra.Command) {
|
||||||
|
|
||||||
rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage")
|
rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage")
|
||||||
rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help")
|
rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help")
|
||||||
|
rootCmd.PersistentFlags().Lookup("help").Hidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// FlagErrorFunc prints an error message which matches the format of the
|
// FlagErrorFunc prints an error message which matches the format of the
|
||||||
|
@ -97,9 +99,19 @@ func managementSubCommands(cmd *cobra.Command) []*cobra.Command {
|
||||||
return cmds
|
return cmds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UseLine returns the usage line for a command. This implementation is different
|
||||||
|
// from the default Command.UseLine in that it does not add a `[flags]` to the
|
||||||
|
// end of the line.
|
||||||
|
func UseLine(cmd *cobra.Command) string {
|
||||||
|
if cmd.HasParent() {
|
||||||
|
return cmd.Parent().CommandPath() + " " + cmd.Use
|
||||||
|
}
|
||||||
|
return cmd.Use
|
||||||
|
}
|
||||||
|
|
||||||
var usageTemplate = `Usage:
|
var usageTemplate = `Usage:
|
||||||
|
|
||||||
{{- if not .HasSubCommands}} {{.UseLine}}{{end}}
|
{{- if not .HasSubCommands}} {{ useLine . }}{{end}}
|
||||||
{{- if .HasSubCommands}} {{ .CommandPath}} COMMAND{{end}}
|
{{- if .HasSubCommands}} {{ .CommandPath}} COMMAND{{end}}
|
||||||
|
|
||||||
{{ .Short | trim }}
|
{{ .Short | trim }}
|
||||||
|
|
157
vendor/github.com/docker/cli/cli/command/cli.go
generated
vendored
157
vendor/github.com/docker/cli/cli/command/cli.go
generated
vendored
|
@ -1,27 +1,28 @@
|
||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
cliconfig "github.com/docker/cli/cli/config"
|
cliconfig "github.com/docker/cli/cli/config"
|
||||||
"github.com/docker/cli/cli/config/configfile"
|
"github.com/docker/cli/cli/config/configfile"
|
||||||
"github.com/docker/cli/cli/config/credentials"
|
|
||||||
cliflags "github.com/docker/cli/cli/flags"
|
cliflags "github.com/docker/cli/cli/flags"
|
||||||
|
"github.com/docker/cli/cli/trust"
|
||||||
dopts "github.com/docker/cli/opts"
|
dopts "github.com/docker/cli/opts"
|
||||||
"github.com/docker/docker/api"
|
"github.com/docker/docker/api"
|
||||||
"github.com/docker/docker/api/types"
|
|
||||||
"github.com/docker/docker/api/types/versions"
|
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/go-connections/sockets"
|
"github.com/docker/go-connections/sockets"
|
||||||
"github.com/docker/go-connections/tlsconfig"
|
"github.com/docker/go-connections/tlsconfig"
|
||||||
"github.com/docker/notary/passphrase"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/theupdateframework/notary"
|
||||||
|
notaryclient "github.com/theupdateframework/notary/client"
|
||||||
|
"github.com/theupdateframework/notary/passphrase"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,7 +41,8 @@ type Cli interface {
|
||||||
In() *InStream
|
In() *InStream
|
||||||
SetIn(in *InStream)
|
SetIn(in *InStream)
|
||||||
ConfigFile() *configfile.ConfigFile
|
ConfigFile() *configfile.ConfigFile
|
||||||
CredentialsStore(serverAddress string) credentials.Store
|
ServerInfo() ServerInfo
|
||||||
|
NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DockerCli is an instance the docker command line client.
|
// DockerCli is an instance the docker command line client.
|
||||||
|
@ -105,106 +107,66 @@ func (cli *DockerCli) ServerInfo() ServerInfo {
|
||||||
return cli.server
|
return cli.server
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllCredentials returns all of the credentials stored in all of the
|
|
||||||
// configured credential stores.
|
|
||||||
func (cli *DockerCli) GetAllCredentials() (map[string]types.AuthConfig, error) {
|
|
||||||
auths := make(map[string]types.AuthConfig)
|
|
||||||
for registry := range cli.configFile.CredentialHelpers {
|
|
||||||
helper := cli.CredentialsStore(registry)
|
|
||||||
newAuths, err := helper.GetAll()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
addAll(auths, newAuths)
|
|
||||||
}
|
|
||||||
defaultStore := cli.CredentialsStore("")
|
|
||||||
newAuths, err := defaultStore.GetAll()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
addAll(auths, newAuths)
|
|
||||||
return auths, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func addAll(to, from map[string]types.AuthConfig) {
|
|
||||||
for reg, ac := range from {
|
|
||||||
to[reg] = ac
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CredentialsStore returns a new credentials store based
|
|
||||||
// on the settings provided in the configuration file. Empty string returns
|
|
||||||
// the default credential store.
|
|
||||||
func (cli *DockerCli) CredentialsStore(serverAddress string) credentials.Store {
|
|
||||||
if helper := getConfiguredCredentialStore(cli.configFile, serverAddress); helper != "" {
|
|
||||||
return credentials.NewNativeStore(cli.configFile, helper)
|
|
||||||
}
|
|
||||||
return credentials.NewFileStore(cli.configFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
// getConfiguredCredentialStore returns the credential helper configured for the
|
|
||||||
// given registry, the default credsStore, or the empty string if neither are
|
|
||||||
// configured.
|
|
||||||
func getConfiguredCredentialStore(c *configfile.ConfigFile, serverAddress string) string {
|
|
||||||
if c.CredentialHelpers != nil && serverAddress != "" {
|
|
||||||
if helper, exists := c.CredentialHelpers[serverAddress]; exists {
|
|
||||||
return helper
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return c.CredentialsStore
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize the dockerCli runs initialization that must happen after command
|
// Initialize the dockerCli runs initialization that must happen after command
|
||||||
// line flags are parsed.
|
// line flags are parsed.
|
||||||
func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
|
func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
|
||||||
cli.configFile = LoadDefaultConfigFile(cli.err)
|
cli.configFile = cliconfig.LoadDefaultConfigFile(cli.err)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
cli.client, err = NewAPIClientFromFlags(opts.Common, cli.configFile)
|
cli.client, err = NewAPIClientFromFlags(opts.Common, cli.configFile)
|
||||||
if tlsconfig.IsErrEncryptedKey(err) {
|
if tlsconfig.IsErrEncryptedKey(err) {
|
||||||
var (
|
|
||||||
passwd string
|
|
||||||
giveup bool
|
|
||||||
)
|
|
||||||
passRetriever := passphrase.PromptRetrieverWithInOut(cli.In(), cli.Out(), nil)
|
passRetriever := passphrase.PromptRetrieverWithInOut(cli.In(), cli.Out(), nil)
|
||||||
|
newClient := func(password string) (client.APIClient, error) {
|
||||||
for attempts := 0; tlsconfig.IsErrEncryptedKey(err); attempts++ {
|
opts.Common.TLSOptions.Passphrase = password
|
||||||
// some code and comments borrowed from notary/trustmanager/keystore.go
|
return NewAPIClientFromFlags(opts.Common, cli.configFile)
|
||||||
passwd, giveup, err = passRetriever("private", "encrypted TLS private", false, attempts)
|
|
||||||
// Check if the passphrase retriever got an error or if it is telling us to give up
|
|
||||||
if giveup || err != nil {
|
|
||||||
return errors.Wrap(err, "private key is encrypted, but could not get passphrase")
|
|
||||||
}
|
|
||||||
|
|
||||||
opts.Common.TLSOptions.Passphrase = passwd
|
|
||||||
cli.client, err = NewAPIClientFromFlags(opts.Common, cli.configFile)
|
|
||||||
}
|
}
|
||||||
|
cli.client, err = getClientWithPassword(passRetriever, newClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
cli.initializeFromClient()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cli *DockerCli) initializeFromClient() {
|
||||||
cli.defaultVersion = cli.client.ClientVersion()
|
cli.defaultVersion = cli.client.ClientVersion()
|
||||||
|
|
||||||
if ping, err := cli.client.Ping(context.Background()); err == nil {
|
ping, err := cli.client.Ping(context.Background())
|
||||||
cli.server = ServerInfo{
|
if err != nil {
|
||||||
HasExperimental: ping.Experimental,
|
// Default to true if we fail to connect to daemon
|
||||||
OSType: ping.OSType,
|
cli.server = ServerInfo{HasExperimental: true}
|
||||||
}
|
|
||||||
|
|
||||||
// since the new header was added in 1.25, assume server is 1.24 if header is not present.
|
if ping.APIVersion != "" {
|
||||||
if ping.APIVersion == "" {
|
cli.client.NegotiateAPIVersionPing(ping)
|
||||||
ping.APIVersion = "1.24"
|
|
||||||
}
|
|
||||||
|
|
||||||
// if server version is lower than the current cli, downgrade
|
|
||||||
if versions.LessThan(ping.APIVersion, cli.client.ClientVersion()) {
|
|
||||||
cli.client.UpdateClientVersion(ping.APIVersion)
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
cli.server = ServerInfo{
|
||||||
|
HasExperimental: ping.Experimental,
|
||||||
|
OSType: ping.OSType,
|
||||||
|
}
|
||||||
|
cli.client.NegotiateAPIVersionPing(ping)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getClientWithPassword(passRetriever notary.PassRetriever, newClient func(password string) (client.APIClient, error)) (client.APIClient, error) {
|
||||||
|
for attempts := 0; ; attempts++ {
|
||||||
|
passwd, giveup, err := passRetriever("private", "encrypted TLS private", false, attempts)
|
||||||
|
if giveup || err != nil {
|
||||||
|
return nil, errors.Wrap(err, "private key is encrypted, but could not get passphrase")
|
||||||
|
}
|
||||||
|
|
||||||
|
apiclient, err := newClient(passwd)
|
||||||
|
if !tlsconfig.IsErrEncryptedKey(err) {
|
||||||
|
return apiclient, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotaryClient provides a Notary Repository to interact with signed metadata for an image
|
||||||
|
func (cli *DockerCli) NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error) {
|
||||||
|
return trust.GetNotaryRepository(cli.In(), cli.Out(), UserAgent(), imgRefAndAuth.RepoInfo(), imgRefAndAuth.AuthConfig(), actions...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerInfo stores details about the supported features and platform of the
|
// ServerInfo stores details about the supported features and platform of the
|
||||||
|
@ -219,19 +181,6 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer) *DockerCli {
|
||||||
return &DockerCli{in: NewInStream(in), out: NewOutStream(out), err: err}
|
return &DockerCli{in: NewInStream(in), out: NewOutStream(out), err: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadDefaultConfigFile attempts to load the default config file and returns
|
|
||||||
// an initialized ConfigFile struct if none is found.
|
|
||||||
func LoadDefaultConfigFile(err io.Writer) *configfile.ConfigFile {
|
|
||||||
configFile, e := cliconfig.Load(cliconfig.Dir())
|
|
||||||
if e != nil {
|
|
||||||
fmt.Fprintf(err, "WARNING: Error loading config file:%v\n", e)
|
|
||||||
}
|
|
||||||
if !configFile.ContainsAuth() {
|
|
||||||
credentials.DetectDefaultStore(configFile)
|
|
||||||
}
|
|
||||||
return configFile
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewAPIClientFromFlags creates a new APIClient from command line flags
|
// NewAPIClientFromFlags creates a new APIClient from command line flags
|
||||||
func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.ConfigFile) (client.APIClient, error) {
|
func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.ConfigFile) (client.APIClient, error) {
|
||||||
host, err := getServerHost(opts.Hosts, opts.TLSOptions)
|
host, err := getServerHost(opts.Hosts, opts.TLSOptions)
|
||||||
|
@ -258,7 +207,8 @@ func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.
|
||||||
return client.NewClient(host, verStr, httpClient, customHeaders)
|
return client.NewClient(host, verStr, httpClient, customHeaders)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (host string, err error) {
|
func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (string, error) {
|
||||||
|
var host string
|
||||||
switch len(hosts) {
|
switch len(hosts) {
|
||||||
case 0:
|
case 0:
|
||||||
host = os.Getenv("DOCKER_HOST")
|
host = os.Getenv("DOCKER_HOST")
|
||||||
|
@ -268,8 +218,7 @@ func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (host string,
|
||||||
return "", errors.New("Please specify only one -H")
|
return "", errors.New("Please specify only one -H")
|
||||||
}
|
}
|
||||||
|
|
||||||
host, err = dopts.ParseHost(tlsOptions != nil, host)
|
return dopts.ParseHost(tlsOptions != nil, host)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, error) {
|
func newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, error) {
|
||||||
|
@ -285,6 +234,10 @@ func newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, er
|
||||||
}
|
}
|
||||||
tr := &http.Transport{
|
tr := &http.Transport{
|
||||||
TLSClientConfig: config,
|
TLSClientConfig: config,
|
||||||
|
DialContext: (&net.Dialer{
|
||||||
|
KeepAlive: 30 * time.Second,
|
||||||
|
Timeout: 30 * time.Second,
|
||||||
|
}).DialContext,
|
||||||
}
|
}
|
||||||
proto, addr, _, err := client.ParseHost(host)
|
proto, addr, _, err := client.ParseHost(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
2
vendor/github.com/docker/cli/cli/command/events_utils.go
generated
vendored
2
vendor/github.com/docker/cli/cli/command/events_utils.go
generated
vendored
|
@ -3,8 +3,8 @@ package command
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
eventtypes "github.com/docker/docker/api/types/events"
|
eventtypes "github.com/docker/docker/api/types/events"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EventHandler is abstract interface for user to customize
|
// EventHandler is abstract interface for user to customize
|
||||||
|
|
133
vendor/github.com/docker/cli/cli/command/image/build.go
generated
vendored
133
vendor/github.com/docker/cli/cli/command/image/build.go
generated
vendored
|
@ -21,13 +21,14 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/idtools"
|
||||||
"github.com/docker/docker/pkg/jsonmessage"
|
"github.com/docker/docker/pkg/jsonmessage"
|
||||||
"github.com/docker/docker/pkg/progress"
|
"github.com/docker/docker/pkg/progress"
|
||||||
"github.com/docker/docker/pkg/streamformatter"
|
"github.com/docker/docker/pkg/streamformatter"
|
||||||
"github.com/docker/docker/pkg/urlutil"
|
"github.com/docker/docker/pkg/urlutil"
|
||||||
runconfigopts "github.com/docker/docker/runconfig/opts"
|
|
||||||
units "github.com/docker/go-units"
|
units "github.com/docker/go-units"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
@ -62,6 +63,8 @@ type buildOptions struct {
|
||||||
squash bool
|
squash bool
|
||||||
target string
|
target string
|
||||||
imageIDFile string
|
imageIDFile string
|
||||||
|
stream bool
|
||||||
|
platform string
|
||||||
}
|
}
|
||||||
|
|
||||||
// dockerfileFromStdin returns true when the user specified that the Dockerfile
|
// dockerfileFromStdin returns true when the user specified that the Dockerfile
|
||||||
|
@ -76,16 +79,20 @@ func (o buildOptions) contextFromStdin() bool {
|
||||||
return o.context == "-"
|
return o.context == "-"
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBuildCommand creates a new `docker build` command
|
func newBuildOptions() buildOptions {
|
||||||
func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|
||||||
ulimits := make(map[string]*units.Ulimit)
|
ulimits := make(map[string]*units.Ulimit)
|
||||||
options := buildOptions{
|
return buildOptions{
|
||||||
tags: opts.NewListOpts(validateTag),
|
tags: opts.NewListOpts(validateTag),
|
||||||
buildArgs: opts.NewListOpts(opts.ValidateEnv),
|
buildArgs: opts.NewListOpts(opts.ValidateEnv),
|
||||||
ulimits: opts.NewUlimitOpt(&ulimits),
|
ulimits: opts.NewUlimitOpt(&ulimits),
|
||||||
labels: opts.NewListOpts(opts.ValidateEnv),
|
labels: opts.NewListOpts(opts.ValidateEnv),
|
||||||
extraHosts: opts.NewListOpts(opts.ValidateExtraHost),
|
extraHosts: opts.NewListOpts(opts.ValidateExtraHost),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBuildCommand creates a new `docker build` command
|
||||||
|
func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
|
options := newBuildOptions()
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "build [OPTIONS] PATH | URL | -",
|
Use: "build [OPTIONS] PATH | URL | -",
|
||||||
|
@ -129,11 +136,16 @@ func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
flags.StringVar(&options.imageIDFile, "iidfile", "", "Write the image ID to the file")
|
flags.StringVar(&options.imageIDFile, "iidfile", "", "Write the image ID to the file")
|
||||||
|
|
||||||
command.AddTrustVerificationFlags(flags)
|
command.AddTrustVerificationFlags(flags)
|
||||||
|
command.AddPlatformFlag(flags, &options.platform)
|
||||||
|
|
||||||
flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer")
|
flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer")
|
||||||
flags.SetAnnotation("squash", "experimental", nil)
|
flags.SetAnnotation("squash", "experimental", nil)
|
||||||
flags.SetAnnotation("squash", "version", []string{"1.25"})
|
flags.SetAnnotation("squash", "version", []string{"1.25"})
|
||||||
|
|
||||||
|
flags.BoolVar(&options.stream, "stream", false, "Stream attaches to server to negotiate build context")
|
||||||
|
flags.SetAnnotation("stream", "experimental", nil)
|
||||||
|
flags.SetAnnotation("stream", "version", []string{"1.31"})
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +166,7 @@ func (out *lastProgressOutput) WriteProgress(prog progress.Progress) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: gocyclo
|
// nolint: gocyclo
|
||||||
func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
|
func runBuild(dockerCli command.Cli, options buildOptions) error {
|
||||||
var (
|
var (
|
||||||
buildCtx io.ReadCloser
|
buildCtx io.ReadCloser
|
||||||
dockerfileCtx io.ReadCloser
|
dockerfileCtx io.ReadCloser
|
||||||
|
@ -164,6 +176,7 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
|
||||||
relDockerfile string
|
relDockerfile string
|
||||||
progBuff io.Writer
|
progBuff io.Writer
|
||||||
buildBuff io.Writer
|
buildBuff io.Writer
|
||||||
|
remote string
|
||||||
)
|
)
|
||||||
|
|
||||||
if options.dockerfileFromStdin() {
|
if options.dockerfileFromStdin() {
|
||||||
|
@ -189,6 +202,7 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case options.contextFromStdin():
|
case options.contextFromStdin():
|
||||||
|
// buildCtx is tar archive. if stdin was dockerfile then it is wrapped
|
||||||
buildCtx, relDockerfile, err = build.GetContextFromReader(dockerCli.In(), options.dockerfileName)
|
buildCtx, relDockerfile, err = build.GetContextFromReader(dockerCli.In(), options.dockerfileName)
|
||||||
case isLocalDir(specifiedContext):
|
case isLocalDir(specifiedContext):
|
||||||
contextDir, relDockerfile, err = build.GetContextFromLocalDir(specifiedContext, options.dockerfileName)
|
contextDir, relDockerfile, err = build.GetContextFromLocalDir(specifiedContext, options.dockerfileName)
|
||||||
|
@ -212,7 +226,8 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
|
||||||
contextDir = tempDir
|
contextDir = tempDir
|
||||||
}
|
}
|
||||||
|
|
||||||
if buildCtx == nil {
|
// read from a directory into tar archive
|
||||||
|
if buildCtx == nil && !options.stream {
|
||||||
excludes, err := build.ReadDockerignore(contextDir)
|
excludes, err := build.ReadDockerignore(contextDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -229,38 +244,61 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
excludes = build.TrimBuildFilesFromExcludes(excludes, relDockerfile, options.dockerfileFromStdin())
|
excludes = build.TrimBuildFilesFromExcludes(excludes, relDockerfile, options.dockerfileFromStdin())
|
||||||
|
|
||||||
compression := archive.Uncompressed
|
|
||||||
if options.compress {
|
|
||||||
compression = archive.Gzip
|
|
||||||
}
|
|
||||||
buildCtx, err = archive.TarWithOptions(contextDir, &archive.TarOptions{
|
buildCtx, err = archive.TarWithOptions(contextDir, &archive.TarOptions{
|
||||||
Compression: compression,
|
|
||||||
ExcludePatterns: excludes,
|
ExcludePatterns: excludes,
|
||||||
|
ChownOpts: &idtools.IDPair{UID: 0, GID: 0},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace Dockerfile if added dynamically
|
// replace Dockerfile if it was added from stdin and there is archive context
|
||||||
if dockerfileCtx != nil {
|
if dockerfileCtx != nil && buildCtx != nil {
|
||||||
buildCtx, relDockerfile, err = build.AddDockerfileToBuildContext(dockerfileCtx, buildCtx)
|
buildCtx, relDockerfile, err = build.AddDockerfileToBuildContext(dockerfileCtx, buildCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
// if streaming and dockerfile was not from stdin then read from file
|
||||||
|
// to the same reader that is usually stdin
|
||||||
|
if options.stream && dockerfileCtx == nil {
|
||||||
|
dockerfileCtx, err = os.Open(relDockerfile)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "failed to open %s", relDockerfile)
|
||||||
|
}
|
||||||
|
defer dockerfileCtx.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
var resolvedTags []*resolvedTag
|
var resolvedTags []*resolvedTag
|
||||||
if command.IsTrusted() {
|
if command.IsTrusted() {
|
||||||
translator := func(ctx context.Context, ref reference.NamedTagged) (reference.Canonical, error) {
|
translator := func(ctx context.Context, ref reference.NamedTagged) (reference.Canonical, error) {
|
||||||
return TrustedReference(ctx, dockerCli, ref, nil)
|
return TrustedReference(ctx, dockerCli, ref, nil)
|
||||||
}
|
}
|
||||||
// Wrap the tar archive to replace the Dockerfile entry with the rewritten
|
// if there is a tar wrapper, the dockerfile needs to be replaced inside it
|
||||||
// Dockerfile which uses trusted pulls.
|
if buildCtx != nil {
|
||||||
buildCtx = replaceDockerfileTarWrapper(ctx, buildCtx, relDockerfile, translator, &resolvedTags)
|
// Wrap the tar archive to replace the Dockerfile entry with the rewritten
|
||||||
|
// Dockerfile which uses trusted pulls.
|
||||||
|
buildCtx = replaceDockerfileTarWrapper(ctx, buildCtx, relDockerfile, translator, &resolvedTags)
|
||||||
|
} else if dockerfileCtx != nil {
|
||||||
|
// if there was not archive context still do the possible replacements in Dockerfile
|
||||||
|
newDockerfile, _, err := rewriteDockerfileFrom(ctx, dockerfileCtx, translator)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
dockerfileCtx = ioutil.NopCloser(bytes.NewBuffer(newDockerfile))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.compress {
|
||||||
|
buildCtx, err = build.Compress(buildCtx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup an upload progress bar
|
// Setup an upload progress bar
|
||||||
|
@ -269,9 +307,46 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
|
||||||
progressOutput = &lastProgressOutput{output: progressOutput}
|
progressOutput = &lastProgressOutput{output: progressOutput}
|
||||||
}
|
}
|
||||||
|
|
||||||
var body io.Reader = progress.NewProgressReader(buildCtx, progressOutput, 0, "", "Sending build context to Docker daemon")
|
// if up to this point nothing has set the context then we must have another
|
||||||
|
// way for sending it(streaming) and set the context to the Dockerfile
|
||||||
|
if dockerfileCtx != nil && buildCtx == nil {
|
||||||
|
buildCtx = dockerfileCtx
|
||||||
|
}
|
||||||
|
|
||||||
authConfigs, _ := dockerCli.GetAllCredentials()
|
s, err := trySession(dockerCli, contextDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var body io.Reader
|
||||||
|
if buildCtx != nil && !options.stream {
|
||||||
|
body = progress.NewProgressReader(buildCtx, progressOutput, 0, "", "Sending build context to Docker daemon")
|
||||||
|
}
|
||||||
|
|
||||||
|
// add context stream to the session
|
||||||
|
if options.stream && s != nil {
|
||||||
|
syncDone := make(chan error) // used to signal first progress reporting completed.
|
||||||
|
// progress would also send errors but don't need it here as errors
|
||||||
|
// are handled by session.Run() and ImageBuild()
|
||||||
|
if err := addDirToSession(s, contextDir, progressOutput, syncDone); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
buf := newBufferedWriter(syncDone, buildBuff)
|
||||||
|
defer func() {
|
||||||
|
select {
|
||||||
|
case <-buf.flushed:
|
||||||
|
case <-ctx.Done():
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
buildBuff = buf
|
||||||
|
|
||||||
|
remote = clientSessionRemote
|
||||||
|
body = buildCtx
|
||||||
|
}
|
||||||
|
|
||||||
|
configFile := dockerCli.ConfigFile()
|
||||||
|
authConfigs, _ := configFile.GetAllCredentials()
|
||||||
buildOptions := types.ImageBuildOptions{
|
buildOptions := types.ImageBuildOptions{
|
||||||
Memory: options.memory.Value(),
|
Memory: options.memory.Value(),
|
||||||
MemorySwap: options.memorySwap.Value(),
|
MemorySwap: options.memorySwap.Value(),
|
||||||
|
@ -291,15 +366,28 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
|
||||||
Dockerfile: relDockerfile,
|
Dockerfile: relDockerfile,
|
||||||
ShmSize: options.shmSize.Value(),
|
ShmSize: options.shmSize.Value(),
|
||||||
Ulimits: options.ulimits.GetList(),
|
Ulimits: options.ulimits.GetList(),
|
||||||
BuildArgs: runconfigopts.ConvertKVStringsToMapWithNil(options.buildArgs.GetAll()),
|
BuildArgs: configFile.ParseProxyConfig(dockerCli.Client().DaemonHost(), options.buildArgs.GetAll()),
|
||||||
AuthConfigs: authConfigs,
|
AuthConfigs: authConfigs,
|
||||||
Labels: runconfigopts.ConvertKVStringsToMap(options.labels.GetAll()),
|
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()),
|
||||||
CacheFrom: options.cacheFrom,
|
CacheFrom: options.cacheFrom,
|
||||||
SecurityOpt: options.securityOpt,
|
SecurityOpt: options.securityOpt,
|
||||||
NetworkMode: options.networkMode,
|
NetworkMode: options.networkMode,
|
||||||
Squash: options.squash,
|
Squash: options.squash,
|
||||||
ExtraHosts: options.extraHosts.GetAll(),
|
ExtraHosts: options.extraHosts.GetAll(),
|
||||||
Target: options.target,
|
Target: options.target,
|
||||||
|
RemoteContext: remote,
|
||||||
|
Platform: options.platform,
|
||||||
|
}
|
||||||
|
|
||||||
|
if s != nil {
|
||||||
|
go func() {
|
||||||
|
logrus.Debugf("running session: %v", s.ID())
|
||||||
|
if err := s.Run(ctx, dockerCli.Client().DialSession); err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
cancel() // cancel progress context
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
buildOptions.SessionID = s.ID()
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := dockerCli.Client().ImageBuild(ctx, body, buildOptions)
|
response, err := dockerCli.Client().ImageBuild(ctx, body, buildOptions)
|
||||||
|
@ -307,6 +395,7 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
|
||||||
if options.quiet {
|
if options.quiet {
|
||||||
fmt.Fprintf(dockerCli.Err(), "%s", progBuff)
|
fmt.Fprintf(dockerCli.Err(), "%s", progBuff)
|
||||||
}
|
}
|
||||||
|
cancel()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
74
vendor/github.com/docker/cli/cli/command/image/build/context.go
generated
vendored
74
vendor/github.com/docker/cli/cli/command/image/build/context.go
generated
vendored
|
@ -1,25 +1,25 @@
|
||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/tar"
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"archive/tar"
|
|
||||||
"bytes"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/docker/builder/remotecontext/git"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/pkg/fileutils"
|
"github.com/docker/docker/pkg/fileutils"
|
||||||
"github.com/docker/docker/pkg/gitutils"
|
|
||||||
"github.com/docker/docker/pkg/httputils"
|
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
|
"github.com/docker/docker/pkg/pools"
|
||||||
"github.com/docker/docker/pkg/progress"
|
"github.com/docker/docker/pkg/progress"
|
||||||
"github.com/docker/docker/pkg/streamformatter"
|
"github.com/docker/docker/pkg/streamformatter"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
|
@ -29,6 +29,8 @@ import (
|
||||||
const (
|
const (
|
||||||
// DefaultDockerfileName is the Default filename with Docker commands, read by docker build
|
// DefaultDockerfileName is the Default filename with Docker commands, read by docker build
|
||||||
DefaultDockerfileName string = "Dockerfile"
|
DefaultDockerfileName string = "Dockerfile"
|
||||||
|
// archiveHeaderSize is the number of bytes in an archive header
|
||||||
|
archiveHeaderSize = 512
|
||||||
)
|
)
|
||||||
|
|
||||||
// ValidateContextDirectory checks if all the contents of the directory
|
// ValidateContextDirectory checks if all the contents of the directory
|
||||||
|
@ -85,12 +87,12 @@ func ValidateContextDirectory(srcPath string, excludes []string) error {
|
||||||
func GetContextFromReader(r io.ReadCloser, dockerfileName string) (out io.ReadCloser, relDockerfile string, err error) {
|
func GetContextFromReader(r io.ReadCloser, dockerfileName string) (out io.ReadCloser, relDockerfile string, err error) {
|
||||||
buf := bufio.NewReader(r)
|
buf := bufio.NewReader(r)
|
||||||
|
|
||||||
magic, err := buf.Peek(archive.HeaderSize)
|
magic, err := buf.Peek(archiveHeaderSize)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
return nil, "", errors.Errorf("failed to peek context header from STDIN: %v", err)
|
return nil, "", errors.Errorf("failed to peek context header from STDIN: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if archive.IsArchive(magic) {
|
if IsArchive(magic) {
|
||||||
return ioutils.NewReadCloserWrapper(buf, func() error { return r.Close() }), dockerfileName, nil
|
return ioutils.NewReadCloserWrapper(buf, func() error { return r.Close() }), dockerfileName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +136,18 @@ func GetContextFromReader(r io.ReadCloser, dockerfileName string) (out io.ReadCl
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsArchive checks for the magic bytes of a tar or any supported compression
|
||||||
|
// algorithm.
|
||||||
|
func IsArchive(header []byte) bool {
|
||||||
|
compression := archive.DetectCompression(header)
|
||||||
|
if compression != archive.Uncompressed {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
r := tar.NewReader(bytes.NewBuffer(header))
|
||||||
|
_, err := r.Next()
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetContextFromGitURL uses a Git URL as context for a `docker build`. The
|
// GetContextFromGitURL uses a Git URL as context for a `docker build`. The
|
||||||
// git repo is cloned into a temporary directory used as the context directory.
|
// git repo is cloned into a temporary directory used as the context directory.
|
||||||
// Returns the absolute path to the temporary context directory, the relative
|
// Returns the absolute path to the temporary context directory, the relative
|
||||||
|
@ -143,7 +157,7 @@ func GetContextFromGitURL(gitURL, dockerfileName string) (string, string, error)
|
||||||
if _, err := exec.LookPath("git"); err != nil {
|
if _, err := exec.LookPath("git"); err != nil {
|
||||||
return "", "", errors.Wrapf(err, "unable to find 'git'")
|
return "", "", errors.Wrapf(err, "unable to find 'git'")
|
||||||
}
|
}
|
||||||
absContextDir, err := gitutils.Clone(gitURL)
|
absContextDir, err := git.Clone(gitURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", errors.Wrapf(err, "unable to 'git clone' to temporary context directory")
|
return "", "", errors.Wrapf(err, "unable to 'git clone' to temporary context directory")
|
||||||
}
|
}
|
||||||
|
@ -161,7 +175,7 @@ func GetContextFromGitURL(gitURL, dockerfileName string) (string, string, error)
|
||||||
// Returns the tar archive used for the context and a path of the
|
// Returns the tar archive used for the context and a path of the
|
||||||
// dockerfile inside the tar.
|
// dockerfile inside the tar.
|
||||||
func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.ReadCloser, string, error) {
|
func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.ReadCloser, string, error) {
|
||||||
response, err := httputils.Download(remoteURL)
|
response, err := getWithStatusError(remoteURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", errors.Errorf("unable to download remote context %s: %v", remoteURL, err)
|
return nil, "", errors.Errorf("unable to download remote context %s: %v", remoteURL, err)
|
||||||
}
|
}
|
||||||
|
@ -173,6 +187,24 @@ func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.Read
|
||||||
return GetContextFromReader(ioutils.NewReadCloserWrapper(progReader, func() error { return response.Body.Close() }), dockerfileName)
|
return GetContextFromReader(ioutils.NewReadCloserWrapper(progReader, func() error { return response.Body.Close() }), dockerfileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getWithStatusError does an http.Get() and returns an error if the
|
||||||
|
// status code is 4xx or 5xx.
|
||||||
|
func getWithStatusError(url string) (resp *http.Response, err error) {
|
||||||
|
if resp, err = http.Get(url); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if resp.StatusCode < 400 {
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
msg := fmt.Sprintf("failed to GET %s with status %s", url, resp.Status)
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
resp.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, msg+": error reading body")
|
||||||
|
}
|
||||||
|
return nil, errors.Errorf(msg+": %s", bytes.TrimSpace(body))
|
||||||
|
}
|
||||||
|
|
||||||
// GetContextFromLocalDir uses the given local directory as context for a
|
// GetContextFromLocalDir uses the given local directory as context for a
|
||||||
// `docker build`. Returns the absolute path to the local context directory,
|
// `docker build`. Returns the absolute path to the local context directory,
|
||||||
// the relative path of the dockerfile in that context directory, and a non-nil
|
// the relative path of the dockerfile in that context directory, and a non-nil
|
||||||
|
@ -344,3 +376,27 @@ func AddDockerfileToBuildContext(dockerfileCtx io.ReadCloser, buildCtx io.ReadCl
|
||||||
})
|
})
|
||||||
return buildCtx, randomName, nil
|
return buildCtx, randomName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compress the build context for sending to the API
|
||||||
|
func Compress(buildCtx io.ReadCloser) (io.ReadCloser, error) {
|
||||||
|
pipeReader, pipeWriter := io.Pipe()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
compressWriter, err := archive.CompressStream(pipeWriter, archive.Gzip)
|
||||||
|
if err != nil {
|
||||||
|
pipeWriter.CloseWithError(err)
|
||||||
|
}
|
||||||
|
defer buildCtx.Close()
|
||||||
|
|
||||||
|
if _, err := pools.Copy(compressWriter, buildCtx); err != nil {
|
||||||
|
pipeWriter.CloseWithError(
|
||||||
|
errors.Wrap(err, "failed to compress context"))
|
||||||
|
compressWriter.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
compressWriter.Close()
|
||||||
|
pipeWriter.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
return pipeReader, nil
|
||||||
|
}
|
||||||
|
|
153
vendor/github.com/docker/cli/cli/command/image/build_session.go
generated
vendored
Normal file
153
vendor/github.com/docker/cli/cli/command/image/build_session.go
generated
vendored
Normal file
|
@ -0,0 +1,153 @@
|
||||||
|
package image
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/rand"
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/cli/cli/command"
|
||||||
|
"github.com/docker/cli/cli/command/image/build"
|
||||||
|
cliconfig "github.com/docker/cli/cli/config"
|
||||||
|
"github.com/docker/docker/api/types/versions"
|
||||||
|
"github.com/docker/docker/pkg/progress"
|
||||||
|
"github.com/moby/buildkit/session"
|
||||||
|
"github.com/moby/buildkit/session/filesync"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"golang.org/x/time/rate"
|
||||||
|
)
|
||||||
|
|
||||||
|
const clientSessionRemote = "client-session"
|
||||||
|
|
||||||
|
func isSessionSupported(dockerCli command.Cli) bool {
|
||||||
|
return dockerCli.ServerInfo().HasExperimental && versions.GreaterThanOrEqualTo(dockerCli.Client().ClientVersion(), "1.31")
|
||||||
|
}
|
||||||
|
|
||||||
|
func trySession(dockerCli command.Cli, contextDir string) (*session.Session, error) {
|
||||||
|
var s *session.Session
|
||||||
|
if isSessionSupported(dockerCli) {
|
||||||
|
sharedKey, err := getBuildSharedKey(contextDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "failed to get build shared key")
|
||||||
|
}
|
||||||
|
s, err = session.NewSession(filepath.Base(contextDir), sharedKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "failed to create session")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func addDirToSession(session *session.Session, contextDir string, progressOutput progress.Output, done chan error) error {
|
||||||
|
excludes, err := build.ReadDockerignore(contextDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
p := &sizeProgress{out: progressOutput, action: "Streaming build context to Docker daemon"}
|
||||||
|
|
||||||
|
workdirProvider := filesync.NewFSSyncProvider([]filesync.SyncedDir{
|
||||||
|
{Dir: contextDir, Excludes: excludes},
|
||||||
|
})
|
||||||
|
session.Allow(workdirProvider)
|
||||||
|
|
||||||
|
// this will be replaced on parallel build jobs. keep the current
|
||||||
|
// progressbar for now
|
||||||
|
if snpc, ok := workdirProvider.(interface {
|
||||||
|
SetNextProgressCallback(func(int, bool), chan error)
|
||||||
|
}); ok {
|
||||||
|
snpc.SetNextProgressCallback(p.update, done)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type sizeProgress struct {
|
||||||
|
out progress.Output
|
||||||
|
action string
|
||||||
|
limiter *rate.Limiter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sp *sizeProgress) update(size int, last bool) {
|
||||||
|
if sp.limiter == nil {
|
||||||
|
sp.limiter = rate.NewLimiter(rate.Every(100*time.Millisecond), 1)
|
||||||
|
}
|
||||||
|
if last || sp.limiter.Allow() {
|
||||||
|
sp.out.WriteProgress(progress.Progress{Action: sp.action, Current: int64(size), LastUpdate: last})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type bufferedWriter struct {
|
||||||
|
done chan error
|
||||||
|
io.Writer
|
||||||
|
buf *bytes.Buffer
|
||||||
|
flushed chan struct{}
|
||||||
|
mu sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func newBufferedWriter(done chan error, w io.Writer) *bufferedWriter {
|
||||||
|
bw := &bufferedWriter{done: done, Writer: w, buf: new(bytes.Buffer), flushed: make(chan struct{})}
|
||||||
|
go func() {
|
||||||
|
<-done
|
||||||
|
bw.flushBuffer()
|
||||||
|
}()
|
||||||
|
return bw
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bw *bufferedWriter) Write(dt []byte) (int, error) {
|
||||||
|
select {
|
||||||
|
case <-bw.done:
|
||||||
|
bw.flushBuffer()
|
||||||
|
return bw.Writer.Write(dt)
|
||||||
|
default:
|
||||||
|
return bw.buf.Write(dt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bw *bufferedWriter) flushBuffer() {
|
||||||
|
bw.mu.Lock()
|
||||||
|
select {
|
||||||
|
case <-bw.flushed:
|
||||||
|
default:
|
||||||
|
bw.Writer.Write(bw.buf.Bytes())
|
||||||
|
close(bw.flushed)
|
||||||
|
}
|
||||||
|
bw.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getBuildSharedKey(dir string) (string, error) {
|
||||||
|
// build session is hash of build dir with node based randomness
|
||||||
|
s := sha256.Sum256([]byte(fmt.Sprintf("%s:%s", tryNodeIdentifier(), dir)))
|
||||||
|
return hex.EncodeToString(s[:]), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func tryNodeIdentifier() string {
|
||||||
|
out := cliconfig.Dir() // return config dir as default on permission error
|
||||||
|
if err := os.MkdirAll(cliconfig.Dir(), 0700); err == nil {
|
||||||
|
sessionFile := filepath.Join(cliconfig.Dir(), ".buildNodeID")
|
||||||
|
if _, err := os.Lstat(sessionFile); err != nil {
|
||||||
|
if os.IsNotExist(err) { // create a new file with stored randomness
|
||||||
|
b := make([]byte, 32)
|
||||||
|
if _, err := rand.Read(b); err != nil {
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(sessionFile, []byte(hex.EncodeToString(b)), 0600); err != nil {
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dt, err := ioutil.ReadFile(sessionFile)
|
||||||
|
if err == nil {
|
||||||
|
return string(dt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
3
vendor/github.com/docker/cli/cli/command/image/cmd.go
generated
vendored
3
vendor/github.com/docker/cli/cli/command/image/cmd.go
generated
vendored
|
@ -8,8 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewImageCommand returns a cobra command for `image` subcommands
|
// NewImageCommand returns a cobra command for `image` subcommands
|
||||||
// nolint: interfacer
|
func NewImageCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
func NewImageCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "image",
|
Use: "image",
|
||||||
Short: "Manage images",
|
Short: "Manage images",
|
||||||
|
|
8
vendor/github.com/docker/cli/cli/command/image/prune.go
generated
vendored
8
vendor/github.com/docker/cli/cli/command/image/prune.go
generated
vendored
|
@ -37,7 +37,7 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
|
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Tags: map[string]string{"version": "1.25"},
|
Annotations: map[string]string{"version": "1.25"},
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
@ -65,12 +65,12 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
|
||||||
warning = allImageWarning
|
warning = allImageWarning
|
||||||
}
|
}
|
||||||
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
|
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
|
||||||
return
|
return 0, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
report, err := dockerCli.Client().ImagesPrune(context.Background(), pruneFilters)
|
report, err := dockerCli.Client().ImagesPrune(context.Background(), pruneFilters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return 0, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(report.ImagesDeleted) > 0 {
|
if len(report.ImagesDeleted) > 0 {
|
||||||
|
@ -85,7 +85,7 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
|
||||||
spaceReclaimed = report.SpaceReclaimed
|
spaceReclaimed = report.SpaceReclaimed
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return spaceReclaimed, output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunPrune calls the Image Prune API
|
// RunPrune calls the Image Prune API
|
||||||
|
|
37
vendor/github.com/docker/cli/cli/command/image/pull.go
generated
vendored
37
vendor/github.com/docker/cli/cli/command/image/pull.go
generated
vendored
|
@ -6,16 +6,17 @@ import (
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
|
"github.com/docker/cli/cli/trust"
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/docker/registry"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
type pullOptions struct {
|
type pullOptions struct {
|
||||||
remote string
|
remote string
|
||||||
all bool
|
all bool
|
||||||
|
platform string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPullCommand creates a new `docker pull` command
|
// NewPullCommand creates a new `docker pull` command
|
||||||
|
@ -35,44 +36,39 @@ func NewPullCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
|
||||||
flags.BoolVarP(&opts.all, "all-tags", "a", false, "Download all tagged images in the repository")
|
flags.BoolVarP(&opts.all, "all-tags", "a", false, "Download all tagged images in the repository")
|
||||||
|
|
||||||
|
command.AddPlatformFlag(flags, &opts.platform)
|
||||||
command.AddTrustVerificationFlags(flags)
|
command.AddTrustVerificationFlags(flags)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func runPull(dockerCli command.Cli, opts pullOptions) error {
|
func runPull(cli command.Cli, opts pullOptions) error {
|
||||||
distributionRef, err := reference.ParseNormalizedNamed(opts.remote)
|
distributionRef, err := reference.ParseNormalizedNamed(opts.remote)
|
||||||
if err != nil {
|
switch {
|
||||||
|
case err != nil:
|
||||||
return err
|
return err
|
||||||
}
|
case opts.all && !reference.IsNameOnly(distributionRef):
|
||||||
if opts.all && !reference.IsNameOnly(distributionRef) {
|
|
||||||
return errors.New("tag can't be used with --all-tags/-a")
|
return errors.New("tag can't be used with --all-tags/-a")
|
||||||
}
|
case !opts.all && reference.IsNameOnly(distributionRef):
|
||||||
|
|
||||||
if !opts.all && reference.IsNameOnly(distributionRef) {
|
|
||||||
distributionRef = reference.TagNameOnly(distributionRef)
|
distributionRef = reference.TagNameOnly(distributionRef)
|
||||||
if tagged, ok := distributionRef.(reference.Tagged); ok {
|
if tagged, ok := distributionRef.(reference.Tagged); ok {
|
||||||
fmt.Fprintf(dockerCli.Out(), "Using default tag: %s\n", tagged.Tag())
|
fmt.Fprintf(cli.Out(), "Using default tag: %s\n", tagged.Tag())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve the Repository name from fqn to RepositoryInfo
|
ctx := context.Background()
|
||||||
repoInfo, err := registry.ParseRepositoryInfo(distributionRef)
|
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, AuthResolver(cli), distributionRef.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index)
|
|
||||||
requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(dockerCli, repoInfo.Index, "pull")
|
|
||||||
|
|
||||||
// Check if reference has a digest
|
// Check if reference has a digest
|
||||||
_, isCanonical := distributionRef.(reference.Canonical)
|
_, isCanonical := distributionRef.(reference.Canonical)
|
||||||
if command.IsTrusted() && !isCanonical {
|
if command.IsTrusted() && !isCanonical {
|
||||||
err = trustedPull(ctx, dockerCli, repoInfo, distributionRef, authConfig, requestPrivilege)
|
err = trustedPull(ctx, cli, imgRefAndAuth, opts.platform)
|
||||||
} else {
|
} else {
|
||||||
err = imagePullPrivileged(ctx, dockerCli, authConfig, reference.FamiliarString(distributionRef), requestPrivilege, opts.all)
|
err = imagePullPrivileged(ctx, cli, imgRefAndAuth, opts.all, opts.platform)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "when fetching 'plugin'") {
|
if strings.Contains(err.Error(), "when fetching 'plugin'") {
|
||||||
|
@ -80,6 +76,5 @@ func runPull(dockerCli command.Cli, opts pullOptions) error {
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
2
vendor/github.com/docker/cli/cli/command/image/push.go
generated
vendored
2
vendor/github.com/docker/cli/cli/command/image/push.go
generated
vendored
|
@ -48,7 +48,7 @@ func runPush(dockerCli command.Cli, remote string) error {
|
||||||
requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(dockerCli, repoInfo.Index, "push")
|
requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(dockerCli, repoInfo.Index, "push")
|
||||||
|
|
||||||
if command.IsTrusted() {
|
if command.IsTrusted() {
|
||||||
return trustedPush(ctx, dockerCli, repoInfo, ref, authConfig, requestPrivilege)
|
return TrustedPush(ctx, dockerCli, repoInfo, ref, authConfig, requestPrivilege)
|
||||||
}
|
}
|
||||||
|
|
||||||
responseBody, err := imagePushPrivileged(ctx, dockerCli, authConfig, ref, requestPrivilege)
|
responseBody, err := imagePushPrivileged(ctx, dockerCli, authConfig, ref, requestPrivilege)
|
||||||
|
|
15
vendor/github.com/docker/cli/cli/command/image/remove.go
generated
vendored
15
vendor/github.com/docker/cli/cli/command/image/remove.go
generated
vendored
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
apiclient "github.com/docker/docker/client"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -56,9 +57,13 @@ func runRemove(dockerCli command.Cli, opts removeOptions, images []string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
var errs []string
|
var errs []string
|
||||||
for _, image := range images {
|
var fatalErr = false
|
||||||
dels, err := client.ImageRemove(ctx, image, options)
|
for _, img := range images {
|
||||||
|
dels, err := client.ImageRemove(ctx, img, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if !apiclient.IsErrNotFound(err) {
|
||||||
|
fatalErr = true
|
||||||
|
}
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
} else {
|
} else {
|
||||||
for _, del := range dels {
|
for _, del := range dels {
|
||||||
|
@ -72,7 +77,11 @@ func runRemove(dockerCli command.Cli, opts removeOptions, images []string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
return errors.Errorf("%s", strings.Join(errs, "\n"))
|
msg := strings.Join(errs, "\n")
|
||||||
|
if !opts.force || fatalErr {
|
||||||
|
return errors.New(msg)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(dockerCli.Err(), msg)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
16
vendor/github.com/docker/cli/cli/command/image/save.go
generated
vendored
16
vendor/github.com/docker/cli/cli/command/image/save.go
generated
vendored
|
@ -2,6 +2,8 @@ package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
|
@ -41,6 +43,10 @@ func runSave(dockerCli command.Cli, opts saveOptions) error {
|
||||||
return errors.New("cowardly refusing to save to a terminal. Use the -o flag or redirect")
|
return errors.New("cowardly refusing to save to a terminal. Use the -o flag or redirect")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := validateOutputPath(opts.output); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to save image")
|
||||||
|
}
|
||||||
|
|
||||||
responseBody, err := dockerCli.Client().ImageSave(context.Background(), opts.images)
|
responseBody, err := dockerCli.Client().ImageSave(context.Background(), opts.images)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -54,3 +60,13 @@ func runSave(dockerCli command.Cli, opts saveOptions) error {
|
||||||
|
|
||||||
return command.CopyToFile(opts.output, responseBody)
|
return command.CopyToFile(opts.output, responseBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateOutputPath(path string) error {
|
||||||
|
dir := filepath.Dir(path)
|
||||||
|
if dir != "" && dir != "." {
|
||||||
|
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||||
|
return errors.Errorf("unable to validate output path: directory %q does not exist", dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
209
vendor/github.com/docker/cli/cli/command/image/trust.go
generated
vendored
209
vendor/github.com/docker/cli/cli/command/image/trust.go
generated
vendored
|
@ -5,20 +5,20 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"path"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/cli/cli/trust"
|
"github.com/docker/cli/cli/trust"
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
registrytypes "github.com/docker/docker/api/types/registry"
|
||||||
"github.com/docker/docker/pkg/jsonmessage"
|
"github.com/docker/docker/pkg/jsonmessage"
|
||||||
"github.com/docker/docker/registry"
|
"github.com/docker/docker/registry"
|
||||||
"github.com/docker/notary/client"
|
digest "github.com/opencontainers/go-digest"
|
||||||
"github.com/docker/notary/tuf/data"
|
|
||||||
"github.com/opencontainers/go-digest"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/theupdateframework/notary/client"
|
||||||
|
"github.com/theupdateframework/notary/tuf/data"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ type target struct {
|
||||||
size int64
|
size int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// trustedPush handles content trust pushing of an image
|
// TrustedPush handles content trust pushing of an image
|
||||||
func trustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, requestPrivilege types.RequestPrivilegeFunc) error {
|
func TrustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, requestPrivilege types.RequestPrivilegeFunc) error {
|
||||||
responseBody, err := imagePushPrivileged(ctx, cli, authConfig, ref, requestPrivilege)
|
responseBody, err := imagePushPrivileged(ctx, cli, authConfig, ref, requestPrivilege)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -84,7 +84,7 @@ func PushTrustedReference(streams command.Streams, repoInfo *registry.Repository
|
||||||
if err := jsonmessage.DisplayJSONMessagesToStream(in, streams.Out(), nil); err != nil {
|
if err := jsonmessage.DisplayJSONMessagesToStream(in, streams.Out(), nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintln(streams.Out(), "No tag specified, skipping trust metadata push")
|
fmt.Fprintln(streams.Err(), "No tag specified, skipping trust metadata push")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,31 +97,29 @@ func PushTrustedReference(streams command.Streams, repoInfo *registry.Repository
|
||||||
}
|
}
|
||||||
|
|
||||||
if target == nil {
|
if target == nil {
|
||||||
fmt.Fprintln(streams.Out(), "No targets found, please provide a specific tag in order to sign it")
|
return errors.Errorf("no targets found, please provide a specific tag in order to sign it")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintln(streams.Out(), "Signing and pushing trust metadata")
|
fmt.Fprintln(streams.Out(), "Signing and pushing trust metadata")
|
||||||
|
|
||||||
repo, err := trust.GetNotaryRepository(streams, repoInfo, authConfig, "push", "pull")
|
repo, err := trust.GetNotaryRepository(streams.In(), streams.Out(), command.UserAgent(), repoInfo, &authConfig, "push", "pull")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(streams.Out(), "Error establishing connection to notary repository: %s\n", err)
|
return errors.Wrap(err, "error establishing connection to trust repository")
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the latest repository metadata so we can figure out which roles to sign
|
// get the latest repository metadata so we can figure out which roles to sign
|
||||||
err = repo.Update(false)
|
_, err = repo.ListTargets()
|
||||||
|
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case client.ErrRepoNotInitialized, client.ErrRepositoryNotExist:
|
case client.ErrRepoNotInitialized, client.ErrRepositoryNotExist:
|
||||||
keys := repo.CryptoService.ListKeys(data.CanonicalRootRole)
|
keys := repo.GetCryptoService().ListKeys(data.CanonicalRootRole)
|
||||||
var rootKeyID string
|
var rootKeyID string
|
||||||
// always select the first root key
|
// always select the first root key
|
||||||
if len(keys) > 0 {
|
if len(keys) > 0 {
|
||||||
sort.Strings(keys)
|
sort.Strings(keys)
|
||||||
rootKeyID = keys[0]
|
rootKeyID = keys[0]
|
||||||
} else {
|
} else {
|
||||||
rootPublicKey, err := repo.CryptoService.Create(data.CanonicalRootRole, "", data.ECDSAKey)
|
rootPublicKey, err := repo.GetCryptoService().Create(data.CanonicalRootRole, "", data.ECDSAKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -136,7 +134,7 @@ func PushTrustedReference(streams command.Streams, repoInfo *registry.Repository
|
||||||
err = repo.AddTarget(target, data.CanonicalTargetsRole)
|
err = repo.AddTarget(target, data.CanonicalTargetsRole)
|
||||||
case nil:
|
case nil:
|
||||||
// already initialized and we have successfully downloaded the latest metadata
|
// already initialized and we have successfully downloaded the latest metadata
|
||||||
err = addTargetToAllSignableRoles(repo, target)
|
err = AddTargetToAllSignableRoles(repo, target)
|
||||||
default:
|
default:
|
||||||
return trust.NotaryError(repoInfo.Name.Name(), err)
|
return trust.NotaryError(repoInfo.Name.Name(), err)
|
||||||
}
|
}
|
||||||
|
@ -146,59 +144,24 @@ func PushTrustedReference(streams command.Streams, repoInfo *registry.Repository
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(streams.Out(), "Failed to sign %q:%s - %s\n", repoInfo.Name.Name(), tag, err.Error())
|
err = errors.Wrapf(err, "failed to sign %s:%s", repoInfo.Name.Name(), tag)
|
||||||
return trust.NotaryError(repoInfo.Name.Name(), err)
|
return trust.NotaryError(repoInfo.Name.Name(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(streams.Out(), "Successfully signed %q:%s\n", repoInfo.Name.Name(), tag)
|
fmt.Fprintf(streams.Out(), "Successfully signed %s:%s\n", repoInfo.Name.Name(), tag)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to add the image target to all the top level delegation roles we can
|
// AddTargetToAllSignableRoles attempts to add the image target to all the top level delegation roles we can
|
||||||
// (based on whether we have the signing key and whether the role's path allows
|
// (based on whether we have the signing key and whether the role's path allows
|
||||||
// us to).
|
// us to).
|
||||||
// If there are no delegation roles, we add to the targets role.
|
// If there are no delegation roles, we add to the targets role.
|
||||||
func addTargetToAllSignableRoles(repo *client.NotaryRepository, target *client.Target) error {
|
func AddTargetToAllSignableRoles(repo client.Repository, target *client.Target) error {
|
||||||
var signableRoles []string
|
signableRoles, err := trust.GetSignableRoles(repo, target)
|
||||||
|
|
||||||
// translate the full key names, which includes the GUN, into just the key IDs
|
|
||||||
allCanonicalKeyIDs := make(map[string]struct{})
|
|
||||||
for fullKeyID := range repo.CryptoService.ListAllKeys() {
|
|
||||||
allCanonicalKeyIDs[path.Base(fullKeyID)] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
allDelegationRoles, err := repo.GetDelegationRoles()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there are no delegation roles, then just try to sign it into the targets role
|
|
||||||
if len(allDelegationRoles) == 0 {
|
|
||||||
return repo.AddTarget(target, data.CanonicalTargetsRole)
|
|
||||||
}
|
|
||||||
|
|
||||||
// there are delegation roles, find every delegation role we have a key for, and
|
|
||||||
// attempt to sign into into all those roles.
|
|
||||||
for _, delegationRole := range allDelegationRoles {
|
|
||||||
// We do not support signing any delegation role that isn't a direct child of the targets role.
|
|
||||||
// Also don't bother checking the keys if we can't add the target
|
|
||||||
// to this role due to path restrictions
|
|
||||||
if path.Dir(delegationRole.Name) != data.CanonicalTargetsRole || !delegationRole.CheckPaths(target.Name) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, canonicalKeyID := range delegationRole.KeyIDs {
|
|
||||||
if _, ok := allCanonicalKeyIDs[canonicalKeyID]; ok {
|
|
||||||
signableRoles = append(signableRoles, delegationRole.Name)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(signableRoles) == 0 {
|
|
||||||
return errors.Errorf("no valid signing keys for delegation roles")
|
|
||||||
}
|
|
||||||
|
|
||||||
return repo.AddTarget(target, signableRoles...)
|
return repo.AddTarget(target, signableRoles...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,57 +180,13 @@ func imagePushPrivileged(ctx context.Context, cli command.Cli, authConfig types.
|
||||||
}
|
}
|
||||||
|
|
||||||
// trustedPull handles content trust pulling of an image
|
// trustedPull handles content trust pulling of an image
|
||||||
func trustedPull(ctx context.Context, cli command.Cli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, requestPrivilege types.RequestPrivilegeFunc) error {
|
func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth, platform string) error {
|
||||||
var refs []target
|
refs, err := getTrustedPullTargets(cli, imgRefAndAuth)
|
||||||
|
|
||||||
notaryRepo, err := trust.GetNotaryRepository(cli, repoInfo, authConfig, "pull")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(cli.Out(), "Error establishing connection to trust repository: %s\n", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if tagged, isTagged := ref.(reference.NamedTagged); !isTagged {
|
ref := imgRefAndAuth.Reference()
|
||||||
// List all targets
|
|
||||||
targets, err := notaryRepo.ListTargets(trust.ReleasesRole, data.CanonicalTargetsRole)
|
|
||||||
if err != nil {
|
|
||||||
return trust.NotaryError(ref.Name(), err)
|
|
||||||
}
|
|
||||||
for _, tgt := range targets {
|
|
||||||
t, err := convertTarget(tgt.Target)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(cli.Out(), "Skipping target for %q\n", reference.FamiliarName(ref))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Only list tags in the top level targets role or the releases delegation role - ignore
|
|
||||||
// all other delegation roles
|
|
||||||
if tgt.Role != trust.ReleasesRole && tgt.Role != data.CanonicalTargetsRole {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
refs = append(refs, t)
|
|
||||||
}
|
|
||||||
if len(refs) == 0 {
|
|
||||||
return trust.NotaryError(ref.Name(), errors.Errorf("No trusted tags for %s", ref.Name()))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t, err := notaryRepo.GetTargetByName(tagged.Tag(), trust.ReleasesRole, data.CanonicalTargetsRole)
|
|
||||||
if err != nil {
|
|
||||||
return trust.NotaryError(ref.Name(), err)
|
|
||||||
}
|
|
||||||
// Only get the tag if it's in the top level targets role or the releases delegation role
|
|
||||||
// ignore it if it's in any other delegation roles
|
|
||||||
if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole {
|
|
||||||
return trust.NotaryError(ref.Name(), errors.Errorf("No trust data for %s", tagged.Tag()))
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Debugf("retrieving target for %s role\n", t.Role)
|
|
||||||
r, err := convertTarget(t.Target)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
|
|
||||||
}
|
|
||||||
refs = append(refs, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, r := range refs {
|
for i, r := range refs {
|
||||||
displayTag := r.name
|
displayTag := r.name
|
||||||
if displayTag != "" {
|
if displayTag != "" {
|
||||||
|
@ -279,7 +198,11 @@ func trustedPull(ctx context.Context, cli command.Cli, repoInfo *registry.Reposi
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := imagePullPrivileged(ctx, cli, authConfig, reference.FamiliarString(trustedRef), requestPrivilege, false); err != nil {
|
updatedImgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, AuthResolver(cli), trustedRef.String())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := imagePullPrivileged(ctx, cli, updatedImgRefAndAuth, false, platform); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,19 +218,70 @@ func trustedPull(ctx context.Context, cli command.Cli, repoInfo *registry.Reposi
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// imagePullPrivileged pulls the image and displays it to the output
|
func getTrustedPullTargets(cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth) ([]target, error) {
|
||||||
func imagePullPrivileged(ctx context.Context, cli command.Cli, authConfig types.AuthConfig, ref string, requestPrivilege types.RequestPrivilegeFunc, all bool) error {
|
notaryRepo, err := cli.NotaryClient(imgRefAndAuth, trust.ActionsPullOnly)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "error establishing connection to trust repository")
|
||||||
|
}
|
||||||
|
|
||||||
encodedAuth, err := command.EncodeAuthToBase64(authConfig)
|
ref := imgRefAndAuth.Reference()
|
||||||
|
tagged, isTagged := ref.(reference.NamedTagged)
|
||||||
|
if !isTagged {
|
||||||
|
// List all targets
|
||||||
|
targets, err := notaryRepo.ListTargets(trust.ReleasesRole, data.CanonicalTargetsRole)
|
||||||
|
if err != nil {
|
||||||
|
return nil, trust.NotaryError(ref.Name(), err)
|
||||||
|
}
|
||||||
|
var refs []target
|
||||||
|
for _, tgt := range targets {
|
||||||
|
t, err := convertTarget(tgt.Target)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(cli.Err(), "Skipping target for %q\n", reference.FamiliarName(ref))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Only list tags in the top level targets role or the releases delegation role - ignore
|
||||||
|
// all other delegation roles
|
||||||
|
if tgt.Role != trust.ReleasesRole && tgt.Role != data.CanonicalTargetsRole {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
refs = append(refs, t)
|
||||||
|
}
|
||||||
|
if len(refs) == 0 {
|
||||||
|
return nil, trust.NotaryError(ref.Name(), errors.Errorf("No trusted tags for %s", ref.Name()))
|
||||||
|
}
|
||||||
|
return refs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
t, err := notaryRepo.GetTargetByName(tagged.Tag(), trust.ReleasesRole, data.CanonicalTargetsRole)
|
||||||
|
if err != nil {
|
||||||
|
return nil, trust.NotaryError(ref.Name(), err)
|
||||||
|
}
|
||||||
|
// Only get the tag if it's in the top level targets role or the releases delegation role
|
||||||
|
// ignore it if it's in any other delegation roles
|
||||||
|
if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole {
|
||||||
|
return nil, trust.NotaryError(ref.Name(), errors.Errorf("No trust data for %s", tagged.Tag()))
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Debugf("retrieving target for %s role", t.Role)
|
||||||
|
r, err := convertTarget(t.Target)
|
||||||
|
return []target{r}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// imagePullPrivileged pulls the image and displays it to the output
|
||||||
|
func imagePullPrivileged(ctx context.Context, cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth, all bool, platform string) error {
|
||||||
|
ref := reference.FamiliarString(imgRefAndAuth.Reference())
|
||||||
|
|
||||||
|
encodedAuth, err := command.EncodeAuthToBase64(*imgRefAndAuth.AuthConfig())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(cli, imgRefAndAuth.RepoInfo().Index, "pull")
|
||||||
options := types.ImagePullOptions{
|
options := types.ImagePullOptions{
|
||||||
RegistryAuth: encodedAuth,
|
RegistryAuth: encodedAuth,
|
||||||
PrivilegeFunc: requestPrivilege,
|
PrivilegeFunc: requestPrivilege,
|
||||||
All: all,
|
All: all,
|
||||||
|
Platform: platform,
|
||||||
}
|
}
|
||||||
|
|
||||||
responseBody, err := cli.Client().ImagePull(ctx, ref, options)
|
responseBody, err := cli.Client().ImagePull(ctx, ref, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -335,10 +309,9 @@ func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedT
|
||||||
// Resolve the Auth config relevant for this server
|
// Resolve the Auth config relevant for this server
|
||||||
authConfig := command.ResolveAuthConfig(ctx, cli, repoInfo.Index)
|
authConfig := command.ResolveAuthConfig(ctx, cli, repoInfo.Index)
|
||||||
|
|
||||||
notaryRepo, err := trust.GetNotaryRepository(cli, repoInfo, authConfig, "pull")
|
notaryRepo, err := trust.GetNotaryRepository(cli.In(), cli.Out(), command.UserAgent(), repoInfo, &authConfig, "pull")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(cli.Out(), "Error establishing connection to trust repository: %s\n", err)
|
return nil, errors.Wrap(err, "error establishing connection to trust repository")
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := notaryRepo.GetTargetByName(ref.Tag(), trust.ReleasesRole, data.CanonicalTargetsRole)
|
t, err := notaryRepo.GetTargetByName(ref.Tag(), trust.ReleasesRole, data.CanonicalTargetsRole)
|
||||||
|
@ -348,14 +321,13 @@ func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedT
|
||||||
// Only list tags in the top level targets role or the releases delegation role - ignore
|
// Only list tags in the top level targets role or the releases delegation role - ignore
|
||||||
// all other delegation roles
|
// all other delegation roles
|
||||||
if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole {
|
if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole {
|
||||||
return nil, trust.NotaryError(repoInfo.Name.Name(), errors.Errorf("No trust data for %s", ref.Tag()))
|
return nil, trust.NotaryError(repoInfo.Name.Name(), client.ErrNoSuchTarget(ref.Tag()))
|
||||||
}
|
}
|
||||||
r, err := convertTarget(t.Target)
|
r, err := convertTarget(t.Target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return reference.WithDigest(reference.TrimNamed(ref), r.digest)
|
return reference.WithDigest(reference.TrimNamed(ref), r.digest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,7 +350,14 @@ func TagTrusted(ctx context.Context, cli command.Cli, trustedRef reference.Canon
|
||||||
familiarRef := reference.FamiliarString(ref)
|
familiarRef := reference.FamiliarString(ref)
|
||||||
trustedFamiliarRef := reference.FamiliarString(trustedRef)
|
trustedFamiliarRef := reference.FamiliarString(trustedRef)
|
||||||
|
|
||||||
fmt.Fprintf(cli.Out(), "Tagging %s as %s\n", trustedFamiliarRef, familiarRef)
|
fmt.Fprintf(cli.Err(), "Tagging %s as %s\n", trustedFamiliarRef, familiarRef)
|
||||||
|
|
||||||
return cli.Client().ImageTag(ctx, trustedFamiliarRef, familiarRef)
|
return cli.Client().ImageTag(ctx, trustedFamiliarRef, familiarRef)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuthResolver returns an auth resolver function from a command.Cli
|
||||||
|
func AuthResolver(cli command.Cli) func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
|
||||||
|
return func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
|
||||||
|
return command.ResolveAuthConfig(ctx, cli, index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
2
vendor/github.com/docker/cli/cli/command/out.go
generated
vendored
2
vendor/github.com/docker/cli/cli/command/out.go
generated
vendored
|
@ -4,8 +4,8 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"github.com/docker/docker/pkg/term"
|
"github.com/docker/docker/pkg/term"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// OutStream is an output stream used by the DockerCli to write normal program
|
// OutStream is an output stream used by the DockerCli to write normal program
|
||||||
|
|
4
vendor/github.com/docker/cli/cli/command/registry.go
generated
vendored
4
vendor/github.com/docker/cli/cli/command/registry.go
generated
vendored
|
@ -70,7 +70,7 @@ func ResolveAuthConfig(ctx context.Context, cli Cli, index *registrytypes.IndexI
|
||||||
configKey = ElectAuthServer(ctx, cli)
|
configKey = ElectAuthServer(ctx, cli)
|
||||||
}
|
}
|
||||||
|
|
||||||
a, _ := cli.CredentialsStore(configKey).Get(configKey)
|
a, _ := cli.ConfigFile().GetAuthConfig(configKey)
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ func ConfigureAuth(cli Cli, flUser, flPassword, serverAddress string, isDefaultR
|
||||||
serverAddress = registry.ConvertToHostname(serverAddress)
|
serverAddress = registry.ConvertToHostname(serverAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
authconfig, err := cli.CredentialsStore(serverAddress).Get(serverAddress)
|
authconfig, err := cli.ConfigFile().GetAuthConfig(serverAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return authconfig, err
|
return authconfig, err
|
||||||
}
|
}
|
||||||
|
|
4
vendor/github.com/docker/cli/cli/command/trust.go
generated
vendored
4
vendor/github.com/docker/cli/cli/command/trust.go
generated
vendored
|
@ -12,6 +12,10 @@ var (
|
||||||
untrusted bool
|
untrusted bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
untrusted = !getDefaultTrustState()
|
||||||
|
}
|
||||||
|
|
||||||
// AddTrustVerificationFlags adds content trust flags to the provided flagset
|
// AddTrustVerificationFlags adds content trust flags to the provided flagset
|
||||||
func AddTrustVerificationFlags(fs *pflag.FlagSet) {
|
func AddTrustVerificationFlags(fs *pflag.FlagSet) {
|
||||||
trusted := getDefaultTrustState()
|
trusted := getDefaultTrustState()
|
||||||
|
|
8
vendor/github.com/docker/cli/cli/command/utils.go
generated
vendored
8
vendor/github.com/docker/cli/cli/command/utils.go
generated
vendored
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/pkg/system"
|
"github.com/docker/docker/pkg/system"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CopyToFile writes the content of the reader to the specified file
|
// CopyToFile writes the content of the reader to the specified file
|
||||||
|
@ -117,3 +118,10 @@ func PruneFilters(dockerCli Cli, pruneFilters filters.Args) filters.Args {
|
||||||
|
|
||||||
return pruneFilters
|
return pruneFilters
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddPlatformFlag adds `platform` to a set of flags for API version 1.32 and later.
|
||||||
|
func AddPlatformFlag(flags *pflag.FlagSet, target *string) {
|
||||||
|
flags.StringVar(target, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
|
||||||
|
flags.SetAnnotation("platform", "version", []string{"1.32"})
|
||||||
|
flags.SetAnnotation("platform", "experimental", nil)
|
||||||
|
}
|
||||||
|
|
54
vendor/github.com/docker/cli/cli/config/config.go
generated
vendored
54
vendor/github.com/docker/cli/cli/config/config.go
generated
vendored
|
@ -1,11 +1,13 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/docker/cli/cli/config/configfile"
|
"github.com/docker/cli/cli/config/configfile"
|
||||||
|
"github.com/docker/cli/cli/config/credentials"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/pkg/homedir"
|
"github.com/docker/docker/pkg/homedir"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -38,15 +40,6 @@ func SetDir(dir string) {
|
||||||
configDir = dir
|
configDir = dir
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfigFile initializes an empty configuration file for the given filename 'fn'
|
|
||||||
func NewConfigFile(fn string) *configfile.ConfigFile {
|
|
||||||
return &configfile.ConfigFile{
|
|
||||||
AuthConfigs: make(map[string]types.AuthConfig),
|
|
||||||
HTTPHeaders: make(map[string]string),
|
|
||||||
Filename: fn,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// LegacyLoadFromReader is a convenience function that creates a ConfigFile object from
|
// LegacyLoadFromReader is a convenience function that creates a ConfigFile object from
|
||||||
// a non-nested reader
|
// a non-nested reader
|
||||||
func LegacyLoadFromReader(configData io.Reader) (*configfile.ConfigFile, error) {
|
func LegacyLoadFromReader(configData io.Reader) (*configfile.ConfigFile, error) {
|
||||||
|
@ -75,46 +68,53 @@ func Load(configDir string) (*configfile.ConfigFile, error) {
|
||||||
configDir = Dir()
|
configDir = Dir()
|
||||||
}
|
}
|
||||||
|
|
||||||
configFile := configfile.ConfigFile{
|
filename := filepath.Join(configDir, ConfigFileName)
|
||||||
AuthConfigs: make(map[string]types.AuthConfig),
|
configFile := configfile.New(filename)
|
||||||
Filename: filepath.Join(configDir, ConfigFileName),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try happy path first - latest config file
|
// Try happy path first - latest config file
|
||||||
if _, err := os.Stat(configFile.Filename); err == nil {
|
if _, err := os.Stat(filename); err == nil {
|
||||||
file, err := os.Open(configFile.Filename)
|
file, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &configFile, errors.Errorf("%s - %v", configFile.Filename, err)
|
return configFile, errors.Errorf("%s - %v", filename, err)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
err = configFile.LoadFromReader(file)
|
err = configFile.LoadFromReader(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Errorf("%s - %v", configFile.Filename, err)
|
err = errors.Errorf("%s - %v", filename, err)
|
||||||
}
|
}
|
||||||
return &configFile, err
|
return configFile, err
|
||||||
} else if !os.IsNotExist(err) {
|
} else if !os.IsNotExist(err) {
|
||||||
// if file is there but we can't stat it for any reason other
|
// if file is there but we can't stat it for any reason other
|
||||||
// than it doesn't exist then stop
|
// than it doesn't exist then stop
|
||||||
return &configFile, errors.Errorf("%s - %v", configFile.Filename, err)
|
return configFile, errors.Errorf("%s - %v", filename, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't find latest config file so check for the old one
|
// Can't find latest config file so check for the old one
|
||||||
confFile := filepath.Join(homedir.Get(), oldConfigfile)
|
confFile := filepath.Join(homedir.Get(), oldConfigfile)
|
||||||
if _, err := os.Stat(confFile); err != nil {
|
if _, err := os.Stat(confFile); err != nil {
|
||||||
return &configFile, nil //missing file is not an error
|
return configFile, nil //missing file is not an error
|
||||||
}
|
}
|
||||||
file, err := os.Open(confFile)
|
file, err := os.Open(confFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &configFile, errors.Errorf("%s - %v", confFile, err)
|
return configFile, errors.Errorf("%s - %v", confFile, err)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
err = configFile.LegacyLoadFromReader(file)
|
err = configFile.LegacyLoadFromReader(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &configFile, errors.Errorf("%s - %v", confFile, err)
|
return configFile, errors.Errorf("%s - %v", confFile, err)
|
||||||
}
|
}
|
||||||
|
return configFile, nil
|
||||||
if configFile.HTTPHeaders == nil {
|
}
|
||||||
configFile.HTTPHeaders = map[string]string{}
|
|
||||||
}
|
// LoadDefaultConfigFile attempts to load the default config file and returns
|
||||||
return &configFile, nil
|
// an initialized ConfigFile struct if none is found.
|
||||||
|
func LoadDefaultConfigFile(stderr io.Writer) *configfile.ConfigFile {
|
||||||
|
configFile, err := Load(Dir())
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(stderr, "WARNING: Error loading config file: %v\n", err)
|
||||||
|
}
|
||||||
|
if !configFile.ContainsAuth() {
|
||||||
|
configFile.CredentialsStore = credentials.DetectDefaultStore(configFile.CredentialsStore)
|
||||||
|
}
|
||||||
|
return configFile
|
||||||
}
|
}
|
||||||
|
|
111
vendor/github.com/docker/cli/cli/config/configfile/file.go
generated
vendored
111
vendor/github.com/docker/cli/cli/config/configfile/file.go
generated
vendored
|
@ -9,6 +9,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/cli/cli/config/credentials"
|
||||||
|
"github.com/docker/cli/opts"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
@ -41,6 +43,24 @@ type ConfigFile struct {
|
||||||
ConfigFormat string `json:"configFormat,omitempty"`
|
ConfigFormat string `json:"configFormat,omitempty"`
|
||||||
NodesFormat string `json:"nodesFormat,omitempty"`
|
NodesFormat string `json:"nodesFormat,omitempty"`
|
||||||
PruneFilters []string `json:"pruneFilters,omitempty"`
|
PruneFilters []string `json:"pruneFilters,omitempty"`
|
||||||
|
Proxies map[string]ProxyConfig `json:"proxies,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProxyConfig contains proxy configuration settings
|
||||||
|
type ProxyConfig struct {
|
||||||
|
HTTPProxy string `json:"httpProxy,omitempty"`
|
||||||
|
HTTPSProxy string `json:"httpsProxy,omitempty"`
|
||||||
|
NoProxy string `json:"noProxy,omitempty"`
|
||||||
|
FTPProxy string `json:"ftpProxy,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// New initializes an empty configuration file for the given filename 'fn'
|
||||||
|
func New(fn string) *ConfigFile {
|
||||||
|
return &ConfigFile{
|
||||||
|
AuthConfigs: make(map[string]types.AuthConfig),
|
||||||
|
HTTPHeaders: make(map[string]string),
|
||||||
|
Filename: fn,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// LegacyLoadFromReader reads the non-nested configuration data given and sets up the
|
// LegacyLoadFromReader reads the non-nested configuration data given and sets up the
|
||||||
|
@ -108,6 +128,11 @@ func (configFile *ConfigFile) ContainsAuth() bool {
|
||||||
len(configFile.AuthConfigs) > 0
|
len(configFile.AuthConfigs) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAuthConfigs returns the mapping of repo to auth configuration
|
||||||
|
func (configFile *ConfigFile) GetAuthConfigs() map[string]types.AuthConfig {
|
||||||
|
return configFile.AuthConfigs
|
||||||
|
}
|
||||||
|
|
||||||
// SaveToWriter encodes and writes out all the authorization information to
|
// SaveToWriter encodes and writes out all the authorization information to
|
||||||
// the given writer
|
// the given writer
|
||||||
func (configFile *ConfigFile) SaveToWriter(writer io.Writer) error {
|
func (configFile *ConfigFile) SaveToWriter(writer io.Writer) error {
|
||||||
|
@ -152,6 +177,39 @@ func (configFile *ConfigFile) Save() error {
|
||||||
return configFile.SaveToWriter(f)
|
return configFile.SaveToWriter(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseProxyConfig computes proxy configuration by retrieving the config for the provided host and
|
||||||
|
// then checking this against any environment variables provided to the container
|
||||||
|
func (configFile *ConfigFile) ParseProxyConfig(host string, runOpts []string) map[string]*string {
|
||||||
|
var cfgKey string
|
||||||
|
|
||||||
|
if _, ok := configFile.Proxies[host]; !ok {
|
||||||
|
cfgKey = "default"
|
||||||
|
} else {
|
||||||
|
cfgKey = host
|
||||||
|
}
|
||||||
|
|
||||||
|
config := configFile.Proxies[cfgKey]
|
||||||
|
permitted := map[string]*string{
|
||||||
|
"HTTP_PROXY": &config.HTTPProxy,
|
||||||
|
"HTTPS_PROXY": &config.HTTPSProxy,
|
||||||
|
"NO_PROXY": &config.NoProxy,
|
||||||
|
"FTP_PROXY": &config.FTPProxy,
|
||||||
|
}
|
||||||
|
m := opts.ConvertKVStringsToMapWithNil(runOpts)
|
||||||
|
for k := range permitted {
|
||||||
|
if *permitted[k] == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, ok := m[k]; !ok {
|
||||||
|
m[k] = permitted[k]
|
||||||
|
}
|
||||||
|
if _, ok := m[strings.ToLower(k)]; !ok {
|
||||||
|
m[strings.ToLower(k)] = permitted[k]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
// encodeAuth creates a base64 encoded string to containing authorization information
|
// encodeAuth creates a base64 encoded string to containing authorization information
|
||||||
func encodeAuth(authConfig *types.AuthConfig) string {
|
func encodeAuth(authConfig *types.AuthConfig) string {
|
||||||
if authConfig.Username == "" && authConfig.Password == "" {
|
if authConfig.Username == "" && authConfig.Password == "" {
|
||||||
|
@ -188,3 +246,56 @@ func decodeAuth(authStr string) (string, string, error) {
|
||||||
password := strings.Trim(arr[1], "\x00")
|
password := strings.Trim(arr[1], "\x00")
|
||||||
return arr[0], password, nil
|
return arr[0], password, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCredentialsStore returns a new credentials store from the settings in the
|
||||||
|
// configuration file
|
||||||
|
func (configFile *ConfigFile) GetCredentialsStore(serverAddress string) credentials.Store {
|
||||||
|
if helper := getConfiguredCredentialStore(configFile, serverAddress); helper != "" {
|
||||||
|
return credentials.NewNativeStore(configFile, helper)
|
||||||
|
}
|
||||||
|
return credentials.NewFileStore(configFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAuthConfig for a repository from the credential store
|
||||||
|
func (configFile *ConfigFile) GetAuthConfig(serverAddress string) (types.AuthConfig, error) {
|
||||||
|
return configFile.GetCredentialsStore(serverAddress).Get(serverAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
// getConfiguredCredentialStore returns the credential helper configured for the
|
||||||
|
// given registry, the default credsStore, or the empty string if neither are
|
||||||
|
// configured.
|
||||||
|
func getConfiguredCredentialStore(c *ConfigFile, serverAddress string) string {
|
||||||
|
if c.CredentialHelpers != nil && serverAddress != "" {
|
||||||
|
if helper, exists := c.CredentialHelpers[serverAddress]; exists {
|
||||||
|
return helper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c.CredentialsStore
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAllCredentials returns all of the credentials stored in all of the
|
||||||
|
// configured credential stores.
|
||||||
|
func (configFile *ConfigFile) GetAllCredentials() (map[string]types.AuthConfig, error) {
|
||||||
|
auths := make(map[string]types.AuthConfig)
|
||||||
|
addAll := func(from map[string]types.AuthConfig) {
|
||||||
|
for reg, ac := range from {
|
||||||
|
auths[reg] = ac
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for registry := range configFile.CredentialHelpers {
|
||||||
|
helper := configFile.GetCredentialsStore(registry)
|
||||||
|
newAuths, err := helper.GetAll()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
addAll(newAuths)
|
||||||
|
}
|
||||||
|
defaultStore := configFile.GetCredentialsStore("")
|
||||||
|
newAuths, err := defaultStore.GetAll()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
addAll(newAuths)
|
||||||
|
return auths, nil
|
||||||
|
}
|
||||||
|
|
17
vendor/github.com/docker/cli/cli/config/credentials/credentials.go
generated
vendored
Normal file
17
vendor/github.com/docker/cli/cli/config/credentials/credentials.go
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package credentials
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Store is the interface that any credentials store must implement.
|
||||||
|
type Store interface {
|
||||||
|
// Erase removes credentials from the store for a given server.
|
||||||
|
Erase(serverAddress string) error
|
||||||
|
// Get retrieves credentials from the store for a given server.
|
||||||
|
Get(serverAddress string) (types.AuthConfig, error)
|
||||||
|
// GetAll retrieves all the credentials from the store.
|
||||||
|
GetAll() (map[string]types.AuthConfig, error)
|
||||||
|
// Store saves credentials in the store.
|
||||||
|
Store(authConfig types.AuthConfig) error
|
||||||
|
}
|
21
vendor/github.com/docker/cli/cli/config/credentials/default_store.go
generated
vendored
Normal file
21
vendor/github.com/docker/cli/cli/config/credentials/default_store.go
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package credentials
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DetectDefaultStore return the default credentials store for the platform if
|
||||||
|
// the store executable is available.
|
||||||
|
func DetectDefaultStore(store string) string {
|
||||||
|
platformDefault := defaultCredentialsStore()
|
||||||
|
|
||||||
|
// user defined or no default for platform
|
||||||
|
if store != "" || platformDefault == "" {
|
||||||
|
return store
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := exec.LookPath(remoteCredentialsPrefix + platformDefault); err == nil {
|
||||||
|
return platformDefault
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
5
vendor/github.com/docker/cli/cli/config/credentials/default_store_darwin.go
generated
vendored
Normal file
5
vendor/github.com/docker/cli/cli/config/credentials/default_store_darwin.go
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
package credentials
|
||||||
|
|
||||||
|
func defaultCredentialsStore() string {
|
||||||
|
return "osxkeychain"
|
||||||
|
}
|
13
vendor/github.com/docker/cli/cli/config/credentials/default_store_linux.go
generated
vendored
Normal file
13
vendor/github.com/docker/cli/cli/config/credentials/default_store_linux.go
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package credentials
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/docker/docker-credential-helpers/pass"
|
||||||
|
)
|
||||||
|
|
||||||
|
func defaultCredentialsStore() string {
|
||||||
|
if pass.PassInitialized {
|
||||||
|
return "pass"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "secretservice"
|
||||||
|
}
|
5
vendor/github.com/docker/cli/cli/config/credentials/default_store_unsupported.go
generated
vendored
Normal file
5
vendor/github.com/docker/cli/cli/config/credentials/default_store_unsupported.go
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
// +build !windows,!darwin,!linux
|
||||||
|
|
||||||
|
package credentials
|
||||||
|
|
||||||
|
const defaultCredentialsStore = ""
|
5
vendor/github.com/docker/cli/cli/config/credentials/default_store_windows.go
generated
vendored
Normal file
5
vendor/github.com/docker/cli/cli/config/credentials/default_store_windows.go
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
package credentials
|
||||||
|
|
||||||
|
func defaultCredentialsStore() string {
|
||||||
|
return "wincred"
|
||||||
|
}
|
55
vendor/github.com/docker/cli/cli/config/credentials/file_store.go
generated
vendored
Normal file
55
vendor/github.com/docker/cli/cli/config/credentials/file_store.go
generated
vendored
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
package credentials
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/registry"
|
||||||
|
)
|
||||||
|
|
||||||
|
type store interface {
|
||||||
|
Save() error
|
||||||
|
GetAuthConfigs() map[string]types.AuthConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
// fileStore implements a credentials store using
|
||||||
|
// the docker configuration file to keep the credentials in plain text.
|
||||||
|
type fileStore struct {
|
||||||
|
file store
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFileStore creates a new file credentials store.
|
||||||
|
func NewFileStore(file store) Store {
|
||||||
|
return &fileStore{file: file}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erase removes the given credentials from the file store.
|
||||||
|
func (c *fileStore) Erase(serverAddress string) error {
|
||||||
|
delete(c.file.GetAuthConfigs(), serverAddress)
|
||||||
|
return c.file.Save()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get retrieves credentials for a specific server from the file store.
|
||||||
|
func (c *fileStore) Get(serverAddress string) (types.AuthConfig, error) {
|
||||||
|
authConfig, ok := c.file.GetAuthConfigs()[serverAddress]
|
||||||
|
if !ok {
|
||||||
|
// Maybe they have a legacy config file, we will iterate the keys converting
|
||||||
|
// them to the new format and testing
|
||||||
|
for r, ac := range c.file.GetAuthConfigs() {
|
||||||
|
if serverAddress == registry.ConvertToHostname(r) {
|
||||||
|
return ac, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
authConfig = types.AuthConfig{}
|
||||||
|
}
|
||||||
|
return authConfig, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *fileStore) GetAll() (map[string]types.AuthConfig, error) {
|
||||||
|
return c.file.GetAuthConfigs(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store saves the given credentials in the file store.
|
||||||
|
func (c *fileStore) Store(authConfig types.AuthConfig) error {
|
||||||
|
c.file.GetAuthConfigs()[authConfig.ServerAddress] = authConfig
|
||||||
|
return c.file.Save()
|
||||||
|
}
|
143
vendor/github.com/docker/cli/cli/config/credentials/native_store.go
generated
vendored
Normal file
143
vendor/github.com/docker/cli/cli/config/credentials/native_store.go
generated
vendored
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
package credentials
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/docker/docker-credential-helpers/client"
|
||||||
|
"github.com/docker/docker-credential-helpers/credentials"
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
remoteCredentialsPrefix = "docker-credential-"
|
||||||
|
tokenUsername = "<token>"
|
||||||
|
)
|
||||||
|
|
||||||
|
// nativeStore implements a credentials store
|
||||||
|
// using native keychain to keep credentials secure.
|
||||||
|
// It piggybacks into a file store to keep users' emails.
|
||||||
|
type nativeStore struct {
|
||||||
|
programFunc client.ProgramFunc
|
||||||
|
fileStore Store
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewNativeStore creates a new native store that
|
||||||
|
// uses a remote helper program to manage credentials.
|
||||||
|
func NewNativeStore(file store, helperSuffix string) Store {
|
||||||
|
name := remoteCredentialsPrefix + helperSuffix
|
||||||
|
return &nativeStore{
|
||||||
|
programFunc: client.NewShellProgramFunc(name),
|
||||||
|
fileStore: NewFileStore(file),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erase removes the given credentials from the native store.
|
||||||
|
func (c *nativeStore) Erase(serverAddress string) error {
|
||||||
|
if err := client.Erase(c.programFunc, serverAddress); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to plain text store to remove email
|
||||||
|
return c.fileStore.Erase(serverAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get retrieves credentials for a specific server from the native store.
|
||||||
|
func (c *nativeStore) Get(serverAddress string) (types.AuthConfig, error) {
|
||||||
|
// load user email if it exist or an empty auth config.
|
||||||
|
auth, _ := c.fileStore.Get(serverAddress)
|
||||||
|
|
||||||
|
creds, err := c.getCredentialsFromStore(serverAddress)
|
||||||
|
if err != nil {
|
||||||
|
return auth, err
|
||||||
|
}
|
||||||
|
auth.Username = creds.Username
|
||||||
|
auth.IdentityToken = creds.IdentityToken
|
||||||
|
auth.Password = creds.Password
|
||||||
|
|
||||||
|
return auth, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAll retrieves all the credentials from the native store.
|
||||||
|
func (c *nativeStore) GetAll() (map[string]types.AuthConfig, error) {
|
||||||
|
auths, err := c.listCredentialsInStore()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Emails are only stored in the file store.
|
||||||
|
// This call can be safely eliminated when emails are removed.
|
||||||
|
fileConfigs, _ := c.fileStore.GetAll()
|
||||||
|
|
||||||
|
authConfigs := make(map[string]types.AuthConfig)
|
||||||
|
for registry := range auths {
|
||||||
|
creds, err := c.getCredentialsFromStore(registry)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ac := fileConfigs[registry] // might contain Email
|
||||||
|
ac.Username = creds.Username
|
||||||
|
ac.Password = creds.Password
|
||||||
|
ac.IdentityToken = creds.IdentityToken
|
||||||
|
authConfigs[registry] = ac
|
||||||
|
}
|
||||||
|
|
||||||
|
return authConfigs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store saves the given credentials in the file store.
|
||||||
|
func (c *nativeStore) Store(authConfig types.AuthConfig) error {
|
||||||
|
if err := c.storeCredentialsInStore(authConfig); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
authConfig.Username = ""
|
||||||
|
authConfig.Password = ""
|
||||||
|
authConfig.IdentityToken = ""
|
||||||
|
|
||||||
|
// Fallback to old credential in plain text to save only the email
|
||||||
|
return c.fileStore.Store(authConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
// storeCredentialsInStore executes the command to store the credentials in the native store.
|
||||||
|
func (c *nativeStore) storeCredentialsInStore(config types.AuthConfig) error {
|
||||||
|
creds := &credentials.Credentials{
|
||||||
|
ServerURL: config.ServerAddress,
|
||||||
|
Username: config.Username,
|
||||||
|
Secret: config.Password,
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.IdentityToken != "" {
|
||||||
|
creds.Username = tokenUsername
|
||||||
|
creds.Secret = config.IdentityToken
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.Store(c.programFunc, creds)
|
||||||
|
}
|
||||||
|
|
||||||
|
// getCredentialsFromStore executes the command to get the credentials from the native store.
|
||||||
|
func (c *nativeStore) getCredentialsFromStore(serverAddress string) (types.AuthConfig, error) {
|
||||||
|
var ret types.AuthConfig
|
||||||
|
|
||||||
|
creds, err := client.Get(c.programFunc, serverAddress)
|
||||||
|
if err != nil {
|
||||||
|
if credentials.IsErrCredentialsNotFound(err) {
|
||||||
|
// do not return an error if the credentials are not
|
||||||
|
// in the keychain. Let docker ask for new credentials.
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if creds.Username == tokenUsername {
|
||||||
|
ret.IdentityToken = creds.Secret
|
||||||
|
} else {
|
||||||
|
ret.Password = creds.Secret
|
||||||
|
ret.Username = creds.Username
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.ServerAddress = serverAddress
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// listCredentialsInStore returns a listing of stored credentials as a map of
|
||||||
|
// URL -> username.
|
||||||
|
func (c *nativeStore) listCredentialsInStore() (map[string]string, error) {
|
||||||
|
return client.List(c.programFunc)
|
||||||
|
}
|
21
vendor/github.com/docker/cli/cli/required.go
generated
vendored
21
vendor/github.com/docker/cli/cli/required.go
generated
vendored
|
@ -18,7 +18,7 @@ func NoArgs(cmd *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.Errorf(
|
return errors.Errorf(
|
||||||
"\"%s\" accepts no argument(s).\nSee '%s --help'.\n\nUsage: %s\n\n%s",
|
"%q accepts no arguments.\nSee '%s --help'.\n\nUsage: %s\n\n%s",
|
||||||
cmd.CommandPath(),
|
cmd.CommandPath(),
|
||||||
cmd.CommandPath(),
|
cmd.CommandPath(),
|
||||||
cmd.UseLine(),
|
cmd.UseLine(),
|
||||||
|
@ -33,9 +33,10 @@ func RequiresMinArgs(min int) cobra.PositionalArgs {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return errors.Errorf(
|
return errors.Errorf(
|
||||||
"\"%s\" requires at least %d argument(s).\nSee '%s --help'.\n\nUsage: %s\n\n%s",
|
"%q requires at least %d %s.\nSee '%s --help'.\n\nUsage: %s\n\n%s",
|
||||||
cmd.CommandPath(),
|
cmd.CommandPath(),
|
||||||
min,
|
min,
|
||||||
|
pluralize("argument", min),
|
||||||
cmd.CommandPath(),
|
cmd.CommandPath(),
|
||||||
cmd.UseLine(),
|
cmd.UseLine(),
|
||||||
cmd.Short,
|
cmd.Short,
|
||||||
|
@ -50,9 +51,10 @@ func RequiresMaxArgs(max int) cobra.PositionalArgs {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return errors.Errorf(
|
return errors.Errorf(
|
||||||
"\"%s\" requires at most %d argument(s).\nSee '%s --help'.\n\nUsage: %s\n\n%s",
|
"%q requires at most %d %s.\nSee '%s --help'.\n\nUsage: %s\n\n%s",
|
||||||
cmd.CommandPath(),
|
cmd.CommandPath(),
|
||||||
max,
|
max,
|
||||||
|
pluralize("argument", max),
|
||||||
cmd.CommandPath(),
|
cmd.CommandPath(),
|
||||||
cmd.UseLine(),
|
cmd.UseLine(),
|
||||||
cmd.Short,
|
cmd.Short,
|
||||||
|
@ -67,10 +69,11 @@ func RequiresRangeArgs(min int, max int) cobra.PositionalArgs {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return errors.Errorf(
|
return errors.Errorf(
|
||||||
"\"%s\" requires at least %d and at most %d argument(s).\nSee '%s --help'.\n\nUsage: %s\n\n%s",
|
"%q requires at least %d and at most %d %s.\nSee '%s --help'.\n\nUsage: %s\n\n%s",
|
||||||
cmd.CommandPath(),
|
cmd.CommandPath(),
|
||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
|
pluralize("argument", max),
|
||||||
cmd.CommandPath(),
|
cmd.CommandPath(),
|
||||||
cmd.UseLine(),
|
cmd.UseLine(),
|
||||||
cmd.Short,
|
cmd.Short,
|
||||||
|
@ -85,12 +88,20 @@ func ExactArgs(number int) cobra.PositionalArgs {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return errors.Errorf(
|
return errors.Errorf(
|
||||||
"\"%s\" requires exactly %d argument(s).\nSee '%s --help'.\n\nUsage: %s\n\n%s",
|
"%q requires exactly %d %s.\nSee '%s --help'.\n\nUsage: %s\n\n%s",
|
||||||
cmd.CommandPath(),
|
cmd.CommandPath(),
|
||||||
number,
|
number,
|
||||||
|
pluralize("argument", number),
|
||||||
cmd.CommandPath(),
|
cmd.CommandPath(),
|
||||||
cmd.UseLine(),
|
cmd.UseLine(),
|
||||||
cmd.Short,
|
cmd.Short,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func pluralize(word string, number int) string {
|
||||||
|
if number == 1 {
|
||||||
|
return word
|
||||||
|
}
|
||||||
|
return word + "s"
|
||||||
|
}
|
||||||
|
|
64
vendor/github.com/docker/cli/opts/duration.go
generated
vendored
Normal file
64
vendor/github.com/docker/cli/opts/duration.go
generated
vendored
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
package opts
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PositiveDurationOpt is an option type for time.Duration that uses a pointer.
|
||||||
|
// It behave similarly to DurationOpt but only allows positive duration values.
|
||||||
|
type PositiveDurationOpt struct {
|
||||||
|
DurationOpt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set a new value on the option. Setting a negative duration value will cause
|
||||||
|
// an error to be returned.
|
||||||
|
func (d *PositiveDurationOpt) Set(s string) error {
|
||||||
|
err := d.DurationOpt.Set(s)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if *d.DurationOpt.value < 0 {
|
||||||
|
return errors.Errorf("duration cannot be negative")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DurationOpt is an option type for time.Duration that uses a pointer. This
|
||||||
|
// allows us to get nil values outside, instead of defaulting to 0
|
||||||
|
type DurationOpt struct {
|
||||||
|
value *time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDurationOpt creates a DurationOpt with the specified duration
|
||||||
|
func NewDurationOpt(value *time.Duration) *DurationOpt {
|
||||||
|
return &DurationOpt{
|
||||||
|
value: value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set a new value on the option
|
||||||
|
func (d *DurationOpt) Set(s string) error {
|
||||||
|
v, err := time.ParseDuration(s)
|
||||||
|
d.value = &v
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type returns the type of this option, which will be displayed in `--help` output
|
||||||
|
func (d *DurationOpt) Type() string {
|
||||||
|
return "duration"
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a string repr of this option
|
||||||
|
func (d *DurationOpt) String() string {
|
||||||
|
if d.value != nil {
|
||||||
|
return d.value.String()
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the time.Duration
|
||||||
|
func (d *DurationOpt) Value() *time.Duration {
|
||||||
|
return d.value
|
||||||
|
}
|
0
vendor/github.com/docker/docker/opts/ip.go → vendor/github.com/docker/cli/opts/ip.go
generated
vendored
0
vendor/github.com/docker/docker/opts/ip.go → vendor/github.com/docker/cli/opts/ip.go
generated
vendored
174
vendor/github.com/docker/cli/opts/mount.go
generated
vendored
Normal file
174
vendor/github.com/docker/cli/opts/mount.go
generated
vendored
Normal file
|
@ -0,0 +1,174 @@
|
||||||
|
package opts
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/csv"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
mounttypes "github.com/docker/docker/api/types/mount"
|
||||||
|
"github.com/docker/go-units"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MountOpt is a Value type for parsing mounts
|
||||||
|
type MountOpt struct {
|
||||||
|
values []mounttypes.Mount
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set a new mount value
|
||||||
|
// nolint: gocyclo
|
||||||
|
func (m *MountOpt) Set(value string) error {
|
||||||
|
csvReader := csv.NewReader(strings.NewReader(value))
|
||||||
|
fields, err := csvReader.Read()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
mount := mounttypes.Mount{}
|
||||||
|
|
||||||
|
volumeOptions := func() *mounttypes.VolumeOptions {
|
||||||
|
if mount.VolumeOptions == nil {
|
||||||
|
mount.VolumeOptions = &mounttypes.VolumeOptions{
|
||||||
|
Labels: make(map[string]string),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if mount.VolumeOptions.DriverConfig == nil {
|
||||||
|
mount.VolumeOptions.DriverConfig = &mounttypes.Driver{}
|
||||||
|
}
|
||||||
|
return mount.VolumeOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
bindOptions := func() *mounttypes.BindOptions {
|
||||||
|
if mount.BindOptions == nil {
|
||||||
|
mount.BindOptions = new(mounttypes.BindOptions)
|
||||||
|
}
|
||||||
|
return mount.BindOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpfsOptions := func() *mounttypes.TmpfsOptions {
|
||||||
|
if mount.TmpfsOptions == nil {
|
||||||
|
mount.TmpfsOptions = new(mounttypes.TmpfsOptions)
|
||||||
|
}
|
||||||
|
return mount.TmpfsOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
setValueOnMap := func(target map[string]string, value string) {
|
||||||
|
parts := strings.SplitN(value, "=", 2)
|
||||||
|
if len(parts) == 1 {
|
||||||
|
target[value] = ""
|
||||||
|
} else {
|
||||||
|
target[parts[0]] = parts[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mount.Type = mounttypes.TypeVolume // default to volume mounts
|
||||||
|
// Set writable as the default
|
||||||
|
for _, field := range fields {
|
||||||
|
parts := strings.SplitN(field, "=", 2)
|
||||||
|
key := strings.ToLower(parts[0])
|
||||||
|
|
||||||
|
if len(parts) == 1 {
|
||||||
|
switch key {
|
||||||
|
case "readonly", "ro":
|
||||||
|
mount.ReadOnly = true
|
||||||
|
continue
|
||||||
|
case "volume-nocopy":
|
||||||
|
volumeOptions().NoCopy = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(parts) != 2 {
|
||||||
|
return fmt.Errorf("invalid field '%s' must be a key=value pair", field)
|
||||||
|
}
|
||||||
|
|
||||||
|
value := parts[1]
|
||||||
|
switch key {
|
||||||
|
case "type":
|
||||||
|
mount.Type = mounttypes.Type(strings.ToLower(value))
|
||||||
|
case "source", "src":
|
||||||
|
mount.Source = value
|
||||||
|
case "target", "dst", "destination":
|
||||||
|
mount.Target = value
|
||||||
|
case "readonly", "ro":
|
||||||
|
mount.ReadOnly, err = strconv.ParseBool(value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid value for %s: %s", key, value)
|
||||||
|
}
|
||||||
|
case "consistency":
|
||||||
|
mount.Consistency = mounttypes.Consistency(strings.ToLower(value))
|
||||||
|
case "bind-propagation":
|
||||||
|
bindOptions().Propagation = mounttypes.Propagation(strings.ToLower(value))
|
||||||
|
case "volume-nocopy":
|
||||||
|
volumeOptions().NoCopy, err = strconv.ParseBool(value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid value for volume-nocopy: %s", value)
|
||||||
|
}
|
||||||
|
case "volume-label":
|
||||||
|
setValueOnMap(volumeOptions().Labels, value)
|
||||||
|
case "volume-driver":
|
||||||
|
volumeOptions().DriverConfig.Name = value
|
||||||
|
case "volume-opt":
|
||||||
|
if volumeOptions().DriverConfig.Options == nil {
|
||||||
|
volumeOptions().DriverConfig.Options = make(map[string]string)
|
||||||
|
}
|
||||||
|
setValueOnMap(volumeOptions().DriverConfig.Options, value)
|
||||||
|
case "tmpfs-size":
|
||||||
|
sizeBytes, err := units.RAMInBytes(value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid value for %s: %s", key, value)
|
||||||
|
}
|
||||||
|
tmpfsOptions().SizeBytes = sizeBytes
|
||||||
|
case "tmpfs-mode":
|
||||||
|
ui64, err := strconv.ParseUint(value, 8, 32)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid value for %s: %s", key, value)
|
||||||
|
}
|
||||||
|
tmpfsOptions().Mode = os.FileMode(ui64)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unexpected key '%s' in '%s'", key, field)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if mount.Type == "" {
|
||||||
|
return fmt.Errorf("type is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if mount.Target == "" {
|
||||||
|
return fmt.Errorf("target is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if mount.VolumeOptions != nil && mount.Type != mounttypes.TypeVolume {
|
||||||
|
return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", mount.Type)
|
||||||
|
}
|
||||||
|
if mount.BindOptions != nil && mount.Type != mounttypes.TypeBind {
|
||||||
|
return fmt.Errorf("cannot mix 'bind-*' options with mount type '%s'", mount.Type)
|
||||||
|
}
|
||||||
|
if mount.TmpfsOptions != nil && mount.Type != mounttypes.TypeTmpfs {
|
||||||
|
return fmt.Errorf("cannot mix 'tmpfs-*' options with mount type '%s'", mount.Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
m.values = append(m.values, mount)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type returns the type of this option
|
||||||
|
func (m *MountOpt) Type() string {
|
||||||
|
return "mount"
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a string repr of this option
|
||||||
|
func (m *MountOpt) String() string {
|
||||||
|
mounts := []string{}
|
||||||
|
for _, mount := range m.values {
|
||||||
|
repr := fmt.Sprintf("%s %s %s", mount.Type, mount.Source, mount.Target)
|
||||||
|
mounts = append(mounts, repr)
|
||||||
|
}
|
||||||
|
return strings.Join(mounts, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the mounts
|
||||||
|
func (m *MountOpt) Value() []mounttypes.Mount {
|
||||||
|
return m.values
|
||||||
|
}
|
106
vendor/github.com/docker/cli/opts/network.go
generated
vendored
Normal file
106
vendor/github.com/docker/cli/opts/network.go
generated
vendored
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
package opts
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/csv"
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
networkOptName = "name"
|
||||||
|
networkOptAlias = "alias"
|
||||||
|
driverOpt = "driver-opt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NetworkAttachmentOpts represents the network options for endpoint creation
|
||||||
|
type NetworkAttachmentOpts struct {
|
||||||
|
Target string
|
||||||
|
Aliases []string
|
||||||
|
DriverOpts map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NetworkOpt represents a network config in swarm mode.
|
||||||
|
type NetworkOpt struct {
|
||||||
|
options []NetworkAttachmentOpts
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set networkopts value
|
||||||
|
func (n *NetworkOpt) Set(value string) error {
|
||||||
|
longSyntax, err := regexp.MatchString(`\w+=\w+(,\w+=\w+)*`, value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var netOpt NetworkAttachmentOpts
|
||||||
|
if longSyntax {
|
||||||
|
csvReader := csv.NewReader(strings.NewReader(value))
|
||||||
|
fields, err := csvReader.Read()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
netOpt.Aliases = []string{}
|
||||||
|
for _, field := range fields {
|
||||||
|
parts := strings.SplitN(field, "=", 2)
|
||||||
|
|
||||||
|
if len(parts) < 2 {
|
||||||
|
return fmt.Errorf("invalid field %s", field)
|
||||||
|
}
|
||||||
|
|
||||||
|
key := strings.TrimSpace(strings.ToLower(parts[0]))
|
||||||
|
value := strings.TrimSpace(strings.ToLower(parts[1]))
|
||||||
|
|
||||||
|
switch key {
|
||||||
|
case networkOptName:
|
||||||
|
netOpt.Target = value
|
||||||
|
case networkOptAlias:
|
||||||
|
netOpt.Aliases = append(netOpt.Aliases, value)
|
||||||
|
case driverOpt:
|
||||||
|
key, value, err = parseDriverOpt(value)
|
||||||
|
if err == nil {
|
||||||
|
if netOpt.DriverOpts == nil {
|
||||||
|
netOpt.DriverOpts = make(map[string]string)
|
||||||
|
}
|
||||||
|
netOpt.DriverOpts[key] = value
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid field key %s", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(netOpt.Target) == 0 {
|
||||||
|
return fmt.Errorf("network name/id is not specified")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
netOpt.Target = value
|
||||||
|
}
|
||||||
|
n.options = append(n.options, netOpt)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type returns the type of this option
|
||||||
|
func (n *NetworkOpt) Type() string {
|
||||||
|
return "network"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the networkopts
|
||||||
|
func (n *NetworkOpt) Value() []NetworkAttachmentOpts {
|
||||||
|
return n.options
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns the network opts as a string
|
||||||
|
func (n *NetworkOpt) String() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseDriverOpt(driverOpt string) (string, string, error) {
|
||||||
|
parts := strings.SplitN(driverOpt, "=", 2)
|
||||||
|
if len(parts) != 2 {
|
||||||
|
return "", "", fmt.Errorf("invalid key value pair format in driver options")
|
||||||
|
}
|
||||||
|
key := strings.TrimSpace(strings.ToLower(parts[0]))
|
||||||
|
value := strings.TrimSpace(strings.ToLower(parts[1]))
|
||||||
|
return key, value, nil
|
||||||
|
}
|
|
@ -179,7 +179,7 @@ func (opts *MapOpts) GetAll() map[string]string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *MapOpts) String() string {
|
func (opts *MapOpts) String() string {
|
||||||
return fmt.Sprintf("%v", map[string]string((opts.values)))
|
return fmt.Sprintf("%v", opts.values)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type returns a string name for this Option type
|
// Type returns a string name for this Option type
|
163
vendor/github.com/docker/cli/opts/port.go
generated
vendored
Normal file
163
vendor/github.com/docker/cli/opts/port.go
generated
vendored
Normal file
|
@ -0,0 +1,163 @@
|
||||||
|
package opts
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/csv"
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types/swarm"
|
||||||
|
"github.com/docker/go-connections/nat"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
portOptTargetPort = "target"
|
||||||
|
portOptPublishedPort = "published"
|
||||||
|
portOptProtocol = "protocol"
|
||||||
|
portOptMode = "mode"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PortOpt represents a port config in swarm mode.
|
||||||
|
type PortOpt struct {
|
||||||
|
ports []swarm.PortConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set a new port value
|
||||||
|
// nolint: gocyclo
|
||||||
|
func (p *PortOpt) Set(value string) error {
|
||||||
|
longSyntax, err := regexp.MatchString(`\w+=\w+(,\w+=\w+)*`, value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if longSyntax {
|
||||||
|
csvReader := csv.NewReader(strings.NewReader(value))
|
||||||
|
fields, err := csvReader.Read()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
pConfig := swarm.PortConfig{}
|
||||||
|
for _, field := range fields {
|
||||||
|
parts := strings.SplitN(field, "=", 2)
|
||||||
|
if len(parts) != 2 {
|
||||||
|
return fmt.Errorf("invalid field %s", field)
|
||||||
|
}
|
||||||
|
|
||||||
|
key := strings.ToLower(parts[0])
|
||||||
|
value := strings.ToLower(parts[1])
|
||||||
|
|
||||||
|
switch key {
|
||||||
|
case portOptProtocol:
|
||||||
|
if value != string(swarm.PortConfigProtocolTCP) && value != string(swarm.PortConfigProtocolUDP) {
|
||||||
|
return fmt.Errorf("invalid protocol value %s", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
pConfig.Protocol = swarm.PortConfigProtocol(value)
|
||||||
|
case portOptMode:
|
||||||
|
if value != string(swarm.PortConfigPublishModeIngress) && value != string(swarm.PortConfigPublishModeHost) {
|
||||||
|
return fmt.Errorf("invalid publish mode value %s", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
pConfig.PublishMode = swarm.PortConfigPublishMode(value)
|
||||||
|
case portOptTargetPort:
|
||||||
|
tPort, err := strconv.ParseUint(value, 10, 16)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
pConfig.TargetPort = uint32(tPort)
|
||||||
|
case portOptPublishedPort:
|
||||||
|
pPort, err := strconv.ParseUint(value, 10, 16)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
pConfig.PublishedPort = uint32(pPort)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid field key %s", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if pConfig.TargetPort == 0 {
|
||||||
|
return fmt.Errorf("missing mandatory field %q", portOptTargetPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
if pConfig.PublishMode == "" {
|
||||||
|
pConfig.PublishMode = swarm.PortConfigPublishModeIngress
|
||||||
|
}
|
||||||
|
|
||||||
|
if pConfig.Protocol == "" {
|
||||||
|
pConfig.Protocol = swarm.PortConfigProtocolTCP
|
||||||
|
}
|
||||||
|
|
||||||
|
p.ports = append(p.ports, pConfig)
|
||||||
|
} else {
|
||||||
|
// short syntax
|
||||||
|
portConfigs := []swarm.PortConfig{}
|
||||||
|
ports, portBindingMap, err := nat.ParsePortSpecs([]string{value})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, portBindings := range portBindingMap {
|
||||||
|
for _, portBinding := range portBindings {
|
||||||
|
if portBinding.HostIP != "" {
|
||||||
|
return fmt.Errorf("hostip is not supported")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for port := range ports {
|
||||||
|
portConfig, err := ConvertPortToPortConfig(port, portBindingMap)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
portConfigs = append(portConfigs, portConfig...)
|
||||||
|
}
|
||||||
|
p.ports = append(p.ports, portConfigs...)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type returns the type of this option
|
||||||
|
func (p *PortOpt) Type() string {
|
||||||
|
return "port"
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a string repr of this option
|
||||||
|
func (p *PortOpt) String() string {
|
||||||
|
ports := []string{}
|
||||||
|
for _, port := range p.ports {
|
||||||
|
repr := fmt.Sprintf("%v:%v/%s/%s", port.PublishedPort, port.TargetPort, port.Protocol, port.PublishMode)
|
||||||
|
ports = append(ports, repr)
|
||||||
|
}
|
||||||
|
return strings.Join(ports, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ports
|
||||||
|
func (p *PortOpt) Value() []swarm.PortConfig {
|
||||||
|
return p.ports
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConvertPortToPortConfig converts ports to the swarm type
|
||||||
|
func ConvertPortToPortConfig(
|
||||||
|
port nat.Port,
|
||||||
|
portBindings map[nat.Port][]nat.PortBinding,
|
||||||
|
) ([]swarm.PortConfig, error) {
|
||||||
|
ports := []swarm.PortConfig{}
|
||||||
|
|
||||||
|
for _, binding := range portBindings[port] {
|
||||||
|
hostPort, err := strconv.ParseUint(binding.HostPort, 10, 16)
|
||||||
|
if err != nil && binding.HostPort != "" {
|
||||||
|
return nil, fmt.Errorf("invalid hostport binding (%s) for port (%s)", binding.HostPort, port.Port())
|
||||||
|
}
|
||||||
|
ports = append(ports, swarm.PortConfig{
|
||||||
|
//TODO Name: ?
|
||||||
|
Protocol: swarm.PortConfigProtocol(strings.ToLower(port.Proto())),
|
||||||
|
TargetPort: uint32(port.Int()),
|
||||||
|
PublishedPort: uint32(hostPort),
|
||||||
|
PublishMode: swarm.PortConfigPublishModeIngress,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return ports, nil
|
||||||
|
}
|
|
@ -18,7 +18,7 @@ func (s *QuotedString) Type() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *QuotedString) String() string {
|
func (s *QuotedString) String() string {
|
||||||
return string(*s.value)
|
return *s.value
|
||||||
}
|
}
|
||||||
|
|
||||||
func trimQuotes(value string) string {
|
func trimQuotes(value string) string {
|
98
vendor/github.com/docker/cli/opts/secret.go
generated
vendored
Normal file
98
vendor/github.com/docker/cli/opts/secret.go
generated
vendored
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
package opts
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/csv"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SecretOpt is a Value type for parsing secrets
|
||||||
|
type SecretOpt struct {
|
||||||
|
values []*swarmtypes.SecretReference
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set a new secret value
|
||||||
|
func (o *SecretOpt) Set(value string) error {
|
||||||
|
csvReader := csv.NewReader(strings.NewReader(value))
|
||||||
|
fields, err := csvReader.Read()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
options := &swarmtypes.SecretReference{
|
||||||
|
File: &swarmtypes.SecretReferenceFileTarget{
|
||||||
|
UID: "0",
|
||||||
|
GID: "0",
|
||||||
|
Mode: 0444,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// support a simple syntax of --secret foo
|
||||||
|
if len(fields) == 1 {
|
||||||
|
options.File.Name = fields[0]
|
||||||
|
options.SecretName = fields[0]
|
||||||
|
o.values = append(o.values, options)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, field := range fields {
|
||||||
|
parts := strings.SplitN(field, "=", 2)
|
||||||
|
key := strings.ToLower(parts[0])
|
||||||
|
|
||||||
|
if len(parts) != 2 {
|
||||||
|
return fmt.Errorf("invalid field '%s' must be a key=value pair", field)
|
||||||
|
}
|
||||||
|
|
||||||
|
value := parts[1]
|
||||||
|
switch key {
|
||||||
|
case "source", "src":
|
||||||
|
options.SecretName = value
|
||||||
|
case "target":
|
||||||
|
options.File.Name = value
|
||||||
|
case "uid":
|
||||||
|
options.File.UID = value
|
||||||
|
case "gid":
|
||||||
|
options.File.GID = value
|
||||||
|
case "mode":
|
||||||
|
m, err := strconv.ParseUint(value, 0, 32)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid mode specified: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
options.File.Mode = os.FileMode(m)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid field in secret request: %s", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.SecretName == "" {
|
||||||
|
return fmt.Errorf("source is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
o.values = append(o.values, options)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type returns the type of this option
|
||||||
|
func (o *SecretOpt) Type() string {
|
||||||
|
return "secret"
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a string repr of this option
|
||||||
|
func (o *SecretOpt) String() string {
|
||||||
|
secrets := []string{}
|
||||||
|
for _, secret := range o.values {
|
||||||
|
repr := fmt.Sprintf("%s -> %s", secret.SecretName, secret.File.Name)
|
||||||
|
secrets = append(secrets, repr)
|
||||||
|
}
|
||||||
|
return strings.Join(secrets, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the secret requests
|
||||||
|
func (o *SecretOpt) Value() []*swarmtypes.SecretReference {
|
||||||
|
return o.values
|
||||||
|
}
|
|
@ -52,10 +52,7 @@ func ValidateThrottleIOpsDevice(val string) (*blkiodev.ThrottleDevice, error) {
|
||||||
return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>. Number must be a positive integer", val)
|
return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>. Number must be a positive integer", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &blkiodev.ThrottleDevice{
|
return &blkiodev.ThrottleDevice{Path: split[0], Rate: rate}, nil
|
||||||
Path: split[0],
|
|
||||||
Rate: uint64(rate),
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ThrottledeviceOpt defines a map of ThrottleDevices
|
// ThrottledeviceOpt defines a map of ThrottleDevices
|
84
vendor/github.com/docker/cli/opts/weightdevice.go
generated
vendored
Normal file
84
vendor/github.com/docker/cli/opts/weightdevice.go
generated
vendored
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
package opts
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types/blkiodev"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ValidatorWeightFctType defines a validator function that returns a validated struct and/or an error.
|
||||||
|
type ValidatorWeightFctType func(val string) (*blkiodev.WeightDevice, error)
|
||||||
|
|
||||||
|
// ValidateWeightDevice validates that the specified string has a valid device-weight format.
|
||||||
|
func ValidateWeightDevice(val string) (*blkiodev.WeightDevice, error) {
|
||||||
|
split := strings.SplitN(val, ":", 2)
|
||||||
|
if len(split) != 2 {
|
||||||
|
return nil, fmt.Errorf("bad format: %s", val)
|
||||||
|
}
|
||||||
|
if !strings.HasPrefix(split[0], "/dev/") {
|
||||||
|
return nil, fmt.Errorf("bad format for device path: %s", val)
|
||||||
|
}
|
||||||
|
weight, err := strconv.ParseUint(split[1], 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid weight for device: %s", val)
|
||||||
|
}
|
||||||
|
if weight > 0 && (weight < 10 || weight > 1000) {
|
||||||
|
return nil, fmt.Errorf("invalid weight for device: %s", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &blkiodev.WeightDevice{
|
||||||
|
Path: split[0],
|
||||||
|
Weight: uint16(weight),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WeightdeviceOpt defines a map of WeightDevices
|
||||||
|
type WeightdeviceOpt struct {
|
||||||
|
values []*blkiodev.WeightDevice
|
||||||
|
validator ValidatorWeightFctType
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewWeightdeviceOpt creates a new WeightdeviceOpt
|
||||||
|
func NewWeightdeviceOpt(validator ValidatorWeightFctType) WeightdeviceOpt {
|
||||||
|
values := []*blkiodev.WeightDevice{}
|
||||||
|
return WeightdeviceOpt{
|
||||||
|
values: values,
|
||||||
|
validator: validator,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set validates a WeightDevice and sets its name as a key in WeightdeviceOpt
|
||||||
|
func (opt *WeightdeviceOpt) Set(val string) error {
|
||||||
|
var value *blkiodev.WeightDevice
|
||||||
|
if opt.validator != nil {
|
||||||
|
v, err := opt.validator(val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
value = v
|
||||||
|
}
|
||||||
|
(opt.values) = append((opt.values), value)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns WeightdeviceOpt values as a string.
|
||||||
|
func (opt *WeightdeviceOpt) String() string {
|
||||||
|
var out []string
|
||||||
|
for _, v := range opt.values {
|
||||||
|
out = append(out, v.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%v", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetList returns a slice of pointers to WeightDevices.
|
||||||
|
func (opt *WeightdeviceOpt) GetList() []*blkiodev.WeightDevice {
|
||||||
|
return opt.values
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type returns the option type
|
||||||
|
func (opt *WeightdeviceOpt) Type() string {
|
||||||
|
return "list"
|
||||||
|
}
|
2
vendor/github.com/docker/distribution/blobs.go
generated
vendored
2
vendor/github.com/docker/distribution/blobs.go
generated
vendored
|
@ -152,7 +152,7 @@ type BlobProvider interface {
|
||||||
|
|
||||||
// BlobServer can serve blobs via http.
|
// BlobServer can serve blobs via http.
|
||||||
type BlobServer interface {
|
type BlobServer interface {
|
||||||
// ServeBlob attempts to serve the blob, identifed by dgst, via http. The
|
// ServeBlob attempts to serve the blob, identified by dgst, via http. The
|
||||||
// service may decide to redirect the client elsewhere or serve the data
|
// service may decide to redirect the client elsewhere or serve the data
|
||||||
// directly.
|
// directly.
|
||||||
//
|
//
|
||||||
|
|
2
vendor/github.com/docker/distribution/context/doc.go
generated
vendored
2
vendor/github.com/docker/distribution/context/doc.go
generated
vendored
|
@ -64,7 +64,7 @@
|
||||||
// Note that this only affects the new context, the previous context, with the
|
// Note that this only affects the new context, the previous context, with the
|
||||||
// version field, can be used independently. Put another way, the new logger,
|
// version field, can be used independently. Put another way, the new logger,
|
||||||
// added to the request context, is unique to that context and can have
|
// added to the request context, is unique to that context and can have
|
||||||
// request scoped varaibles.
|
// request scoped variables.
|
||||||
//
|
//
|
||||||
// HTTP Requests
|
// HTTP Requests
|
||||||
//
|
//
|
||||||
|
|
2
vendor/github.com/docker/distribution/context/http.go
generated
vendored
2
vendor/github.com/docker/distribution/context/http.go
generated
vendored
|
@ -8,9 +8,9 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
|
||||||
"github.com/docker/distribution/uuid"
|
"github.com/docker/distribution/uuid"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Common errors used with this package.
|
// Common errors used with this package.
|
||||||
|
|
2
vendor/github.com/docker/distribution/context/logger.go
generated
vendored
2
vendor/github.com/docker/distribution/context/logger.go
generated
vendored
|
@ -3,7 +3,7 @@ package context
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
2
vendor/github.com/docker/distribution/errors.go
generated
vendored
2
vendor/github.com/docker/distribution/errors.go
generated
vendored
|
@ -77,7 +77,7 @@ func (err ErrManifestUnknownRevision) Error() string {
|
||||||
type ErrManifestUnverified struct{}
|
type ErrManifestUnverified struct{}
|
||||||
|
|
||||||
func (ErrManifestUnverified) Error() string {
|
func (ErrManifestUnverified) Error() string {
|
||||||
return fmt.Sprintf("unverified manifest")
|
return "unverified manifest"
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrManifestVerification provides a type to collect errors encountered
|
// ErrManifestVerification provides a type to collect errors encountered
|
||||||
|
|
2
vendor/github.com/docker/distribution/reference/reference.go
generated
vendored
2
vendor/github.com/docker/distribution/reference/reference.go
generated
vendored
|
@ -15,7 +15,7 @@
|
||||||
// tag := /[\w][\w.-]{0,127}/
|
// tag := /[\w][\w.-]{0,127}/
|
||||||
//
|
//
|
||||||
// digest := digest-algorithm ":" digest-hex
|
// digest := digest-algorithm ":" digest-hex
|
||||||
// digest-algorithm := digest-algorithm-component [ digest-algorithm-separator digest-algorithm-component ]
|
// digest-algorithm := digest-algorithm-component [ digest-algorithm-separator digest-algorithm-component ]*
|
||||||
// digest-algorithm-separator := /[+.-_]/
|
// digest-algorithm-separator := /[+.-_]/
|
||||||
// digest-algorithm-component := /[A-Za-z][A-Za-z0-9]*/
|
// digest-algorithm-component := /[A-Za-z][A-Za-z0-9]*/
|
||||||
// digest-hex := /[0-9a-fA-F]{32,}/ ; At least 128 bit digest value
|
// digest-hex := /[0-9a-fA-F]{32,}/ ; At least 128 bit digest value
|
||||||
|
|
116
vendor/github.com/docker/distribution/registry/api/v2/urls.go
generated
vendored
116
vendor/github.com/docker/distribution/registry/api/v2/urls.go
generated
vendored
|
@ -1,10 +1,9 @@
|
||||||
package v2
|
package v2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
|
@ -48,66 +47,42 @@ func NewURLBuilderFromString(root string, relative bool) (*URLBuilder, error) {
|
||||||
// NewURLBuilderFromRequest uses information from an *http.Request to
|
// NewURLBuilderFromRequest uses information from an *http.Request to
|
||||||
// construct the root url.
|
// construct the root url.
|
||||||
func NewURLBuilderFromRequest(r *http.Request, relative bool) *URLBuilder {
|
func NewURLBuilderFromRequest(r *http.Request, relative bool) *URLBuilder {
|
||||||
var scheme string
|
var (
|
||||||
|
|
||||||
forwardedProto := r.Header.Get("X-Forwarded-Proto")
|
|
||||||
// TODO: log the error
|
|
||||||
forwardedHeader, _, _ := parseForwardedHeader(r.Header.Get("Forwarded"))
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case len(forwardedProto) > 0:
|
|
||||||
scheme = forwardedProto
|
|
||||||
case len(forwardedHeader["proto"]) > 0:
|
|
||||||
scheme = forwardedHeader["proto"]
|
|
||||||
case r.TLS != nil:
|
|
||||||
scheme = "https"
|
|
||||||
case len(r.URL.Scheme) > 0:
|
|
||||||
scheme = r.URL.Scheme
|
|
||||||
default:
|
|
||||||
scheme = "http"
|
scheme = "http"
|
||||||
|
host = r.Host
|
||||||
|
)
|
||||||
|
|
||||||
|
if r.TLS != nil {
|
||||||
|
scheme = "https"
|
||||||
|
} else if len(r.URL.Scheme) > 0 {
|
||||||
|
scheme = r.URL.Scheme
|
||||||
}
|
}
|
||||||
|
|
||||||
host := r.Host
|
// Handle fowarded headers
|
||||||
|
// Prefer "Forwarded" header as defined by rfc7239 if given
|
||||||
if forwardedHost := r.Header.Get("X-Forwarded-Host"); len(forwardedHost) > 0 {
|
// see https://tools.ietf.org/html/rfc7239
|
||||||
// According to the Apache mod_proxy docs, X-Forwarded-Host can be a
|
if forwarded := r.Header.Get("Forwarded"); len(forwarded) > 0 {
|
||||||
// comma-separated list of hosts, to which each proxy appends the
|
forwardedHeader, _, err := parseForwardedHeader(forwarded)
|
||||||
// requested host. We want to grab the first from this comma-separated
|
if err == nil {
|
||||||
// list.
|
if fproto := forwardedHeader["proto"]; len(fproto) > 0 {
|
||||||
hosts := strings.SplitN(forwardedHost, ",", 2)
|
scheme = fproto
|
||||||
host = strings.TrimSpace(hosts[0])
|
}
|
||||||
} else if addr, exists := forwardedHeader["for"]; exists {
|
if fhost := forwardedHeader["host"]; len(fhost) > 0 {
|
||||||
host = addr
|
host = fhost
|
||||||
} else if h, exists := forwardedHeader["host"]; exists {
|
}
|
||||||
host = h
|
|
||||||
}
|
|
||||||
|
|
||||||
portLessHost, port := host, ""
|
|
||||||
if !isIPv6Address(portLessHost) {
|
|
||||||
// with go 1.6, this would treat the last part of IPv6 address as a port
|
|
||||||
portLessHost, port, _ = net.SplitHostPort(host)
|
|
||||||
}
|
|
||||||
if forwardedPort := r.Header.Get("X-Forwarded-Port"); len(port) == 0 && len(forwardedPort) > 0 {
|
|
||||||
ports := strings.SplitN(forwardedPort, ",", 2)
|
|
||||||
forwardedPort = strings.TrimSpace(ports[0])
|
|
||||||
if _, err := strconv.ParseInt(forwardedPort, 10, 32); err == nil {
|
|
||||||
port = forwardedPort
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
if forwardedProto := r.Header.Get("X-Forwarded-Proto"); len(forwardedProto) > 0 {
|
||||||
if len(portLessHost) > 0 {
|
scheme = forwardedProto
|
||||||
host = portLessHost
|
}
|
||||||
}
|
if forwardedHost := r.Header.Get("X-Forwarded-Host"); len(forwardedHost) > 0 {
|
||||||
if len(port) > 0 {
|
// According to the Apache mod_proxy docs, X-Forwarded-Host can be a
|
||||||
// remove enclosing brackets of ipv6 address otherwise they will be duplicated
|
// comma-separated list of hosts, to which each proxy appends the
|
||||||
if len(host) > 1 && host[0] == '[' && host[len(host)-1] == ']' {
|
// requested host. We want to grab the first from this comma-separated
|
||||||
host = host[1 : len(host)-1]
|
// list.
|
||||||
|
hosts := strings.SplitN(forwardedHost, ",", 2)
|
||||||
|
host = strings.TrimSpace(hosts[0])
|
||||||
}
|
}
|
||||||
// JoinHostPort properly encloses ipv6 addresses in square brackets
|
|
||||||
host = net.JoinHostPort(host, port)
|
|
||||||
} else if isIPv6Address(host) && host[0] != '[' {
|
|
||||||
// ipv6 needs to be enclosed in square brackets in urls
|
|
||||||
host = "[" + host + "]"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
basePath := routeDescriptorsMap[RouteNameBase].Path
|
basePath := routeDescriptorsMap[RouteNameBase].Path
|
||||||
|
@ -175,6 +150,8 @@ func (ub *URLBuilder) BuildManifestURL(ref reference.Named) (string, error) {
|
||||||
tagOrDigest = v.Tag()
|
tagOrDigest = v.Tag()
|
||||||
case reference.Digested:
|
case reference.Digested:
|
||||||
tagOrDigest = v.Digest().String()
|
tagOrDigest = v.Digest().String()
|
||||||
|
default:
|
||||||
|
return "", fmt.Errorf("reference must have a tag or digest")
|
||||||
}
|
}
|
||||||
|
|
||||||
manifestURL, err := route.URL("name", ref.Name(), "reference", tagOrDigest)
|
manifestURL, err := route.URL("name", ref.Name(), "reference", tagOrDigest)
|
||||||
|
@ -287,28 +264,3 @@ func appendValues(u string, values ...url.Values) string {
|
||||||
|
|
||||||
return appendValuesURL(up, values...).String()
|
return appendValuesURL(up, values...).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// isIPv6Address returns true if given string is a valid IPv6 address. No port is allowed. The address may be
|
|
||||||
// enclosed in square brackets.
|
|
||||||
func isIPv6Address(host string) bool {
|
|
||||||
if len(host) > 1 && host[0] == '[' && host[len(host)-1] == ']' {
|
|
||||||
host = host[1 : len(host)-1]
|
|
||||||
}
|
|
||||||
// The IPv6 scoped addressing zone identifier starts after the last percent sign.
|
|
||||||
if i := strings.LastIndexByte(host, '%'); i > 0 {
|
|
||||||
host = host[:i]
|
|
||||||
}
|
|
||||||
ip := net.ParseIP(host)
|
|
||||||
if ip == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if ip.To16() == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if ip.To4() == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
// dot can be present in ipv4-mapped address, it needs to come after a colon though
|
|
||||||
i := strings.IndexAny(host, ":.")
|
|
||||||
return i >= 0 && host[i] == ':'
|
|
||||||
}
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue