mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-23 00:39:13 +02:00
update dependencies
This commit is contained in:
23
go.mod
23
go.mod
@ -10,30 +10,35 @@ require (
|
|||||||
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
|
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
|
||||||
github.com/golang/protobuf v1.3.2 // indirect
|
github.com/golang/protobuf v1.3.2 // indirect
|
||||||
github.com/google/go-cmp v0.3.1 // indirect
|
github.com/google/go-cmp v0.3.1 // indirect
|
||||||
github.com/integrii/flaggy v1.3.0
|
github.com/integrii/flaggy v1.4.0
|
||||||
github.com/jesseduffield/gocui v0.3.1-0.20191116013947-b13bda319532
|
github.com/jesseduffield/gocui v0.3.1-0.20191116013947-b13bda319532
|
||||||
github.com/jesseduffield/pty v1.2.1
|
github.com/jesseduffield/pty v1.2.1
|
||||||
github.com/jesseduffield/rollrus v0.0.0-20190701125922-dd028cb0bfd7
|
github.com/jesseduffield/rollrus v0.0.0-20190701125922-dd028cb0bfd7
|
||||||
github.com/jesseduffield/termbox-go v0.0.0-20190630083001-9dd53af7214e // indirect
|
github.com/jesseduffield/termbox-go v0.0.0-20190630083001-9dd53af7214e // indirect
|
||||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
|
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
|
||||||
|
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.4 // indirect
|
github.com/mattn/go-colorable v0.1.4 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.10 // indirect
|
github.com/mattn/go-isatty v0.0.11 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.6 // indirect
|
github.com/mattn/go-runewidth v0.0.7 // indirect
|
||||||
github.com/mgutz/str v1.2.0
|
github.com/mgutz/str v1.2.0
|
||||||
github.com/nicksnyder/go-i18n/v2 v2.0.2
|
github.com/nicksnyder/go-i18n/v2 v2.0.3
|
||||||
github.com/onsi/ginkgo v1.10.3 // indirect
|
github.com/onsi/ginkgo v1.10.3 // indirect
|
||||||
github.com/onsi/gomega v1.7.1 // indirect
|
github.com/onsi/gomega v1.7.1 // indirect
|
||||||
|
github.com/pelletier/go-toml v1.6.0 // indirect
|
||||||
github.com/shibukawa/configdir v0.0.0-20170330084843-e180dbdc8da0
|
github.com/shibukawa/configdir v0.0.0-20170330084843-e180dbdc8da0
|
||||||
github.com/sirupsen/logrus v1.4.2
|
github.com/sirupsen/logrus v1.4.2
|
||||||
github.com/spf13/viper v1.5.0
|
github.com/spf13/afero v1.2.2 // indirect
|
||||||
|
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
github.com/spf13/viper v1.6.1
|
||||||
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad
|
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
github.com/tcnksm/go-gitconfig v0.1.2
|
github.com/tcnksm/go-gitconfig v0.1.2
|
||||||
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708 // indirect
|
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 // indirect
|
||||||
golang.org/x/net v0.0.0-20191112182307-2180aed22343 // indirect
|
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
|
||||||
golang.org/x/sys v0.0.0-20191112214154-59a1497f0cea // indirect
|
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449 // indirect
|
||||||
golang.org/x/text v0.3.2
|
golang.org/x/text v0.3.2
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||||
gopkg.in/src-d/go-git.v4 v4.13.1
|
gopkg.in/src-d/go-git.v4 v4.13.1
|
||||||
gopkg.in/yaml.v2 v2.2.5
|
gopkg.in/yaml.v2 v2.2.7
|
||||||
)
|
)
|
||||||
|
60
go.sum
60
go.sum
@ -63,6 +63,8 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
|
|||||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
|
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
|
||||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
||||||
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||||
@ -71,8 +73,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
|||||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
github.com/integrii/flaggy v1.3.0 h1:8I5Qqz22C6+EwUqJuaN5ITh77obI8VSg6RwYLe2VB7o=
|
github.com/integrii/flaggy v1.4.0 h1:A1x7SYx4jqu5NSrY14z8Z+0UyX2S5ygfJJrfolWR3zM=
|
||||||
github.com/integrii/flaggy v1.3.0/go.mod h1:tnTxHeTJbah0gQ6/K0RW0J7fMUBk9MCF5blhm43LNpI=
|
github.com/integrii/flaggy v1.4.0/go.mod h1:tnTxHeTJbah0gQ6/K0RW0J7fMUBk9MCF5blhm43LNpI=
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
||||||
github.com/jesseduffield/gocui v0.3.1-0.20191116013947-b13bda319532 h1:V1Lk2rm5/p27NjnlF2ezzkxDaisHNcveMNueSD7RYgs=
|
github.com/jesseduffield/gocui v0.3.1-0.20191116013947-b13bda319532 h1:V1Lk2rm5/p27NjnlF2ezzkxDaisHNcveMNueSD7RYgs=
|
||||||
@ -87,6 +89,8 @@ github.com/jesseduffield/termbox-go v0.0.0-20190630083001-9dd53af7214e h1:tth7wr
|
|||||||
github.com/jesseduffield/termbox-go v0.0.0-20190630083001-9dd53af7214e/go.mod h1:anMibpZtqNxjDbxrcDEAwSdaJ37vyUeM1f/M4uekib4=
|
github.com/jesseduffield/termbox-go v0.0.0-20190630083001-9dd53af7214e/go.mod h1:anMibpZtqNxjDbxrcDEAwSdaJ37vyUeM1f/M4uekib4=
|
||||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||||
|
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||||
|
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
|
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
|
||||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
|
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
|
||||||
@ -96,6 +100,8 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW
|
|||||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
|
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
|
||||||
|
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
@ -108,10 +114,10 @@ github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP
|
|||||||
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
|
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
|
||||||
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
|
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
||||||
github.com/mattn/go-runewidth v0.0.6 h1:V2iyH+aX9C5fsYCpK60U8BYIvmhqxuOL3JZcqc1NB7k=
|
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
|
||||||
github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
github.com/mgutz/str v1.2.0 h1:4IzWSdIz9qPQWLfKZ0rJcV0jcUDpxvP4JVZ4GXQyvSw=
|
github.com/mgutz/str v1.2.0 h1:4IzWSdIz9qPQWLfKZ0rJcV0jcUDpxvP4JVZ4GXQyvSw=
|
||||||
github.com/mgutz/str v1.2.0/go.mod h1:w1v0ofgLaJdoD0HpQ3fycxKD1WtxpjSo151pK/31q6w=
|
github.com/mgutz/str v1.2.0/go.mod h1:w1v0ofgLaJdoD0HpQ3fycxKD1WtxpjSo151pK/31q6w=
|
||||||
@ -120,8 +126,8 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
|
|||||||
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
|
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
|
||||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||||
github.com/nicksnyder/go-i18n/v2 v2.0.2 h1:KsHGcTByIM0mHZKQGy0nlJLOjPNjQ6MVib/3PvsBDNY=
|
github.com/nicksnyder/go-i18n/v2 v2.0.3 h1:ks/JkQiOEhhuF6jpNvx+Wih1NIiXzUnZeZVnJuI8R8M=
|
||||||
github.com/nicksnyder/go-i18n/v2 v2.0.2/go.mod h1:JXS4+OKhbcwDoVTEj0sLFWL1vOwec2g/YBAxZ9owJqY=
|
github.com/nicksnyder/go-i18n/v2 v2.0.3/go.mod h1:oDab7q8XCYMRlcrBnaY/7B1eOectbvj6B1UPBT+p5jo=
|
||||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
github.com/onsi/ginkgo v1.10.3 h1:OoxbjfXVZyod1fmWYhI7SEyaD8B00ynP3T+D5GiyHOY=
|
github.com/onsi/ginkgo v1.10.3 h1:OoxbjfXVZyod1fmWYhI7SEyaD8B00ynP3T+D5GiyHOY=
|
||||||
@ -131,6 +137,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
|
|||||||
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
|
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
|
||||||
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
|
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
|
||||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||||
|
github.com/pelletier/go-toml v1.6.0 h1:aetoXYr0Tv7xRU/V4B4IZJ2QcbtMUFoNb3ORp7TzIK4=
|
||||||
|
github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys=
|
||||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
@ -154,18 +162,28 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
|
|||||||
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||||
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
||||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||||
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||||
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||||
|
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
||||||
|
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||||
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
|
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
|
||||||
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
||||||
|
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
|
||||||
|
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
|
||||||
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
|
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
|
||||||
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||||
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
|
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
|
||||||
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
|
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
|
||||||
|
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
|
||||||
|
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
|
||||||
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
|
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
|
||||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||||
github.com/spf13/viper v1.5.0 h1:GpsTwfsQ27oS/Aha/6d1oD7tpKIqWnOA6tgOX9HHkt4=
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
github.com/spf13/viper v1.5.0/go.mod h1:AkYRkVJF8TkSG/xet6PzXX+l39KhhXa2pdqVSxnTcn4=
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
|
github.com/spf13/viper v1.6.1 h1:VPZzIkznI1YhVMRi6vNFLHSwhnhReBfgTxIPccpfdZk=
|
||||||
|
github.com/spf13/viper v1.6.1/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k=
|
||||||
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad h1:fiWzISvDn0Csy5H0iwgAuJGQTUpVfEMJJd4nRFXogbc=
|
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad h1:fiWzISvDn0Csy5H0iwgAuJGQTUpVfEMJJd4nRFXogbc=
|
||||||
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
|
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
|
||||||
github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=
|
github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=
|
||||||
@ -197,8 +215,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
|||||||
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
|
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
|
||||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708 h1:pXVtWnwHkrWD9ru3sDxY/qFK/bfc0egRovX91EjWjf4=
|
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 h1:ULYEB3JvPRE/IfO+9uO7vKV/xzVTO7XPAwm8xbf4w2g=
|
||||||
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
@ -212,8 +230,8 @@ golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR
|
|||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
|
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
|
||||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20191112182307-2180aed22343 h1:00ohfJ4K98s3m6BGUoBd8nyfp4Yl0GoIKvw5abItTjI=
|
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8=
|
||||||
golang.org/x/net v0.0.0-20191112182307-2180aed22343/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
@ -232,10 +250,9 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qqCB4teTffacDWr7CI+0=
|
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qqCB4teTffacDWr7CI+0=
|
||||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU=
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449 h1:gSbV7h1NRL2G1xTg/owz62CST1oJBmxy4QpMMregXVQ=
|
||||||
golang.org/x/sys v0.0.0-20191112214154-59a1497f0cea h1:Mz1TMnfJDRJLk8S8OPCoJYgrsp/Se/2TBre2+vwX128=
|
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191112214154-59a1497f0cea/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
@ -244,6 +261,7 @@ golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGm
|
|||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
|
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
|
||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
@ -258,6 +276,8 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogR
|
|||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||||
|
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
|
||||||
|
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||||
gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg=
|
gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg=
|
||||||
gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98=
|
gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98=
|
||||||
@ -273,6 +293,6 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl
|
|||||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c=
|
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
|
||||||
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
2
vendor/github.com/integrii/flaggy/.gitignore
generated
vendored
2
vendor/github.com/integrii/flaggy/.gitignore
generated
vendored
@ -12,3 +12,5 @@
|
|||||||
|
|
||||||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
||||||
.glide/
|
.glide/
|
||||||
|
|
||||||
|
.idea/
|
||||||
|
34
vendor/github.com/integrii/flaggy/README.md
generated
vendored
34
vendor/github.com/integrii/flaggy/README.md
generated
vendored
@ -172,41 +172,57 @@ Other more specific types can also be used as flag types. They will be automati
|
|||||||
- time.Duration
|
- time.Duration
|
||||||
- []time.Duration
|
- []time.Duration
|
||||||
|
|
||||||
# Recommended Program Structure
|
# An Example Program
|
||||||
|
|
||||||
Best practice when using flaggy includes setting your program's name, description, and version (at build time).
|
Best practice when using flaggy includes setting your program's name, description, and version (at build time) as shown in this example program.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/integrii/flaggy"
|
import "github.com/integrii/flaggy"
|
||||||
|
|
||||||
// make a variable for the version which will be set at build time
|
// Make a variable for the version which will be set at build time.
|
||||||
var version = "unknown"
|
var version = "unknown"
|
||||||
|
|
||||||
// keep subcommands as globals so you can easily check if they were used later on
|
// Keep subcommands as globals so you can easily check if they were used later on.
|
||||||
var mySubcommand *flaggy.Subcommand
|
var mySubcommand *flaggy.Subcommand
|
||||||
|
|
||||||
|
// Setup the variables you want your incoming flags to set.
|
||||||
|
var testVar string
|
||||||
|
|
||||||
|
// If you would like an environment variable as the default for a value, just populate the flag
|
||||||
|
// with the value of the environment by default. If the flag corresponding to this value is not
|
||||||
|
// used, then it will not be changed.
|
||||||
|
var myVar = os.Getenv("MY_VAR")
|
||||||
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Set your program's name and description. These appear in help output.
|
// Set your program's name and description. These appear in help output.
|
||||||
flaggy.SetName("Test Program")
|
flaggy.SetName("Test Program")
|
||||||
flaggy.SetDescription("A little example program")
|
flaggy.SetDescription("A little example program")
|
||||||
|
|
||||||
// you can disable various things by changing bools on the default parser
|
// You can disable various things by changing bools on the default parser
|
||||||
// (or your own parser if you have created one)
|
// (or your own parser if you have created one).
|
||||||
flaggy.DefaultParser.ShowHelpOnUnexpected = false
|
flaggy.DefaultParser.ShowHelpOnUnexpected = false
|
||||||
|
|
||||||
// you can set a help prepend or append on the default parser
|
// You can set a help prepend or append on the default parser.
|
||||||
flaggy.DefaultParser.AdditionalHelpPrepend = "http://github.com/integrii/flaggy"
|
flaggy.DefaultParser.AdditionalHelpPrepend = "http://github.com/integrii/flaggy"
|
||||||
|
|
||||||
|
// Add a flag to the main program (this will be available in all subcommands as well).
|
||||||
|
flaggy.String(&testVar, "tv", "testVariable", "A variable just for testing things!")
|
||||||
|
|
||||||
// create any subcommands and set their parameters
|
// Create any subcommands and set their parameters.
|
||||||
mySubcommand = flaggy.NewSubcommand("mySubcommand")
|
mySubcommand = flaggy.NewSubcommand("mySubcommand")
|
||||||
mySubcommand.Description = "My great subcommand!"
|
mySubcommand.Description = "My great subcommand!"
|
||||||
|
|
||||||
|
// Add a flag to the subcommand.
|
||||||
|
mySubcommand.String(&myVar, "mv", "myVariable", "A variable just for me!")
|
||||||
|
|
||||||
// set the version and parse all inputs into variables
|
// Set the version and parse all inputs into variables.
|
||||||
flaggy.SetVersion(version)
|
flaggy.SetVersion(version)
|
||||||
flaggy.Parse()
|
flaggy.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
func main(){
|
func main(){
|
||||||
if mySubcommand.Used {
|
if mySubcommand.Used {
|
||||||
...
|
...
|
||||||
|
8
vendor/github.com/integrii/flaggy/argumentParser.go
generated
vendored
8
vendor/github.com/integrii/flaggy/argumentParser.go
generated
vendored
@ -5,22 +5,20 @@ package flaggy
|
|||||||
// The return values represent the key being set, and any errors
|
// The return values represent the key being set, and any errors
|
||||||
// returned when setting the key, such as failures to convert the string
|
// returned when setting the key, such as failures to convert the string
|
||||||
// into the appropriate flag value. We stop assigning values as soon
|
// into the appropriate flag value. We stop assigning values as soon
|
||||||
// as we find a parser that accepts it.
|
// as we find a any parser that accepts it.
|
||||||
func setValueForParsers(key string, value string, parsers ...ArgumentParser) (bool, error) {
|
func setValueForParsers(key string, value string, parsers ...ArgumentParser) (bool, error) {
|
||||||
|
|
||||||
var valueWasSet bool
|
|
||||||
|
|
||||||
for _, p := range parsers {
|
for _, p := range parsers {
|
||||||
valueWasSet, err := p.SetValueForKey(key, value)
|
valueWasSet, err := p.SetValueForKey(key, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return valueWasSet, err
|
return valueWasSet, err
|
||||||
}
|
}
|
||||||
if valueWasSet {
|
if valueWasSet {
|
||||||
break
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return valueWasSet, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ArgumentParser represents a parser or subcommand
|
// ArgumentParser represents a parser or subcommand
|
||||||
|
12
vendor/github.com/integrii/flaggy/main.go
generated
vendored
12
vendor/github.com/integrii/flaggy/main.go
generated
vendored
@ -327,6 +327,18 @@ func exitOrPanic(code int) {
|
|||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ShowHelpOnUnexpectedEnable enables the ShowHelpOnUnexpected behavior on the
|
||||||
|
// default parser. This causes unknown inputs to error out.
|
||||||
|
func ShowHelpOnUnexpectedEnable() {
|
||||||
|
DefaultParser.ShowHelpOnUnexpected = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShowHelpOnUnexpectedDisable disables the ShowHelpOnUnexpected behavior on the
|
||||||
|
// default parser. This causes unknown inputs to error out.
|
||||||
|
func ShowHelpOnUnexpectedDisable() {
|
||||||
|
DefaultParser.ShowHelpOnUnexpected = false
|
||||||
|
}
|
||||||
|
|
||||||
// AddPositionalValue adds a positional value to the main parser at the global
|
// AddPositionalValue adds a positional value to the main parser at the global
|
||||||
// context
|
// context
|
||||||
func AddPositionalValue(assignmentVar *string, name string, relativePosition int, required bool, description string) {
|
func AddPositionalValue(assignmentVar *string, name string, relativePosition int, required bool, description string) {
|
||||||
|
23
vendor/github.com/integrii/flaggy/parsedValue.go
generated
vendored
Normal file
23
vendor/github.com/integrii/flaggy/parsedValue.go
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package flaggy
|
||||||
|
|
||||||
|
// parsedValue represents a flag or subcommand that was parsed. Primairily used
|
||||||
|
// to account for all parsed values in order to determine if unknown values were
|
||||||
|
// passed to the root parser after all subcommands have been parsed.
|
||||||
|
type parsedValue struct {
|
||||||
|
Key string
|
||||||
|
Value string
|
||||||
|
IsPositional bool // indicates that this value was positional and not a key/value
|
||||||
|
}
|
||||||
|
|
||||||
|
// newParsedValue creates and returns a new parsedValue struct with the
|
||||||
|
// supplied values set
|
||||||
|
func newParsedValue(key string, value string, isPositional bool) parsedValue {
|
||||||
|
if len(key) == 0 && len(value) == 0 {
|
||||||
|
panic("cant add parsed value with no key or value")
|
||||||
|
}
|
||||||
|
return parsedValue{
|
||||||
|
Key: key,
|
||||||
|
Value: value,
|
||||||
|
IsPositional: isPositional,
|
||||||
|
}
|
||||||
|
}
|
96
vendor/github.com/integrii/flaggy/parser.go
generated
vendored
96
vendor/github.com/integrii/flaggy/parser.go
generated
vendored
@ -4,18 +4,20 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parser represents the set of vars and subcommands we are expecting
|
// Parser represents the set of flags and subcommands we are expecting
|
||||||
// from our input args, and the parser than handles them all.
|
// from our input arguments. Parser is the top level struct responsible for
|
||||||
|
// parsing an entire set of subcommands and flags.
|
||||||
type Parser struct {
|
type Parser struct {
|
||||||
Subcommand
|
Subcommand
|
||||||
Version string // the optional version of the parser.
|
Version string // the optional version of the parser.
|
||||||
ShowHelpWithHFlag bool // display help when -h or --help passed
|
ShowHelpWithHFlag bool // display help when -h or --help passed
|
||||||
ShowVersionWithVersionFlag bool // display the version when --version passed
|
ShowVersionWithVersionFlag bool // display the version when --version passed
|
||||||
ShowHelpOnUnexpected bool // display help when an unexpected flag is passed
|
ShowHelpOnUnexpected bool // display help when an unexpected flag or subcommand is passed
|
||||||
TrailingArguments []string // everything after a -- is placed here
|
TrailingArguments []string // everything after a -- is placed here
|
||||||
HelpTemplate *template.Template // template for Help output
|
HelpTemplate *template.Template // template for Help output
|
||||||
trailingArgumentsExtracted bool // indicates that trailing args have been parsed and should not be appended again
|
trailingArgumentsExtracted bool // indicates that trailing args have been parsed and should not be appended again
|
||||||
@ -46,8 +48,89 @@ func (p *Parser) ParseArgs(args []string) error {
|
|||||||
return errors.New("Parser.Parse() called twice on parser with name: " + " " + p.Name + " " + p.ShortName)
|
return errors.New("Parser.Parse() called twice on parser with name: " + " " + p.Name + " " + p.ShortName)
|
||||||
}
|
}
|
||||||
p.parsed = true
|
p.parsed = true
|
||||||
// debugPrint("Kicking off parsing with args:", args)
|
|
||||||
return p.parse(p, args, 0)
|
debugPrint("Kicking off parsing with args:", args)
|
||||||
|
err := p.parse(p, args, 0)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we are set to crash on unexpected args, look for those here TODO
|
||||||
|
if p.ShowHelpOnUnexpected {
|
||||||
|
parsedValues := p.findAllParsedValues()
|
||||||
|
debugPrint("parsedValues:", parsedValues)
|
||||||
|
argsNotParsed := findArgsNotInParsedValues(args, parsedValues)
|
||||||
|
if len(argsNotParsed) > 0 {
|
||||||
|
// flatten out unused args for our error message
|
||||||
|
var argsNotParsedFlat string
|
||||||
|
for _, a := range argsNotParsed {
|
||||||
|
argsNotParsedFlat = argsNotParsedFlat + " " + a
|
||||||
|
}
|
||||||
|
p.ShowHelpAndExit("Unknown arguments supplied: " + argsNotParsedFlat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// findArgsNotInParsedValues finds arguments not used in parsed values. The
|
||||||
|
// incoming args should be in the order supplied by the user and should not
|
||||||
|
// include the invoked binary, which is normally the first thing in os.Args.
|
||||||
|
func findArgsNotInParsedValues(args []string, parsedValues []parsedValue) []string {
|
||||||
|
var argsNotUsed []string
|
||||||
|
var skipNext bool
|
||||||
|
for _, a := range args {
|
||||||
|
|
||||||
|
// if the final argument (--) is seen, then we stop checking because all
|
||||||
|
// further values are trailing arguments.
|
||||||
|
if determineArgType(a) == argIsFinal {
|
||||||
|
return argsNotUsed
|
||||||
|
}
|
||||||
|
|
||||||
|
// allow for skipping the next arg when needed
|
||||||
|
if skipNext {
|
||||||
|
skipNext = false
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// strip flag slashes from incoming arguments so they match up with the
|
||||||
|
// keys from parsedValues.
|
||||||
|
arg := parseFlagToName(a)
|
||||||
|
|
||||||
|
// indicates that we found this arg used in one of the parsed values. Used
|
||||||
|
// to indicate which values should be added to argsNotUsed.
|
||||||
|
var foundArgUsed bool
|
||||||
|
|
||||||
|
// search all args for a corresponding parsed value
|
||||||
|
for _, pv := range parsedValues {
|
||||||
|
// this argumenet was a key
|
||||||
|
// debugPrint(pv.Key, "==", arg)
|
||||||
|
debugPrint(pv.Key + "==" + arg + " || (" + strconv.FormatBool(pv.IsPositional) + " && " + pv.Value + " == " + arg + ")")
|
||||||
|
if pv.Key == arg || (pv.IsPositional && pv.Value == arg) {
|
||||||
|
debugPrint("Found matching parsed arg for " + pv.Key)
|
||||||
|
foundArgUsed = true // the arg was used in this parsedValues set
|
||||||
|
// if the value is not a positional value and the parsed value had a
|
||||||
|
// value that was not blank, we skip the next value in the argument list
|
||||||
|
if !pv.IsPositional && len(pv.Value) > 0 {
|
||||||
|
skipNext = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// this prevents excessive parsed values from being checked after we find
|
||||||
|
// the arg used for the first time
|
||||||
|
if foundArgUsed {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the arg was not used in any parsed values, then we add it to the slice
|
||||||
|
// of arguments not used
|
||||||
|
if !foundArgUsed {
|
||||||
|
argsNotUsed = append(argsNotUsed, arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return argsNotUsed
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShowVersionAndExit shows the version of this parser
|
// ShowVersionAndExit shows the version of this parser
|
||||||
@ -105,7 +188,8 @@ func (p *Parser) ShowHelpWithMessage(message string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable show version with --version. It is enabled by default.
|
// DisableShowVersionWithVersion disables the showing of version information
|
||||||
|
// with --version. It is enabled by default.
|
||||||
func (p *Parser) DisableShowVersionWithVersion() {
|
func (p *Parser) DisableShowVersionWithVersion() {
|
||||||
p.ShowVersionWithVersionFlag = false
|
p.ShowVersionWithVersionFlag = false
|
||||||
}
|
}
|
||||||
|
109
vendor/github.com/integrii/flaggy/subCommand.go
generated
vendored
109
vendor/github.com/integrii/flaggy/subCommand.go
generated
vendored
@ -23,15 +23,20 @@ type Subcommand struct {
|
|||||||
Subcommands []*Subcommand
|
Subcommands []*Subcommand
|
||||||
Flags []*Flag
|
Flags []*Flag
|
||||||
PositionalFlags []*PositionalValue
|
PositionalFlags []*PositionalValue
|
||||||
AdditionalHelpPrepend string // additional prepended message when Help is displayed
|
ParsedValues []parsedValue // a list of values and positionals parsed
|
||||||
AdditionalHelpAppend string // additional appended message when Help is displayed
|
AdditionalHelpPrepend string // additional prepended message when Help is displayed
|
||||||
Used bool // indicates this subcommand was found and parsed
|
AdditionalHelpAppend string // additional appended message when Help is displayed
|
||||||
Hidden bool // indicates this subcommand should be hidden from help
|
Used bool // indicates this subcommand was found and parsed
|
||||||
|
Hidden bool // indicates this subcommand should be hidden from help
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSubcommand creates a new subcommand that can have flags or PositionalFlags
|
// NewSubcommand creates a new subcommand that can have flags or PositionalFlags
|
||||||
// added to it. The position starts with 1, not 0
|
// added to it. The position starts with 1, not 0
|
||||||
func NewSubcommand(name string) *Subcommand {
|
func NewSubcommand(name string) *Subcommand {
|
||||||
|
if len(name) == 0 {
|
||||||
|
fmt.Fprintln(os.Stderr, "Error creating subcommand (NewSubcommand()). No subcommand name was specified.")
|
||||||
|
exitOrPanic(2)
|
||||||
|
}
|
||||||
newSC := &Subcommand{
|
newSC := &Subcommand{
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
@ -39,10 +44,11 @@ func NewSubcommand(name string) *Subcommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parseAllFlagsFromArgs parses the non-positional flags such as -f or -v=value
|
// parseAllFlagsFromArgs parses the non-positional flags such as -f or -v=value
|
||||||
// out of the supplied args and returns the positional items in order.
|
// out of the supplied args and returns the resulting positional items in order,
|
||||||
|
// all the flag names found (without values), a bool to indicate if help was
|
||||||
|
// requested, and any errors found during parsing
|
||||||
func (sc *Subcommand) parseAllFlagsFromArgs(p *Parser, args []string) ([]string, bool, error) {
|
func (sc *Subcommand) parseAllFlagsFromArgs(p *Parser, args []string) ([]string, bool, error) {
|
||||||
|
|
||||||
var err error
|
|
||||||
var positionalOnlyArguments []string
|
var positionalOnlyArguments []string
|
||||||
var helpRequested bool // indicates the user has supplied -h and we
|
var helpRequested bool // indicates the user has supplied -h and we
|
||||||
// should render help if we are the last subcommand
|
// should render help if we are the last subcommand
|
||||||
@ -58,7 +64,7 @@ func (sc *Subcommand) parseAllFlagsFromArgs(p *Parser, args []string) ([]string,
|
|||||||
// find all the normal flags (not positional) and parse them out
|
// find all the normal flags (not positional) and parse them out
|
||||||
for i, a := range args {
|
for i, a := range args {
|
||||||
|
|
||||||
debugPrint("parsing arg", 1, a)
|
debugPrint("parsing arg:", a)
|
||||||
|
|
||||||
// evaluate if there is a following arg to avoid panics
|
// evaluate if there is a following arg to avoid panics
|
||||||
var nextArgExists bool
|
var nextArgExists bool
|
||||||
@ -121,62 +127,107 @@ func (sc *Subcommand) parseAllFlagsFromArgs(p *Parser, args []string) ([]string,
|
|||||||
// this positional argument into a slice of their own, so that
|
// this positional argument into a slice of their own, so that
|
||||||
// we can determine if its a subcommand or positional value later
|
// we can determine if its a subcommand or positional value later
|
||||||
positionalOnlyArguments = append(positionalOnlyArguments, a)
|
positionalOnlyArguments = append(positionalOnlyArguments, a)
|
||||||
case argIsFlagWithSpace:
|
// track this as a parsed value with the subcommand
|
||||||
|
sc.addParsedPositionalValue(a)
|
||||||
|
case argIsFlagWithSpace: // a flag with a space. ex) -k v or --key value
|
||||||
a = parseFlagToName(a)
|
a = parseFlagToName(a)
|
||||||
|
|
||||||
// debugPrint("Arg", i, "is flag with space:", a)
|
// debugPrint("Arg", i, "is flag with space:", a)
|
||||||
// parse next arg as value to this flag and apply to subcommand flags
|
// parse next arg as value to this flag and apply to subcommand flags
|
||||||
// if the flag is a bool flag, then we check for a following positional
|
// if the flag is a bool flag, then we check for a following positional
|
||||||
// and skip it if necessary
|
// and skip it if necessary
|
||||||
if flagIsBool(sc, p, a) {
|
if flagIsBool(sc, p, a) {
|
||||||
debugPrint(sc.Name, "bool flag", a, "next var is:", nextArg)
|
debugPrint(sc.Name, "bool flag", a, "next var is:", nextArg)
|
||||||
_, err = setValueForParsers(a, "true", p, sc)
|
// set the value in this subcommand and its root parser
|
||||||
|
valueSet, err := setValueForParsers(a, "true", p, sc)
|
||||||
|
|
||||||
// if an error occurs, just return it and quit parsing
|
// if an error occurs, just return it and quit parsing
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []string{}, false, err
|
return []string{}, false, err
|
||||||
}
|
}
|
||||||
// by default, we just assign the next argument to the value and continue
|
|
||||||
|
// log all values parsed by this subcommand. We leave the value blank
|
||||||
|
// because the bool value had no explicit true or false supplied
|
||||||
|
if valueSet {
|
||||||
|
sc.addParsedFlag(a, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
// we've found and set a standalone bool flag, so we move on to the next
|
||||||
|
// argument in the list of arguments
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
skipNext = true
|
skipNext = true
|
||||||
debugPrint(sc.Name, "NOT bool flag", a)
|
// debugPrint(sc.Name, "NOT bool flag", a)
|
||||||
|
|
||||||
// if the next arg was not found, then show a Help message
|
// if the next arg was not found, then show a Help message
|
||||||
if !nextArgExists {
|
if !nextArgExists {
|
||||||
p.ShowHelpWithMessage("Expected a following arg for flag " + a + ", but it did not exist.")
|
p.ShowHelpWithMessage("Expected a following arg for flag " + a + ", but it did not exist.")
|
||||||
exitOrPanic(2)
|
exitOrPanic(2)
|
||||||
}
|
}
|
||||||
_, err = setValueForParsers(a, nextArg, p, sc)
|
valueSet, err := setValueForParsers(a, nextArg, p, sc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []string{}, false, err
|
return []string{}, false, err
|
||||||
}
|
}
|
||||||
case argIsFlagWithValue:
|
|
||||||
|
// log all parsed values in the subcommand
|
||||||
|
if valueSet {
|
||||||
|
sc.addParsedFlag(a, nextArg)
|
||||||
|
}
|
||||||
|
case argIsFlagWithValue: // a flag with an equals sign. ex) -k=v or --key=value
|
||||||
// debugPrint("Arg", i, "is flag with value:", a)
|
// debugPrint("Arg", i, "is flag with value:", a)
|
||||||
a = parseFlagToName(a)
|
a = parseFlagToName(a)
|
||||||
|
|
||||||
// parse flag into key and value and apply to subcommand flags
|
// parse flag into key and value and apply to subcommand flags
|
||||||
key, val := parseArgWithValue(a)
|
key, val := parseArgWithValue(a)
|
||||||
_, err = setValueForParsers(key, val, p, sc)
|
|
||||||
|
// set the value in this subcommand and its root parser
|
||||||
|
valueSet, err := setValueForParsers(key, val, p, sc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []string{}, false, err
|
return []string{}, false, err
|
||||||
}
|
}
|
||||||
// if this flag type was found and not set, and the parser is set to show
|
|
||||||
// Help when an unknown flag is found, then show Help and exit.
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// log all values parsed by the subcommand
|
||||||
|
if valueSet {
|
||||||
|
sc.addParsedFlag(a, val)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return positionalOnlyArguments, helpRequested, nil
|
return positionalOnlyArguments, helpRequested, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse causes the argument parser to parse based on the supplied []string.
|
// findAllParsedValues finds all values parsed by all subcommands and this
|
||||||
// depth specifies the non-flag subcommand positional depth
|
// subcommand and its child subcommands
|
||||||
|
func (sc *Subcommand) findAllParsedValues() []parsedValue {
|
||||||
|
parsedValues := sc.ParsedValues
|
||||||
|
for _, sc := range sc.Subcommands {
|
||||||
|
// skip unused subcommands
|
||||||
|
if !sc.Used {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
parsedValues = append(parsedValues, sc.findAllParsedValues()...)
|
||||||
|
}
|
||||||
|
return parsedValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse causes the argument parser to parse based on the supplied []string.
|
||||||
|
// depth specifies the non-flag subcommand positional depth. A slice of flags
|
||||||
|
// and subcommands parsed is returned so that the parser can ultimately decide
|
||||||
|
// if there were any unexpected values supplied by the user
|
||||||
func (sc *Subcommand) parse(p *Parser, args []string, depth int) error {
|
func (sc *Subcommand) parse(p *Parser, args []string, depth int) error {
|
||||||
|
|
||||||
debugPrint("- Parsing subcommand", sc.Name, "with depth of", depth, "and args", args)
|
debugPrint("- Parsing subcommand", sc.Name, "with depth of", depth, "and args", args)
|
||||||
|
|
||||||
// if a command is parsed, its used
|
// if a command is parsed, its used
|
||||||
sc.Used = true
|
sc.Used = true
|
||||||
|
debugPrint("used subcommand", sc.Name, sc.ShortName)
|
||||||
|
if len(sc.Name) > 0 {
|
||||||
|
sc.addParsedPositionalValue(sc.Name)
|
||||||
|
}
|
||||||
|
if len(sc.ShortName) > 0 {
|
||||||
|
sc.addParsedPositionalValue(sc.ShortName)
|
||||||
|
}
|
||||||
|
|
||||||
// as subcommands are used, they become the context of the parser. This helps
|
// as subcommands are used, they become the context of the parser. This helps
|
||||||
// us understand how to display help based on which subcommand is being used
|
// us understand how to display help based on which subcommand is being used
|
||||||
@ -191,9 +242,10 @@ func (sc *Subcommand) parse(p *Parser, args []string, depth int) error {
|
|||||||
sc.ensureNoConflictWithBuiltinVersion()
|
sc.ensureNoConflictWithBuiltinVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the normal flags out of the argument list and retain the positionals.
|
// Parse the normal flags out of the argument list and return the positionals
|
||||||
// Apply the flags to the parent parser and the current subcommand context.
|
// (subcommands and positional values), along with the flags used.
|
||||||
// ./command -f -z subcommand someVar -b becomes ./command subcommand somevar
|
// Then the flag values are applied to the parent parser and the current
|
||||||
|
// subcommand being parsed.
|
||||||
positionalOnlyArguments, helpRequested, err := sc.parseAllFlagsFromArgs(p, args)
|
positionalOnlyArguments, helpRequested, err := sc.parseAllFlagsFromArgs(p, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -292,7 +344,7 @@ func (sc *Subcommand) parse(p *Parser, args []string, depth int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// find any positionals that were not used on subcommands that were
|
// find any positionals that were not used on subcommands that were
|
||||||
// found and throw help (unknown argument)
|
// found and throw help (unknown argument) in the global parse or subcommand
|
||||||
for _, pv := range p.PositionalFlags {
|
for _, pv := range p.PositionalFlags {
|
||||||
if pv.Required && !pv.Found {
|
if pv.Required && !pv.Found {
|
||||||
p.ShowHelpWithMessage("Required global positional variable " + pv.Name + " not found at position " + strconv.Itoa(pv.Position))
|
p.ShowHelpWithMessage("Required global positional variable " + pv.Name + " not found at position " + strconv.Itoa(pv.Position))
|
||||||
@ -309,6 +361,17 @@ func (sc *Subcommand) parse(p *Parser, args []string, depth int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// addParsedFlag makes it easy to append flag values parsed by the subcommand
|
||||||
|
func (sc *Subcommand) addParsedFlag(key string, value string) {
|
||||||
|
sc.ParsedValues = append(sc.ParsedValues, newParsedValue(key, value, false))
|
||||||
|
}
|
||||||
|
|
||||||
|
// addParsedPositionalValue makes it easy to append positionals parsed by the
|
||||||
|
// subcommand
|
||||||
|
func (sc *Subcommand) addParsedPositionalValue(value string) {
|
||||||
|
sc.ParsedValues = append(sc.ParsedValues, newParsedValue("", value, true))
|
||||||
|
}
|
||||||
|
|
||||||
// FlagExists lets you know if the flag name exists as either a short or long
|
// FlagExists lets you know if the flag name exists as either a short or long
|
||||||
// name in the (sub)command
|
// name in the (sub)command
|
||||||
func (sc *Subcommand) FlagExists(name string) bool {
|
func (sc *Subcommand) FlagExists(name string) bool {
|
||||||
|
10
vendor/github.com/jesseduffield/pty/types.go
generated
vendored
10
vendor/github.com/jesseduffield/pty/types.go
generated
vendored
@ -1,10 +0,0 @@
|
|||||||
// +build ignore
|
|
||||||
|
|
||||||
package pty
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
type (
|
|
||||||
_C_int C.int
|
|
||||||
_C_uint C.uint
|
|
||||||
)
|
|
17
vendor/github.com/jesseduffield/pty/types_dragonfly.go
generated
vendored
17
vendor/github.com/jesseduffield/pty/types_dragonfly.go
generated
vendored
@ -1,17 +0,0 @@
|
|||||||
// +build ignore
|
|
||||||
|
|
||||||
package pty
|
|
||||||
|
|
||||||
/*
|
|
||||||
#define _KERNEL
|
|
||||||
#include <sys/conf.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/filio.h>
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
const (
|
|
||||||
_C_SPECNAMELEN = C.SPECNAMELEN /* max length of devicename */
|
|
||||||
)
|
|
||||||
|
|
||||||
type fiodgnameArg C.struct_fiodname_args
|
|
15
vendor/github.com/jesseduffield/pty/types_freebsd.go
generated
vendored
15
vendor/github.com/jesseduffield/pty/types_freebsd.go
generated
vendored
@ -1,15 +0,0 @@
|
|||||||
// +build ignore
|
|
||||||
|
|
||||||
package pty
|
|
||||||
|
|
||||||
/*
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/filio.h>
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
const (
|
|
||||||
_C_SPECNAMELEN = C.SPECNAMELEN /* max length of devicename */
|
|
||||||
)
|
|
||||||
|
|
||||||
type fiodgnameArg C.struct_fiodgname_arg
|
|
14
vendor/github.com/jesseduffield/pty/types_openbsd.go
generated
vendored
14
vendor/github.com/jesseduffield/pty/types_openbsd.go
generated
vendored
@ -1,14 +0,0 @@
|
|||||||
// +build ignore
|
|
||||||
|
|
||||||
package pty
|
|
||||||
|
|
||||||
/*
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/tty.h>
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
type ptmget C.struct_ptmget
|
|
||||||
|
|
||||||
var ioctl_PTMGET = C.PTMGET
|
|
39
vendor/github.com/jesseduffield/termbox-go/syscalls.go
generated
vendored
39
vendor/github.com/jesseduffield/termbox-go/syscalls.go
generated
vendored
@ -1,39 +0,0 @@
|
|||||||
// +build ignore
|
|
||||||
|
|
||||||
package termbox
|
|
||||||
|
|
||||||
/*
|
|
||||||
#include <termios.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
type syscall_Termios C.struct_termios
|
|
||||||
|
|
||||||
const (
|
|
||||||
syscall_IGNBRK = C.IGNBRK
|
|
||||||
syscall_BRKINT = C.BRKINT
|
|
||||||
syscall_PARMRK = C.PARMRK
|
|
||||||
syscall_ISTRIP = C.ISTRIP
|
|
||||||
syscall_INLCR = C.INLCR
|
|
||||||
syscall_IGNCR = C.IGNCR
|
|
||||||
syscall_ICRNL = C.ICRNL
|
|
||||||
syscall_IXON = C.IXON
|
|
||||||
syscall_OPOST = C.OPOST
|
|
||||||
syscall_ECHO = C.ECHO
|
|
||||||
syscall_ECHONL = C.ECHONL
|
|
||||||
syscall_ICANON = C.ICANON
|
|
||||||
syscall_ISIG = C.ISIG
|
|
||||||
syscall_IEXTEN = C.IEXTEN
|
|
||||||
syscall_CSIZE = C.CSIZE
|
|
||||||
syscall_PARENB = C.PARENB
|
|
||||||
syscall_CS8 = C.CS8
|
|
||||||
syscall_VMIN = C.VMIN
|
|
||||||
syscall_VTIME = C.VTIME
|
|
||||||
|
|
||||||
// on darwin change these to (on *bsd too?):
|
|
||||||
// C.TIOCGETA
|
|
||||||
// C.TIOCSETA
|
|
||||||
syscall_TCGETS = C.TCGETS
|
|
||||||
syscall_TCSETS = C.TCSETS
|
|
||||||
)
|
|
1
vendor/github.com/konsorten/go-windows-terminal-sequences/README.md
generated
vendored
1
vendor/github.com/konsorten/go-windows-terminal-sequences/README.md
generated
vendored
@ -26,6 +26,7 @@ The tool is sponsored by the [marvin + konsorten GmbH](http://www.konsorten.de).
|
|||||||
We thank all the authors who provided code to this library:
|
We thank all the authors who provided code to this library:
|
||||||
|
|
||||||
* Felix Kollmann
|
* Felix Kollmann
|
||||||
|
* Nicolas Perraut
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
11
vendor/github.com/konsorten/go-windows-terminal-sequences/sequences_dummy.go
generated
vendored
Normal file
11
vendor/github.com/konsorten/go-windows-terminal-sequences/sequences_dummy.go
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// +build linux darwin
|
||||||
|
|
||||||
|
package sequences
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EnableVirtualTerminalProcessing(stream uintptr, enable bool) error {
|
||||||
|
return fmt.Errorf("windows only package")
|
||||||
|
}
|
4
vendor/github.com/mattn/go-isatty/go.mod
generated
vendored
4
vendor/github.com/mattn/go-isatty/go.mod
generated
vendored
@ -1,5 +1,5 @@
|
|||||||
module github.com/mattn/go-isatty
|
module github.com/mattn/go-isatty
|
||||||
|
|
||||||
require golang.org/x/sys v0.0.0-20191008105621-543471e840be
|
go 1.12
|
||||||
|
|
||||||
go 1.14
|
require golang.org/x/sys v0.0.0-20191026070338-33540a1f6037
|
||||||
|
6
vendor/github.com/mattn/go-isatty/go.sum
generated
vendored
6
vendor/github.com/mattn/go-isatty/go.sum
generated
vendored
@ -1,4 +1,2 @@
|
|||||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ=
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
||||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU=
|
|
||||||
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
|
2
vendor/github.com/mattn/go-isatty/isatty_plan9.go
generated
vendored
2
vendor/github.com/mattn/go-isatty/isatty_plan9.go
generated
vendored
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
// IsTerminal returns true if the given file descriptor is a terminal.
|
// IsTerminal returns true if the given file descriptor is a terminal.
|
||||||
func IsTerminal(fd uintptr) bool {
|
func IsTerminal(fd uintptr) bool {
|
||||||
path, err := syscall.Fd2path(fd)
|
path, err := syscall.Fd2path(int(fd))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
13
vendor/github.com/mattn/go-runewidth/runewidth.go
generated
vendored
13
vendor/github.com/mattn/go-runewidth/runewidth.go
generated
vendored
@ -102,11 +102,9 @@ func NewCondition() *Condition {
|
|||||||
// See http://www.unicode.org/reports/tr11/
|
// See http://www.unicode.org/reports/tr11/
|
||||||
func (c *Condition) RuneWidth(r rune) int {
|
func (c *Condition) RuneWidth(r rune) int {
|
||||||
switch {
|
switch {
|
||||||
case r < 0 || r > 0x10FFFF ||
|
case r < 0 || r > 0x10FFFF || inTables(r, nonprint, combining, notassigned):
|
||||||
inTables(r, nonprint, combining, notassigned):
|
|
||||||
return 0
|
return 0
|
||||||
case (c.EastAsianWidth && IsAmbiguousWidth(r)) ||
|
case (c.EastAsianWidth && IsAmbiguousWidth(r)) || inTables(r, doublewidth):
|
||||||
inTables(r, doublewidth, emoji):
|
|
||||||
return 2
|
return 2
|
||||||
default:
|
default:
|
||||||
return 1
|
return 1
|
||||||
@ -128,9 +126,12 @@ func (c *Condition) stringWidthZeroJoiner(s string) (width int) {
|
|||||||
}
|
}
|
||||||
w := c.RuneWidth(r)
|
w := c.RuneWidth(r)
|
||||||
if r2 == 0x200D && inTables(r, emoji) && inTables(r1, emoji) {
|
if r2 == 0x200D && inTables(r, emoji) && inTables(r1, emoji) {
|
||||||
w = 0
|
if width < w {
|
||||||
|
width = w
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
width += w
|
||||||
}
|
}
|
||||||
width += w
|
|
||||||
r1, r2 = r2, r
|
r1, r2 = r2, r
|
||||||
}
|
}
|
||||||
return width
|
return width
|
||||||
|
3
vendor/github.com/pelletier/go-toml/.gitignore
generated
vendored
3
vendor/github.com/pelletier/go-toml/.gitignore
generated
vendored
@ -1,2 +1,5 @@
|
|||||||
test_program/test_program_bin
|
test_program/test_program_bin
|
||||||
fuzz/
|
fuzz/
|
||||||
|
cmd/tomll/tomll
|
||||||
|
cmd/tomljson/tomljson
|
||||||
|
cmd/tomltestgen/tomltestgen
|
||||||
|
132
vendor/github.com/pelletier/go-toml/CONTRIBUTING.md
generated
vendored
Normal file
132
vendor/github.com/pelletier/go-toml/CONTRIBUTING.md
generated
vendored
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
## Contributing
|
||||||
|
|
||||||
|
Thank you for your interest in go-toml! We appreciate you considering
|
||||||
|
contributing to go-toml!
|
||||||
|
|
||||||
|
The main goal is the project is to provide an easy-to-use TOML
|
||||||
|
implementation for Go that gets the job done and gets out of your way –
|
||||||
|
dealing with TOML is probably not the central piece of your project.
|
||||||
|
|
||||||
|
As the single maintainer of go-toml, time is scarce. All help, big or
|
||||||
|
small, is more than welcomed!
|
||||||
|
|
||||||
|
### Ask questions
|
||||||
|
|
||||||
|
Any question you may have, somebody else might have it too. Always feel
|
||||||
|
free to ask them on the [issues tracker][issues-tracker]. We will try to
|
||||||
|
answer them as clearly and quickly as possible, time permitting.
|
||||||
|
|
||||||
|
Asking questions also helps us identify areas where the documentation needs
|
||||||
|
improvement, or new features that weren't envisioned before. Sometimes, a
|
||||||
|
seemingly innocent question leads to the fix of a bug. Don't hesitate and
|
||||||
|
ask away!
|
||||||
|
|
||||||
|
### Improve the documentation
|
||||||
|
|
||||||
|
The best way to share your knowledge and experience with go-toml is to
|
||||||
|
improve the documentation. Fix a typo, clarify an interface, add an
|
||||||
|
example, anything goes!
|
||||||
|
|
||||||
|
The documentation is present in the [README][readme] and thorough the
|
||||||
|
source code. On release, it gets updated on [GoDoc][godoc]. To make a
|
||||||
|
change to the documentation, create a pull request with your proposed
|
||||||
|
changes. For simple changes like that, the easiest way to go is probably
|
||||||
|
the "Fork this project and edit the file" button on Github, displayed at
|
||||||
|
the top right of the file. Unless it's a trivial change (for example a
|
||||||
|
typo), provide a little bit of context in your pull request description or
|
||||||
|
commit message.
|
||||||
|
|
||||||
|
### Report a bug
|
||||||
|
|
||||||
|
Found a bug! Sorry to hear that :(. Help us and other track them down and
|
||||||
|
fix by reporting it. [File a new bug report][bug-report] on the [issues
|
||||||
|
tracker][issues-tracker]. The template should provide enough guidance on
|
||||||
|
what to include. When in doubt: add more details! By reducing ambiguity and
|
||||||
|
providing more information, it decreases back and forth and saves everyone
|
||||||
|
time.
|
||||||
|
|
||||||
|
### Code changes
|
||||||
|
|
||||||
|
Want to contribute a patch? Very happy to hear that!
|
||||||
|
|
||||||
|
First, some high-level rules:
|
||||||
|
|
||||||
|
* A short proposal with some POC code is better than a lengthy piece of
|
||||||
|
text with no code. Code speaks louder than words.
|
||||||
|
* No backward-incompatible patch will be accepted unless discussed.
|
||||||
|
Sometimes it's hard, and Go's lack of versioning by default does not
|
||||||
|
help, but we try not to break people's programs unless we absolutely have
|
||||||
|
to.
|
||||||
|
* If you are writing a new feature or extending an existing one, make sure
|
||||||
|
to write some documentation.
|
||||||
|
* Bug fixes need to be accompanied with regression tests.
|
||||||
|
* New code needs to be tested.
|
||||||
|
* Your commit messages need to explain why the change is needed, even if
|
||||||
|
already included in the PR description.
|
||||||
|
|
||||||
|
It does sound like a lot, but those best practices are here to save time
|
||||||
|
overall and continuously improve the quality of the project, which is
|
||||||
|
something everyone benefits from.
|
||||||
|
|
||||||
|
#### Get started
|
||||||
|
|
||||||
|
The fairly standard code contribution process looks like that:
|
||||||
|
|
||||||
|
1. [Fork the project][fork].
|
||||||
|
2. Make your changes, commit on any branch you like.
|
||||||
|
3. [Open up a pull request][pull-request]
|
||||||
|
4. Review, potential ask for changes.
|
||||||
|
5. Merge. You're in!
|
||||||
|
|
||||||
|
Feel free to ask for help! You can create draft pull requests to gather
|
||||||
|
some early feedback!
|
||||||
|
|
||||||
|
#### Run the tests
|
||||||
|
|
||||||
|
You can run tests for go-toml using Go's test tool: `go test ./...`.
|
||||||
|
When creating a pull requests, all tests will be ran on Linux on a few Go
|
||||||
|
versions (Travis CI), and on Windows using the latest Go version
|
||||||
|
(AppVeyor).
|
||||||
|
|
||||||
|
#### Style
|
||||||
|
|
||||||
|
Try to look around and follow the same format and structure as the rest of
|
||||||
|
the code. We enforce using `go fmt` on the whole code base.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Maintainers-only
|
||||||
|
|
||||||
|
#### Merge pull request
|
||||||
|
|
||||||
|
Checklist:
|
||||||
|
|
||||||
|
* Passing CI.
|
||||||
|
* Does not introduce backward-incompatible changes (unless discussed).
|
||||||
|
* Has relevant doc changes.
|
||||||
|
* Has relevant unit tests.
|
||||||
|
|
||||||
|
1. Merge using "squash and merge".
|
||||||
|
2. Make sure to edit the commit message to keep all the useful information
|
||||||
|
nice and clean.
|
||||||
|
3. Make sure the commit title is clear and contains the PR number (#123).
|
||||||
|
|
||||||
|
#### New release
|
||||||
|
|
||||||
|
1. Go to [releases][releases]. Click on "X commits to master since this
|
||||||
|
release".
|
||||||
|
2. Make note of all the changes. Look for backward incompatible changes,
|
||||||
|
new features, and bug fixes.
|
||||||
|
3. Pick the new version using the above and semver.
|
||||||
|
4. Create a [new release][new-release].
|
||||||
|
5. Follow the same format as [1.1.0][release-110].
|
||||||
|
|
||||||
|
[issues-tracker]: https://github.com/pelletier/go-toml/issues
|
||||||
|
[bug-report]: https://github.com/pelletier/go-toml/issues/new?template=bug_report.md
|
||||||
|
[godoc]: https://godoc.org/github.com/pelletier/go-toml
|
||||||
|
[readme]: ./README.md
|
||||||
|
[fork]: https://help.github.com/articles/fork-a-repo
|
||||||
|
[pull-request]: https://help.github.com/en/articles/creating-a-pull-request
|
||||||
|
[releases]: https://github.com/pelletier/go-toml/releases
|
||||||
|
[new-release]: https://github.com/pelletier/go-toml/releases/new
|
||||||
|
[release-110]: https://github.com/pelletier/go-toml/releases/tag/v1.1.0
|
11
vendor/github.com/pelletier/go-toml/Dockerfile
generated
vendored
Normal file
11
vendor/github.com/pelletier/go-toml/Dockerfile
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
FROM golang:1.12-alpine3.9 as builder
|
||||||
|
WORKDIR /go/src/github.com/pelletier/go-toml
|
||||||
|
COPY . .
|
||||||
|
ENV CGO_ENABLED=0
|
||||||
|
ENV GOOS=linux
|
||||||
|
RUN go install ./...
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
COPY --from=builder /go/bin/tomll /usr/bin/tomll
|
||||||
|
COPY --from=builder /go/bin/tomljson /usr/bin/tomljson
|
||||||
|
COPY --from=builder /go/bin/jsontoml /usr/bin/jsontoml
|
5
vendor/github.com/pelletier/go-toml/PULL_REQUEST_TEMPLATE.md
generated
vendored
Normal file
5
vendor/github.com/pelletier/go-toml/PULL_REQUEST_TEMPLATE.md
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
**Issue:** add link to pelletier/go-toml issue here
|
||||||
|
|
||||||
|
Explanation of what this pull request does.
|
||||||
|
|
||||||
|
More detailed description of the decisions being made and the reasons why (if the patch is non-trivial).
|
38
vendor/github.com/pelletier/go-toml/README.md
generated
vendored
38
vendor/github.com/pelletier/go-toml/README.md
generated
vendored
@ -3,13 +3,14 @@
|
|||||||
Go library for the [TOML](https://github.com/mojombo/toml) format.
|
Go library for the [TOML](https://github.com/mojombo/toml) format.
|
||||||
|
|
||||||
This library supports TOML version
|
This library supports TOML version
|
||||||
[v0.4.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md)
|
[v0.5.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.5.0.md)
|
||||||
|
|
||||||
[](http://godoc.org/github.com/pelletier/go-toml)
|
[](http://godoc.org/github.com/pelletier/go-toml)
|
||||||
[](https://github.com/pelletier/go-toml/blob/master/LICENSE)
|
[](https://github.com/pelletier/go-toml/blob/master/LICENSE)
|
||||||
[](https://travis-ci.org/pelletier/go-toml)
|
[](https://dev.azure.com/pelletierthomas/go-toml-ci/_build/latest?definitionId=1&branchName=master)
|
||||||
[](https://coveralls.io/github/pelletier/go-toml?branch=master)
|
[](https://codecov.io/gh/pelletier/go-toml)
|
||||||
[](https://goreportcard.com/report/github.com/pelletier/go-toml)
|
[](https://goreportcard.com/report/github.com/pelletier/go-toml)
|
||||||
|
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fpelletier%2Fgo-toml?ref=badge_shield)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@ -98,6 +99,30 @@ Go-toml provides two handy command line tools:
|
|||||||
go install github.com/pelletier/go-toml/cmd/tomljson
|
go install github.com/pelletier/go-toml/cmd/tomljson
|
||||||
tomljson --help
|
tomljson --help
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* `jsontoml`: Reads a JSON file and outputs a TOML representation.
|
||||||
|
|
||||||
|
```
|
||||||
|
go install github.com/pelletier/go-toml/cmd/jsontoml
|
||||||
|
jsontoml --help
|
||||||
|
```
|
||||||
|
|
||||||
|
### Docker image
|
||||||
|
|
||||||
|
Those tools are also availble as a Docker image from
|
||||||
|
[dockerhub](https://hub.docker.com/r/pelletier/go-toml). For example, to
|
||||||
|
use `tomljson`:
|
||||||
|
|
||||||
|
```
|
||||||
|
docker run -v $PWD:/workdir pelletier/go-toml tomljson /workdir/example.toml
|
||||||
|
```
|
||||||
|
|
||||||
|
Only master (`latest`) and tagged versions are published to dockerhub. You
|
||||||
|
can build your own image as usual:
|
||||||
|
|
||||||
|
```
|
||||||
|
docker build -t go-toml .
|
||||||
|
```
|
||||||
|
|
||||||
## Contribute
|
## Contribute
|
||||||
|
|
||||||
@ -107,12 +132,7 @@ much appreciated!
|
|||||||
|
|
||||||
### Run tests
|
### Run tests
|
||||||
|
|
||||||
You have to make sure two kind of tests run:
|
`go test ./...`
|
||||||
|
|
||||||
1. The Go unit tests
|
|
||||||
2. The TOML examples base
|
|
||||||
|
|
||||||
You can run both of them using `./test.sh`.
|
|
||||||
|
|
||||||
### Fuzzing
|
### Fuzzing
|
||||||
|
|
||||||
|
167
vendor/github.com/pelletier/go-toml/azure-pipelines.yml
generated
vendored
Normal file
167
vendor/github.com/pelletier/go-toml/azure-pipelines.yml
generated
vendored
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
trigger:
|
||||||
|
- master
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- stage: fuzzit
|
||||||
|
displayName: "Run Fuzzit"
|
||||||
|
dependsOn: []
|
||||||
|
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'master'))
|
||||||
|
jobs:
|
||||||
|
- job: submit
|
||||||
|
displayName: "Submit"
|
||||||
|
pool:
|
||||||
|
vmImage: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- task: GoTool@0
|
||||||
|
displayName: "Install Go 1.13"
|
||||||
|
inputs:
|
||||||
|
version: "1.13"
|
||||||
|
- script: echo "##vso[task.setvariable variable=PATH]${PATH}:/home/vsts/go/bin/"
|
||||||
|
- script: mkdir -p ${HOME}/go/src/github.com/pelletier/go-toml
|
||||||
|
- script: cp -R . ${HOME}/go/src/github.com/pelletier/go-toml
|
||||||
|
- task: Bash@3
|
||||||
|
inputs:
|
||||||
|
filePath: './fuzzit.sh'
|
||||||
|
env:
|
||||||
|
TYPE: fuzzing
|
||||||
|
FUZZIT_API_KEY: $(FUZZIT_API_KEY)
|
||||||
|
|
||||||
|
- stage: run_checks
|
||||||
|
displayName: "Check"
|
||||||
|
dependsOn: []
|
||||||
|
jobs:
|
||||||
|
- job: fmt
|
||||||
|
displayName: "fmt"
|
||||||
|
pool:
|
||||||
|
vmImage: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- task: GoTool@0
|
||||||
|
displayName: "Install Go 1.13"
|
||||||
|
inputs:
|
||||||
|
version: "1.13"
|
||||||
|
- task: Go@0
|
||||||
|
displayName: "go fmt ./..."
|
||||||
|
inputs:
|
||||||
|
command: 'custom'
|
||||||
|
customCommand: 'fmt'
|
||||||
|
arguments: './...'
|
||||||
|
- job: coverage
|
||||||
|
displayName: "coverage"
|
||||||
|
pool:
|
||||||
|
vmImage: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- task: GoTool@0
|
||||||
|
displayName: "Install Go 1.13"
|
||||||
|
inputs:
|
||||||
|
version: "1.13"
|
||||||
|
- task: Go@0
|
||||||
|
displayName: "Generate coverage"
|
||||||
|
inputs:
|
||||||
|
command: 'test'
|
||||||
|
arguments: "-race -coverprofile=coverage.txt -covermode=atomic"
|
||||||
|
- task: Bash@3
|
||||||
|
inputs:
|
||||||
|
targetType: 'inline'
|
||||||
|
script: 'bash <(curl -s https://codecov.io/bash) -t $(CODECOV_TOKEN)'
|
||||||
|
- job: benchmark
|
||||||
|
displayName: "benchmark"
|
||||||
|
pool:
|
||||||
|
vmImage: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- task: GoTool@0
|
||||||
|
displayName: "Install Go 1.13"
|
||||||
|
inputs:
|
||||||
|
version: "1.13"
|
||||||
|
- script: echo "##vso[task.setvariable variable=PATH]${PATH}:/home/vsts/go/bin/"
|
||||||
|
- task: Bash@3
|
||||||
|
inputs:
|
||||||
|
filePath: './benchmark.sh'
|
||||||
|
arguments: "master $(Build.Repository.Uri)"
|
||||||
|
|
||||||
|
- job: fuzzing
|
||||||
|
displayName: "fuzzing"
|
||||||
|
pool:
|
||||||
|
vmImage: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- task: GoTool@0
|
||||||
|
displayName: "Install Go 1.13"
|
||||||
|
inputs:
|
||||||
|
version: "1.13"
|
||||||
|
- script: echo "##vso[task.setvariable variable=PATH]${PATH}:/home/vsts/go/bin/"
|
||||||
|
- script: mkdir -p ${HOME}/go/src/github.com/pelletier/go-toml
|
||||||
|
- script: cp -R . ${HOME}/go/src/github.com/pelletier/go-toml
|
||||||
|
- task: Bash@3
|
||||||
|
inputs:
|
||||||
|
filePath: './fuzzit.sh'
|
||||||
|
env:
|
||||||
|
TYPE: local-regression
|
||||||
|
|
||||||
|
- job: go_unit_tests
|
||||||
|
displayName: "unit tests"
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
linux 1.13:
|
||||||
|
goVersion: '1.13'
|
||||||
|
imageName: 'ubuntu-latest'
|
||||||
|
mac 1.13:
|
||||||
|
goVersion: '1.13'
|
||||||
|
imageName: 'macos-10.13'
|
||||||
|
windows 1.13:
|
||||||
|
goVersion: '1.13'
|
||||||
|
imageName: 'vs2017-win2016'
|
||||||
|
linux 1.12:
|
||||||
|
goVersion: '1.12'
|
||||||
|
imageName: 'ubuntu-latest'
|
||||||
|
mac 1.12:
|
||||||
|
goVersion: '1.12'
|
||||||
|
imageName: 'macos-10.13'
|
||||||
|
windows 1.12:
|
||||||
|
goVersion: '1.12'
|
||||||
|
imageName: 'vs2017-win2016'
|
||||||
|
pool:
|
||||||
|
vmImage: $(imageName)
|
||||||
|
steps:
|
||||||
|
- task: GoTool@0
|
||||||
|
displayName: "Install Go $(goVersion)"
|
||||||
|
inputs:
|
||||||
|
version: $(goVersion)
|
||||||
|
- task: Go@0
|
||||||
|
displayName: "go test ./..."
|
||||||
|
inputs:
|
||||||
|
command: 'test'
|
||||||
|
arguments: './...'
|
||||||
|
|
||||||
|
- stage: build_docker_image
|
||||||
|
displayName: "Build Docker image"
|
||||||
|
dependsOn: run_checks
|
||||||
|
jobs:
|
||||||
|
- job: build
|
||||||
|
displayName: "Build"
|
||||||
|
pool:
|
||||||
|
vmImage: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- task: Docker@2
|
||||||
|
inputs:
|
||||||
|
command: 'build'
|
||||||
|
Dockerfile: 'Dockerfile'
|
||||||
|
buildContext: '.'
|
||||||
|
addPipelineData: false
|
||||||
|
|
||||||
|
- stage: publish_docker_image
|
||||||
|
displayName: "Publish Docker image"
|
||||||
|
dependsOn: build_docker_image
|
||||||
|
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'master'))
|
||||||
|
jobs:
|
||||||
|
- job: publish
|
||||||
|
displayName: "Publish"
|
||||||
|
pool:
|
||||||
|
vmImage: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- task: Docker@2
|
||||||
|
inputs:
|
||||||
|
containerRegistry: 'DockerHub'
|
||||||
|
repository: 'pelletier/go-toml'
|
||||||
|
command: 'buildAndPush'
|
||||||
|
Dockerfile: 'Dockerfile'
|
||||||
|
buildContext: '.'
|
||||||
|
tags: 'latest'
|
5
vendor/github.com/pelletier/go-toml/benchmark.sh
generated
vendored
5
vendor/github.com/pelletier/go-toml/benchmark.sh
generated
vendored
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -ex
|
||||||
|
|
||||||
reference_ref=${1:-master}
|
reference_ref=${1:-master}
|
||||||
reference_git=${2:-.}
|
reference_git=${2:-.}
|
||||||
@ -8,7 +8,6 @@ reference_git=${2:-.}
|
|||||||
if ! `hash benchstat 2>/dev/null`; then
|
if ! `hash benchstat 2>/dev/null`; then
|
||||||
echo "Installing benchstat"
|
echo "Installing benchstat"
|
||||||
go get golang.org/x/perf/cmd/benchstat
|
go get golang.org/x/perf/cmd/benchstat
|
||||||
go install golang.org/x/perf/cmd/benchstat
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tempdir=`mktemp -d /tmp/go-toml-benchmark-XXXXXX`
|
tempdir=`mktemp -d /tmp/go-toml-benchmark-XXXXXX`
|
||||||
@ -29,4 +28,4 @@ go test -bench=. -benchmem | tee ${local_benchmark}
|
|||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== diff"
|
echo "=== diff"
|
||||||
benchstat -delta-test=none ${ref_benchmark} ${local_benchmark}
|
benchstat -delta-test=none ${ref_benchmark} ${local_benchmark}
|
||||||
|
2
vendor/github.com/pelletier/go-toml/doc.go
generated
vendored
2
vendor/github.com/pelletier/go-toml/doc.go
generated
vendored
@ -1,7 +1,7 @@
|
|||||||
// Package toml is a TOML parser and manipulation library.
|
// Package toml is a TOML parser and manipulation library.
|
||||||
//
|
//
|
||||||
// This version supports the specification as described in
|
// This version supports the specification as described in
|
||||||
// https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md
|
// https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.5.0.md
|
||||||
//
|
//
|
||||||
// Marshaling
|
// Marshaling
|
||||||
//
|
//
|
||||||
|
26
vendor/github.com/pelletier/go-toml/fuzzit.sh
generated
vendored
Normal file
26
vendor/github.com/pelletier/go-toml/fuzzit.sh
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -xe
|
||||||
|
|
||||||
|
# go-fuzz doesn't support modules yet, so ensure we do everything
|
||||||
|
# in the old style GOPATH way
|
||||||
|
export GO111MODULE="off"
|
||||||
|
|
||||||
|
# install go-fuzz
|
||||||
|
go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build
|
||||||
|
|
||||||
|
# target name can only contain lower-case letters (a-z), digits (0-9) and a dash (-)
|
||||||
|
# to add another target, make sure to create it with `fuzzit create target`
|
||||||
|
# before using `fuzzit create job`
|
||||||
|
TARGET=toml-fuzzer
|
||||||
|
|
||||||
|
go-fuzz-build -libfuzzer -o ${TARGET}.a github.com/pelletier/go-toml
|
||||||
|
clang -fsanitize=fuzzer ${TARGET}.a -o ${TARGET}
|
||||||
|
|
||||||
|
# install fuzzit for talking to fuzzit.dev service
|
||||||
|
# or latest version:
|
||||||
|
# https://github.com/fuzzitdev/fuzzit/releases/latest/download/fuzzit_Linux_x86_64
|
||||||
|
wget -q -O fuzzit https://github.com/fuzzitdev/fuzzit/releases/download/v2.4.52/fuzzit_Linux_x86_64
|
||||||
|
chmod a+x fuzzit
|
||||||
|
|
||||||
|
# TODO: change kkowalczyk to go-toml and create toml-fuzzer target there
|
||||||
|
./fuzzit create job --type $TYPE go-toml/${TARGET} ${TARGET}
|
9
vendor/github.com/pelletier/go-toml/go.mod
generated
vendored
Normal file
9
vendor/github.com/pelletier/go-toml/go.mod
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module github.com/pelletier/go-toml
|
||||||
|
|
||||||
|
go 1.12
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/BurntSushi/toml v0.3.1
|
||||||
|
github.com/davecgh/go-spew v1.1.1
|
||||||
|
gopkg.in/yaml.v2 v2.2.4
|
||||||
|
)
|
11
vendor/github.com/pelletier/go-toml/go.sum
generated
vendored
Normal file
11
vendor/github.com/pelletier/go-toml/go.sum
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||||
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
|
||||||
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
136
vendor/github.com/pelletier/go-toml/keysparsing.go
generated
vendored
136
vendor/github.com/pelletier/go-toml/keysparsing.go
generated
vendored
@ -3,79 +3,107 @@
|
|||||||
package toml
|
package toml
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Convert the bare key group string to an array.
|
// Convert the bare key group string to an array.
|
||||||
// The input supports double quotation to allow "." inside the key name,
|
// The input supports double quotation and single quotation,
|
||||||
// but escape sequences are not supported. Lexers must unescape them beforehand.
|
// but escape sequences are not supported. Lexers must unescape them beforehand.
|
||||||
func parseKey(key string) ([]string, error) {
|
func parseKey(key string) ([]string, error) {
|
||||||
groups := []string{}
|
runes := []rune(key)
|
||||||
var buffer bytes.Buffer
|
var groups []string
|
||||||
inQuotes := false
|
|
||||||
wasInQuotes := false
|
|
||||||
ignoreSpace := true
|
|
||||||
expectDot := false
|
|
||||||
|
|
||||||
for _, char := range key {
|
if len(key) == 0 {
|
||||||
if ignoreSpace {
|
return nil, errors.New("empty key")
|
||||||
if char == ' ' {
|
}
|
||||||
continue
|
|
||||||
}
|
idx := 0
|
||||||
ignoreSpace = false
|
for idx < len(runes) {
|
||||||
|
for ; idx < len(runes) && isSpace(runes[idx]); idx++ {
|
||||||
|
// skip leading whitespace
|
||||||
}
|
}
|
||||||
switch char {
|
if idx >= len(runes) {
|
||||||
case '"':
|
break
|
||||||
if inQuotes {
|
}
|
||||||
groups = append(groups, buffer.String())
|
r := runes[idx]
|
||||||
buffer.Reset()
|
if isValidBareChar(r) {
|
||||||
wasInQuotes = true
|
// parse bare key
|
||||||
}
|
startIdx := idx
|
||||||
inQuotes = !inQuotes
|
endIdx := -1
|
||||||
expectDot = false
|
idx++
|
||||||
case '.':
|
for idx < len(runes) {
|
||||||
if inQuotes {
|
r = runes[idx]
|
||||||
buffer.WriteRune(char)
|
if isValidBareChar(r) {
|
||||||
} else {
|
idx++
|
||||||
if !wasInQuotes {
|
} else if r == '.' {
|
||||||
if buffer.Len() == 0 {
|
endIdx = idx
|
||||||
return nil, errors.New("empty table key")
|
break
|
||||||
|
} else if isSpace(r) {
|
||||||
|
endIdx = idx
|
||||||
|
for ; idx < len(runes) && isSpace(runes[idx]); idx++ {
|
||||||
|
// skip trailing whitespace
|
||||||
}
|
}
|
||||||
groups = append(groups, buffer.String())
|
if idx < len(runes) && runes[idx] != '.' {
|
||||||
buffer.Reset()
|
return nil, fmt.Errorf("invalid key character after whitespace: %c", runes[idx])
|
||||||
|
}
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("invalid bare key character: %c", r)
|
||||||
}
|
}
|
||||||
ignoreSpace = true
|
|
||||||
expectDot = false
|
|
||||||
wasInQuotes = false
|
|
||||||
}
|
}
|
||||||
case ' ':
|
if endIdx == -1 {
|
||||||
if inQuotes {
|
endIdx = idx
|
||||||
buffer.WriteRune(char)
|
|
||||||
} else {
|
|
||||||
expectDot = true
|
|
||||||
}
|
}
|
||||||
default:
|
groups = append(groups, string(runes[startIdx:endIdx]))
|
||||||
if !inQuotes && !isValidBareChar(char) {
|
} else if r == '\'' {
|
||||||
return nil, fmt.Errorf("invalid bare character: %c", char)
|
// parse single quoted key
|
||||||
|
idx++
|
||||||
|
startIdx := idx
|
||||||
|
for {
|
||||||
|
if idx >= len(runes) {
|
||||||
|
return nil, fmt.Errorf("unclosed single-quoted key")
|
||||||
|
}
|
||||||
|
r = runes[idx]
|
||||||
|
if r == '\'' {
|
||||||
|
groups = append(groups, string(runes[startIdx:idx]))
|
||||||
|
idx++
|
||||||
|
break
|
||||||
|
}
|
||||||
|
idx++
|
||||||
}
|
}
|
||||||
if !inQuotes && expectDot {
|
} else if r == '"' {
|
||||||
return nil, errors.New("what?")
|
// parse double quoted key
|
||||||
|
idx++
|
||||||
|
startIdx := idx
|
||||||
|
for {
|
||||||
|
if idx >= len(runes) {
|
||||||
|
return nil, fmt.Errorf("unclosed double-quoted key")
|
||||||
|
}
|
||||||
|
r = runes[idx]
|
||||||
|
if r == '"' {
|
||||||
|
groups = append(groups, string(runes[startIdx:idx]))
|
||||||
|
idx++
|
||||||
|
break
|
||||||
|
}
|
||||||
|
idx++
|
||||||
}
|
}
|
||||||
buffer.WriteRune(char)
|
} else if r == '.' {
|
||||||
expectDot = false
|
idx++
|
||||||
|
if idx >= len(runes) {
|
||||||
|
return nil, fmt.Errorf("unexpected end of key")
|
||||||
|
}
|
||||||
|
r = runes[idx]
|
||||||
|
if !isValidBareChar(r) && r != '\'' && r != '"' && r != ' ' {
|
||||||
|
return nil, fmt.Errorf("expecting key part after dot")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("invalid key character: %c", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if inQuotes {
|
|
||||||
return nil, errors.New("mismatched quotes")
|
|
||||||
}
|
|
||||||
if buffer.Len() > 0 {
|
|
||||||
groups = append(groups, buffer.String())
|
|
||||||
}
|
|
||||||
if len(groups) == 0 {
|
if len(groups) == 0 {
|
||||||
return nil, errors.New("empty key")
|
return nil, fmt.Errorf("empty key")
|
||||||
}
|
}
|
||||||
return groups, nil
|
return groups, nil
|
||||||
}
|
}
|
||||||
|
46
vendor/github.com/pelletier/go-toml/lexer.go
generated
vendored
46
vendor/github.com/pelletier/go-toml/lexer.go
generated
vendored
@ -223,9 +223,12 @@ func (l *tomlLexer) lexRvalue() tomlLexStateFn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
possibleDate := l.peekString(35)
|
possibleDate := l.peekString(35)
|
||||||
dateMatch := dateRegexp.FindString(possibleDate)
|
dateSubmatches := dateRegexp.FindStringSubmatch(possibleDate)
|
||||||
if dateMatch != "" {
|
if dateSubmatches != nil && dateSubmatches[0] != "" {
|
||||||
l.fastForward(len(dateMatch))
|
l.fastForward(len(dateSubmatches[0]))
|
||||||
|
if dateSubmatches[2] == "" { // no timezone information => local date
|
||||||
|
return l.lexLocalDate
|
||||||
|
}
|
||||||
return l.lexDate
|
return l.lexDate
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,13 +250,13 @@ func (l *tomlLexer) lexRvalue() tomlLexStateFn {
|
|||||||
func (l *tomlLexer) lexLeftCurlyBrace() tomlLexStateFn {
|
func (l *tomlLexer) lexLeftCurlyBrace() tomlLexStateFn {
|
||||||
l.next()
|
l.next()
|
||||||
l.emit(tokenLeftCurlyBrace)
|
l.emit(tokenLeftCurlyBrace)
|
||||||
return l.lexRvalue
|
return l.lexVoid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *tomlLexer) lexRightCurlyBrace() tomlLexStateFn {
|
func (l *tomlLexer) lexRightCurlyBrace() tomlLexStateFn {
|
||||||
l.next()
|
l.next()
|
||||||
l.emit(tokenRightCurlyBrace)
|
l.emit(tokenRightCurlyBrace)
|
||||||
return l.lexRvalue
|
return l.lexVoid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *tomlLexer) lexDate() tomlLexStateFn {
|
func (l *tomlLexer) lexDate() tomlLexStateFn {
|
||||||
@ -261,6 +264,11 @@ func (l *tomlLexer) lexDate() tomlLexStateFn {
|
|||||||
return l.lexRvalue
|
return l.lexRvalue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *tomlLexer) lexLocalDate() tomlLexStateFn {
|
||||||
|
l.emit(tokenLocalDate)
|
||||||
|
return l.lexRvalue
|
||||||
|
}
|
||||||
|
|
||||||
func (l *tomlLexer) lexTrue() tomlLexStateFn {
|
func (l *tomlLexer) lexTrue() tomlLexStateFn {
|
||||||
l.fastForward(4)
|
l.fastForward(4)
|
||||||
l.emit(tokenTrue)
|
l.emit(tokenTrue)
|
||||||
@ -309,7 +317,7 @@ func (l *tomlLexer) lexKey() tomlLexStateFn {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return l.errorf(err.Error())
|
return l.errorf(err.Error())
|
||||||
}
|
}
|
||||||
growingString += str
|
growingString += "\"" + str + "\""
|
||||||
l.next()
|
l.next()
|
||||||
continue
|
continue
|
||||||
} else if r == '\'' {
|
} else if r == '\'' {
|
||||||
@ -318,13 +326,15 @@ func (l *tomlLexer) lexKey() tomlLexStateFn {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return l.errorf(err.Error())
|
return l.errorf(err.Error())
|
||||||
}
|
}
|
||||||
growingString += str
|
growingString += "'" + str + "'"
|
||||||
l.next()
|
l.next()
|
||||||
continue
|
continue
|
||||||
} else if r == '\n' {
|
} else if r == '\n' {
|
||||||
return l.errorf("keys cannot contain new lines")
|
return l.errorf("keys cannot contain new lines")
|
||||||
} else if isSpace(r) {
|
} else if isSpace(r) {
|
||||||
break
|
break
|
||||||
|
} else if r == '.' {
|
||||||
|
// skip
|
||||||
} else if !isValidBareChar(r) {
|
} else if !isValidBareChar(r) {
|
||||||
return l.errorf("keys cannot contain %c character", r)
|
return l.errorf("keys cannot contain %c character", r)
|
||||||
}
|
}
|
||||||
@ -731,7 +741,27 @@ func (l *tomlLexer) run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
dateRegexp = regexp.MustCompile(`^\d{1,4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})`)
|
// Regexp for all date/time formats supported by TOML.
|
||||||
|
// Group 1: nano precision
|
||||||
|
// Group 2: timezone
|
||||||
|
//
|
||||||
|
// /!\ also matches the empty string
|
||||||
|
//
|
||||||
|
// Example matches:
|
||||||
|
//1979-05-27T07:32:00Z
|
||||||
|
//1979-05-27T00:32:00-07:00
|
||||||
|
//1979-05-27T00:32:00.999999-07:00
|
||||||
|
//1979-05-27 07:32:00Z
|
||||||
|
//1979-05-27 00:32:00-07:00
|
||||||
|
//1979-05-27 00:32:00.999999-07:00
|
||||||
|
//1979-05-27T07:32:00
|
||||||
|
//1979-05-27T00:32:00.999999
|
||||||
|
//1979-05-27 07:32:00
|
||||||
|
//1979-05-27 00:32:00.999999
|
||||||
|
//1979-05-27
|
||||||
|
//07:32:00
|
||||||
|
//00:32:00.999999
|
||||||
|
dateRegexp = regexp.MustCompile(`^(?:\d{1,4}-\d{2}-\d{2})?(?:[T ]?\d{2}:\d{2}:\d{2}(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})?)?`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entry point
|
// Entry point
|
||||||
|
281
vendor/github.com/pelletier/go-toml/localtime.go
generated
vendored
Normal file
281
vendor/github.com/pelletier/go-toml/localtime.go
generated
vendored
Normal file
@ -0,0 +1,281 @@
|
|||||||
|
// Implementation of TOML's local date/time.
|
||||||
|
// Copied over from https://github.com/googleapis/google-cloud-go/blob/master/civil/civil.go
|
||||||
|
// to avoid pulling all the Google dependencies.
|
||||||
|
//
|
||||||
|
// Copyright 2016 Google LLC
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// Package civil implements types for civil time, a time-zone-independent
|
||||||
|
// representation of time that follows the rules of the proleptic
|
||||||
|
// Gregorian calendar with exactly 24-hour days, 60-minute hours, and 60-second
|
||||||
|
// minutes.
|
||||||
|
//
|
||||||
|
// Because they lack location information, these types do not represent unique
|
||||||
|
// moments or intervals of time. Use time.Time for that purpose.
|
||||||
|
package toml
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A LocalDate represents a date (year, month, day).
|
||||||
|
//
|
||||||
|
// This type does not include location information, and therefore does not
|
||||||
|
// describe a unique 24-hour timespan.
|
||||||
|
type LocalDate struct {
|
||||||
|
Year int // Year (e.g., 2014).
|
||||||
|
Month time.Month // Month of the year (January = 1, ...).
|
||||||
|
Day int // Day of the month, starting at 1.
|
||||||
|
}
|
||||||
|
|
||||||
|
// LocalDateOf returns the LocalDate in which a time occurs in that time's location.
|
||||||
|
func LocalDateOf(t time.Time) LocalDate {
|
||||||
|
var d LocalDate
|
||||||
|
d.Year, d.Month, d.Day = t.Date()
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseLocalDate parses a string in RFC3339 full-date format and returns the date value it represents.
|
||||||
|
func ParseLocalDate(s string) (LocalDate, error) {
|
||||||
|
t, err := time.Parse("2006-01-02", s)
|
||||||
|
if err != nil {
|
||||||
|
return LocalDate{}, err
|
||||||
|
}
|
||||||
|
return LocalDateOf(t), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns the date in RFC3339 full-date format.
|
||||||
|
func (d LocalDate) String() string {
|
||||||
|
return fmt.Sprintf("%04d-%02d-%02d", d.Year, d.Month, d.Day)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValid reports whether the date is valid.
|
||||||
|
func (d LocalDate) IsValid() bool {
|
||||||
|
return LocalDateOf(d.In(time.UTC)) == d
|
||||||
|
}
|
||||||
|
|
||||||
|
// In returns the time corresponding to time 00:00:00 of the date in the location.
|
||||||
|
//
|
||||||
|
// In is always consistent with time.LocalDate, even when time.LocalDate returns a time
|
||||||
|
// on a different day. For example, if loc is America/Indiana/Vincennes, then both
|
||||||
|
// time.LocalDate(1955, time.May, 1, 0, 0, 0, 0, loc)
|
||||||
|
// and
|
||||||
|
// civil.LocalDate{Year: 1955, Month: time.May, Day: 1}.In(loc)
|
||||||
|
// return 23:00:00 on April 30, 1955.
|
||||||
|
//
|
||||||
|
// In panics if loc is nil.
|
||||||
|
func (d LocalDate) In(loc *time.Location) time.Time {
|
||||||
|
return time.Date(d.Year, d.Month, d.Day, 0, 0, 0, 0, loc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddDays returns the date that is n days in the future.
|
||||||
|
// n can also be negative to go into the past.
|
||||||
|
func (d LocalDate) AddDays(n int) LocalDate {
|
||||||
|
return LocalDateOf(d.In(time.UTC).AddDate(0, 0, n))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DaysSince returns the signed number of days between the date and s, not including the end day.
|
||||||
|
// This is the inverse operation to AddDays.
|
||||||
|
func (d LocalDate) DaysSince(s LocalDate) (days int) {
|
||||||
|
// We convert to Unix time so we do not have to worry about leap seconds:
|
||||||
|
// Unix time increases by exactly 86400 seconds per day.
|
||||||
|
deltaUnix := d.In(time.UTC).Unix() - s.In(time.UTC).Unix()
|
||||||
|
return int(deltaUnix / 86400)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Before reports whether d1 occurs before d2.
|
||||||
|
func (d1 LocalDate) Before(d2 LocalDate) bool {
|
||||||
|
if d1.Year != d2.Year {
|
||||||
|
return d1.Year < d2.Year
|
||||||
|
}
|
||||||
|
if d1.Month != d2.Month {
|
||||||
|
return d1.Month < d2.Month
|
||||||
|
}
|
||||||
|
return d1.Day < d2.Day
|
||||||
|
}
|
||||||
|
|
||||||
|
// After reports whether d1 occurs after d2.
|
||||||
|
func (d1 LocalDate) After(d2 LocalDate) bool {
|
||||||
|
return d2.Before(d1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalText implements the encoding.TextMarshaler interface.
|
||||||
|
// The output is the result of d.String().
|
||||||
|
func (d LocalDate) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(d.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalText implements the encoding.TextUnmarshaler interface.
|
||||||
|
// The date is expected to be a string in a format accepted by ParseLocalDate.
|
||||||
|
func (d *LocalDate) UnmarshalText(data []byte) error {
|
||||||
|
var err error
|
||||||
|
*d, err = ParseLocalDate(string(data))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// A LocalTime represents a time with nanosecond precision.
|
||||||
|
//
|
||||||
|
// This type does not include location information, and therefore does not
|
||||||
|
// describe a unique moment in time.
|
||||||
|
//
|
||||||
|
// This type exists to represent the TIME type in storage-based APIs like BigQuery.
|
||||||
|
// Most operations on Times are unlikely to be meaningful. Prefer the LocalDateTime type.
|
||||||
|
type LocalTime struct {
|
||||||
|
Hour int // The hour of the day in 24-hour format; range [0-23]
|
||||||
|
Minute int // The minute of the hour; range [0-59]
|
||||||
|
Second int // The second of the minute; range [0-59]
|
||||||
|
Nanosecond int // The nanosecond of the second; range [0-999999999]
|
||||||
|
}
|
||||||
|
|
||||||
|
// LocalTimeOf returns the LocalTime representing the time of day in which a time occurs
|
||||||
|
// in that time's location. It ignores the date.
|
||||||
|
func LocalTimeOf(t time.Time) LocalTime {
|
||||||
|
var tm LocalTime
|
||||||
|
tm.Hour, tm.Minute, tm.Second = t.Clock()
|
||||||
|
tm.Nanosecond = t.Nanosecond()
|
||||||
|
return tm
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseLocalTime parses a string and returns the time value it represents.
|
||||||
|
// ParseLocalTime accepts an extended form of the RFC3339 partial-time format. After
|
||||||
|
// the HH:MM:SS part of the string, an optional fractional part may appear,
|
||||||
|
// consisting of a decimal point followed by one to nine decimal digits.
|
||||||
|
// (RFC3339 admits only one digit after the decimal point).
|
||||||
|
func ParseLocalTime(s string) (LocalTime, error) {
|
||||||
|
t, err := time.Parse("15:04:05.999999999", s)
|
||||||
|
if err != nil {
|
||||||
|
return LocalTime{}, err
|
||||||
|
}
|
||||||
|
return LocalTimeOf(t), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns the date in the format described in ParseLocalTime. If Nanoseconds
|
||||||
|
// is zero, no fractional part will be generated. Otherwise, the result will
|
||||||
|
// end with a fractional part consisting of a decimal point and nine digits.
|
||||||
|
func (t LocalTime) String() string {
|
||||||
|
s := fmt.Sprintf("%02d:%02d:%02d", t.Hour, t.Minute, t.Second)
|
||||||
|
if t.Nanosecond == 0 {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
return s + fmt.Sprintf(".%09d", t.Nanosecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValid reports whether the time is valid.
|
||||||
|
func (t LocalTime) IsValid() bool {
|
||||||
|
// Construct a non-zero time.
|
||||||
|
tm := time.Date(2, 2, 2, t.Hour, t.Minute, t.Second, t.Nanosecond, time.UTC)
|
||||||
|
return LocalTimeOf(tm) == t
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalText implements the encoding.TextMarshaler interface.
|
||||||
|
// The output is the result of t.String().
|
||||||
|
func (t LocalTime) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(t.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalText implements the encoding.TextUnmarshaler interface.
|
||||||
|
// The time is expected to be a string in a format accepted by ParseLocalTime.
|
||||||
|
func (t *LocalTime) UnmarshalText(data []byte) error {
|
||||||
|
var err error
|
||||||
|
*t, err = ParseLocalTime(string(data))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// A LocalDateTime represents a date and time.
|
||||||
|
//
|
||||||
|
// This type does not include location information, and therefore does not
|
||||||
|
// describe a unique moment in time.
|
||||||
|
type LocalDateTime struct {
|
||||||
|
Date LocalDate
|
||||||
|
Time LocalTime
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: We deliberately do not embed LocalDate into LocalDateTime, to avoid promoting AddDays and Sub.
|
||||||
|
|
||||||
|
// LocalDateTimeOf returns the LocalDateTime in which a time occurs in that time's location.
|
||||||
|
func LocalDateTimeOf(t time.Time) LocalDateTime {
|
||||||
|
return LocalDateTime{
|
||||||
|
Date: LocalDateOf(t),
|
||||||
|
Time: LocalTimeOf(t),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseLocalDateTime parses a string and returns the LocalDateTime it represents.
|
||||||
|
// ParseLocalDateTime accepts a variant of the RFC3339 date-time format that omits
|
||||||
|
// the time offset but includes an optional fractional time, as described in
|
||||||
|
// ParseLocalTime. Informally, the accepted format is
|
||||||
|
// YYYY-MM-DDTHH:MM:SS[.FFFFFFFFF]
|
||||||
|
// where the 'T' may be a lower-case 't'.
|
||||||
|
func ParseLocalDateTime(s string) (LocalDateTime, error) {
|
||||||
|
t, err := time.Parse("2006-01-02T15:04:05.999999999", s)
|
||||||
|
if err != nil {
|
||||||
|
t, err = time.Parse("2006-01-02t15:04:05.999999999", s)
|
||||||
|
if err != nil {
|
||||||
|
return LocalDateTime{}, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return LocalDateTimeOf(t), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns the date in the format described in ParseLocalDate.
|
||||||
|
func (dt LocalDateTime) String() string {
|
||||||
|
return dt.Date.String() + "T" + dt.Time.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValid reports whether the datetime is valid.
|
||||||
|
func (dt LocalDateTime) IsValid() bool {
|
||||||
|
return dt.Date.IsValid() && dt.Time.IsValid()
|
||||||
|
}
|
||||||
|
|
||||||
|
// In returns the time corresponding to the LocalDateTime in the given location.
|
||||||
|
//
|
||||||
|
// If the time is missing or ambigous at the location, In returns the same
|
||||||
|
// result as time.LocalDate. For example, if loc is America/Indiana/Vincennes, then
|
||||||
|
// both
|
||||||
|
// time.LocalDate(1955, time.May, 1, 0, 30, 0, 0, loc)
|
||||||
|
// and
|
||||||
|
// civil.LocalDateTime{
|
||||||
|
// civil.LocalDate{Year: 1955, Month: time.May, Day: 1}},
|
||||||
|
// civil.LocalTime{Minute: 30}}.In(loc)
|
||||||
|
// return 23:30:00 on April 30, 1955.
|
||||||
|
//
|
||||||
|
// In panics if loc is nil.
|
||||||
|
func (dt LocalDateTime) In(loc *time.Location) time.Time {
|
||||||
|
return time.Date(dt.Date.Year, dt.Date.Month, dt.Date.Day, dt.Time.Hour, dt.Time.Minute, dt.Time.Second, dt.Time.Nanosecond, loc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Before reports whether dt1 occurs before dt2.
|
||||||
|
func (dt1 LocalDateTime) Before(dt2 LocalDateTime) bool {
|
||||||
|
return dt1.In(time.UTC).Before(dt2.In(time.UTC))
|
||||||
|
}
|
||||||
|
|
||||||
|
// After reports whether dt1 occurs after dt2.
|
||||||
|
func (dt1 LocalDateTime) After(dt2 LocalDateTime) bool {
|
||||||
|
return dt2.Before(dt1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalText implements the encoding.TextMarshaler interface.
|
||||||
|
// The output is the result of dt.String().
|
||||||
|
func (dt LocalDateTime) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(dt.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalText implements the encoding.TextUnmarshaler interface.
|
||||||
|
// The datetime is expected to be a string in a format accepted by ParseLocalDateTime
|
||||||
|
func (dt *LocalDateTime) UnmarshalText(data []byte) error {
|
||||||
|
var err error
|
||||||
|
*dt, err = ParseLocalDateTime(string(data))
|
||||||
|
return err
|
||||||
|
}
|
411
vendor/github.com/pelletier/go-toml/marshal.go
generated
vendored
411
vendor/github.com/pelletier/go-toml/marshal.go
generated
vendored
@ -6,20 +6,28 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const tagKeyMultiline = "multiline"
|
const (
|
||||||
|
tagFieldName = "toml"
|
||||||
|
tagFieldComment = "comment"
|
||||||
|
tagCommented = "commented"
|
||||||
|
tagMultiline = "multiline"
|
||||||
|
tagDefault = "default"
|
||||||
|
)
|
||||||
|
|
||||||
type tomlOpts struct {
|
type tomlOpts struct {
|
||||||
name string
|
name string
|
||||||
comment string
|
comment string
|
||||||
commented bool
|
commented bool
|
||||||
multiline bool
|
multiline bool
|
||||||
include bool
|
include bool
|
||||||
omitempty bool
|
omitempty bool
|
||||||
|
defaultValue string
|
||||||
}
|
}
|
||||||
|
|
||||||
type encOpts struct {
|
type encOpts struct {
|
||||||
@ -31,10 +39,40 @@ var encOptsDefaults = encOpts{
|
|||||||
quoteMapKeys: false,
|
quoteMapKeys: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type annotation struct {
|
||||||
|
tag string
|
||||||
|
comment string
|
||||||
|
commented string
|
||||||
|
multiline string
|
||||||
|
defaultValue string
|
||||||
|
}
|
||||||
|
|
||||||
|
var annotationDefault = annotation{
|
||||||
|
tag: tagFieldName,
|
||||||
|
comment: tagFieldComment,
|
||||||
|
commented: tagCommented,
|
||||||
|
multiline: tagMultiline,
|
||||||
|
defaultValue: tagDefault,
|
||||||
|
}
|
||||||
|
|
||||||
|
type marshalOrder int
|
||||||
|
|
||||||
|
// Orders the Encoder can write the fields to the output stream.
|
||||||
|
const (
|
||||||
|
// Sort fields alphabetically.
|
||||||
|
OrderAlphabetical marshalOrder = iota + 1
|
||||||
|
// Preserve the order the fields are encountered. For example, the order of fields in
|
||||||
|
// a struct.
|
||||||
|
OrderPreserve
|
||||||
|
)
|
||||||
|
|
||||||
var timeType = reflect.TypeOf(time.Time{})
|
var timeType = reflect.TypeOf(time.Time{})
|
||||||
var marshalerType = reflect.TypeOf(new(Marshaler)).Elem()
|
var marshalerType = reflect.TypeOf(new(Marshaler)).Elem()
|
||||||
|
var localDateType = reflect.TypeOf(LocalDate{})
|
||||||
|
var localTimeType = reflect.TypeOf(LocalTime{})
|
||||||
|
var localDateTimeType = reflect.TypeOf(LocalDateTime{})
|
||||||
|
|
||||||
// Check if the given marshall type maps to a Tree primitive
|
// Check if the given marshal type maps to a Tree primitive
|
||||||
func isPrimitive(mtype reflect.Type) bool {
|
func isPrimitive(mtype reflect.Type) bool {
|
||||||
switch mtype.Kind() {
|
switch mtype.Kind() {
|
||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
@ -50,37 +88,41 @@ func isPrimitive(mtype reflect.Type) bool {
|
|||||||
case reflect.String:
|
case reflect.String:
|
||||||
return true
|
return true
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
return mtype == timeType || isCustomMarshaler(mtype)
|
return mtype == timeType || mtype == localDateType || mtype == localDateTimeType || mtype == localTimeType || isCustomMarshaler(mtype)
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the given marshall type maps to a Tree slice
|
// Check if the given marshal type maps to a Tree slice or array
|
||||||
func isTreeSlice(mtype reflect.Type) bool {
|
func isTreeSequence(mtype reflect.Type) bool {
|
||||||
switch mtype.Kind() {
|
|
||||||
case reflect.Slice:
|
|
||||||
return !isOtherSlice(mtype)
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the given marshall type maps to a non-Tree slice
|
|
||||||
func isOtherSlice(mtype reflect.Type) bool {
|
|
||||||
switch mtype.Kind() {
|
switch mtype.Kind() {
|
||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
return isOtherSlice(mtype.Elem())
|
return isTreeSequence(mtype.Elem())
|
||||||
case reflect.Slice:
|
case reflect.Slice, reflect.Array:
|
||||||
return isPrimitive(mtype.Elem()) || isOtherSlice(mtype.Elem())
|
return isTree(mtype.Elem())
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the given marshall type maps to a Tree
|
// Check if the given marshal type maps to a non-Tree slice or array
|
||||||
|
func isOtherSequence(mtype reflect.Type) bool {
|
||||||
|
switch mtype.Kind() {
|
||||||
|
case reflect.Ptr:
|
||||||
|
return isOtherSequence(mtype.Elem())
|
||||||
|
case reflect.Slice, reflect.Array:
|
||||||
|
return !isTreeSequence(mtype)
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the given marshal type maps to a Tree
|
||||||
func isTree(mtype reflect.Type) bool {
|
func isTree(mtype reflect.Type) bool {
|
||||||
switch mtype.Kind() {
|
switch mtype.Kind() {
|
||||||
|
case reflect.Ptr:
|
||||||
|
return isTree(mtype.Elem())
|
||||||
case reflect.Map:
|
case reflect.Map:
|
||||||
return true
|
return true
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
@ -135,7 +177,9 @@ Tree primitive types and corresponding marshal types:
|
|||||||
float64 float32, float64, pointers to same
|
float64 float32, float64, pointers to same
|
||||||
string string, pointers to same
|
string string, pointers to same
|
||||||
bool bool, pointers to same
|
bool bool, pointers to same
|
||||||
time.Time time.Time{}, pointers to same
|
time.LocalTime time.LocalTime{}, pointers to same
|
||||||
|
|
||||||
|
For additional flexibility, use the Encoder API.
|
||||||
*/
|
*/
|
||||||
func Marshal(v interface{}) ([]byte, error) {
|
func Marshal(v interface{}) ([]byte, error) {
|
||||||
return NewEncoder(nil).marshal(v)
|
return NewEncoder(nil).marshal(v)
|
||||||
@ -145,13 +189,21 @@ func Marshal(v interface{}) ([]byte, error) {
|
|||||||
type Encoder struct {
|
type Encoder struct {
|
||||||
w io.Writer
|
w io.Writer
|
||||||
encOpts
|
encOpts
|
||||||
|
annotation
|
||||||
|
line int
|
||||||
|
col int
|
||||||
|
order marshalOrder
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEncoder returns a new encoder that writes to w.
|
// NewEncoder returns a new encoder that writes to w.
|
||||||
func NewEncoder(w io.Writer) *Encoder {
|
func NewEncoder(w io.Writer) *Encoder {
|
||||||
return &Encoder{
|
return &Encoder{
|
||||||
w: w,
|
w: w,
|
||||||
encOpts: encOptsDefaults,
|
encOpts: encOptsDefaults,
|
||||||
|
annotation: annotationDefault,
|
||||||
|
line: 0,
|
||||||
|
col: 1,
|
||||||
|
order: OrderAlphabetical,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,11 +249,49 @@ func (e *Encoder) ArraysWithOneElementPerLine(v bool) *Encoder {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Order allows to change in which order fields will be written to the output stream.
|
||||||
|
func (e *Encoder) Order(ord marshalOrder) *Encoder {
|
||||||
|
e.order = ord
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTagName allows changing default tag "toml"
|
||||||
|
func (e *Encoder) SetTagName(v string) *Encoder {
|
||||||
|
e.tag = v
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTagComment allows changing default tag "comment"
|
||||||
|
func (e *Encoder) SetTagComment(v string) *Encoder {
|
||||||
|
e.comment = v
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTagCommented allows changing default tag "commented"
|
||||||
|
func (e *Encoder) SetTagCommented(v string) *Encoder {
|
||||||
|
e.commented = v
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTagMultiline allows changing default tag "multiline"
|
||||||
|
func (e *Encoder) SetTagMultiline(v string) *Encoder {
|
||||||
|
e.multiline = v
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Encoder) marshal(v interface{}) ([]byte, error) {
|
func (e *Encoder) marshal(v interface{}) ([]byte, error) {
|
||||||
mtype := reflect.TypeOf(v)
|
mtype := reflect.TypeOf(v)
|
||||||
if mtype.Kind() != reflect.Struct {
|
|
||||||
return []byte{}, errors.New("Only a struct can be marshaled to TOML")
|
switch mtype.Kind() {
|
||||||
|
case reflect.Struct, reflect.Map:
|
||||||
|
case reflect.Ptr:
|
||||||
|
if mtype.Elem().Kind() != reflect.Struct {
|
||||||
|
return []byte{}, errors.New("Only pointer to struct can be marshaled to TOML")
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return []byte{}, errors.New("Only a struct or map can be marshaled to TOML")
|
||||||
}
|
}
|
||||||
|
|
||||||
sval := reflect.ValueOf(v)
|
sval := reflect.ValueOf(v)
|
||||||
if isCustomMarshaler(mtype) {
|
if isCustomMarshaler(mtype) {
|
||||||
return callCustomMarshaler(sval)
|
return callCustomMarshaler(sval)
|
||||||
@ -212,22 +302,27 @@ func (e *Encoder) marshal(v interface{}) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
_, err = t.writeTo(&buf, "", "", 0, e.arraysOneElementPerLine)
|
_, err = t.writeToOrdered(&buf, "", "", 0, e.arraysOneElementPerLine, e.order)
|
||||||
|
|
||||||
return buf.Bytes(), err
|
return buf.Bytes(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create next tree with a position based on Encoder.line
|
||||||
|
func (e *Encoder) nextTree() *Tree {
|
||||||
|
return newTreeWithPosition(Position{Line: e.line, Col: 1})
|
||||||
|
}
|
||||||
|
|
||||||
// Convert given marshal struct or map value to toml tree
|
// Convert given marshal struct or map value to toml tree
|
||||||
func (e *Encoder) valueToTree(mtype reflect.Type, mval reflect.Value) (*Tree, error) {
|
func (e *Encoder) valueToTree(mtype reflect.Type, mval reflect.Value) (*Tree, error) {
|
||||||
if mtype.Kind() == reflect.Ptr {
|
if mtype.Kind() == reflect.Ptr {
|
||||||
return e.valueToTree(mtype.Elem(), mval.Elem())
|
return e.valueToTree(mtype.Elem(), mval.Elem())
|
||||||
}
|
}
|
||||||
tval := newTree()
|
tval := e.nextTree()
|
||||||
switch mtype.Kind() {
|
switch mtype.Kind() {
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
for i := 0; i < mtype.NumField(); i++ {
|
for i := 0; i < mtype.NumField(); i++ {
|
||||||
mtypef, mvalf := mtype.Field(i), mval.Field(i)
|
mtypef, mvalf := mtype.Field(i), mval.Field(i)
|
||||||
opts := tomlOptions(mtypef)
|
opts := tomlOptions(mtypef, e.annotation)
|
||||||
if opts.include && (!opts.omitempty || !isZero(mvalf)) {
|
if opts.include && (!opts.omitempty || !isZero(mvalf)) {
|
||||||
val, err := e.valueToToml(mtypef.Type, mvalf)
|
val, err := e.valueToToml(mtypef.Type, mvalf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -242,7 +337,26 @@ func (e *Encoder) valueToTree(mtype reflect.Type, mval reflect.Value) (*Tree, er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case reflect.Map:
|
case reflect.Map:
|
||||||
for _, key := range mval.MapKeys() {
|
keys := mval.MapKeys()
|
||||||
|
if e.order == OrderPreserve && len(keys) > 0 {
|
||||||
|
// Sorting []reflect.Value is not straight forward.
|
||||||
|
//
|
||||||
|
// OrderPreserve will support deterministic results when string is used
|
||||||
|
// as the key to maps.
|
||||||
|
typ := keys[0].Type()
|
||||||
|
kind := keys[0].Kind()
|
||||||
|
if kind == reflect.String {
|
||||||
|
ikeys := make([]string, len(keys))
|
||||||
|
for i := range keys {
|
||||||
|
ikeys[i] = keys[i].Interface().(string)
|
||||||
|
}
|
||||||
|
sort.Strings(ikeys)
|
||||||
|
for i := range ikeys {
|
||||||
|
keys[i] = reflect.ValueOf(ikeys[i]).Convert(typ)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, key := range keys {
|
||||||
mvalf := mval.MapIndex(key)
|
mvalf := mval.MapIndex(key)
|
||||||
val, err := e.valueToToml(mtype.Elem(), mvalf)
|
val, err := e.valueToToml(mtype.Elem(), mvalf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -290,6 +404,7 @@ func (e *Encoder) valueToOtherSlice(mtype reflect.Type, mval reflect.Value) (int
|
|||||||
|
|
||||||
// Convert given marshal value to toml value
|
// Convert given marshal value to toml value
|
||||||
func (e *Encoder) valueToToml(mtype reflect.Type, mval reflect.Value) (interface{}, error) {
|
func (e *Encoder) valueToToml(mtype reflect.Type, mval reflect.Value) (interface{}, error) {
|
||||||
|
e.line++
|
||||||
if mtype.Kind() == reflect.Ptr {
|
if mtype.Kind() == reflect.Ptr {
|
||||||
return e.valueToToml(mtype.Elem(), mval.Elem())
|
return e.valueToToml(mtype.Elem(), mval.Elem())
|
||||||
}
|
}
|
||||||
@ -298,15 +413,18 @@ func (e *Encoder) valueToToml(mtype reflect.Type, mval reflect.Value) (interface
|
|||||||
return callCustomMarshaler(mval)
|
return callCustomMarshaler(mval)
|
||||||
case isTree(mtype):
|
case isTree(mtype):
|
||||||
return e.valueToTree(mtype, mval)
|
return e.valueToTree(mtype, mval)
|
||||||
case isTreeSlice(mtype):
|
case isTreeSequence(mtype):
|
||||||
return e.valueToTreeSlice(mtype, mval)
|
return e.valueToTreeSlice(mtype, mval)
|
||||||
case isOtherSlice(mtype):
|
case isOtherSequence(mtype):
|
||||||
return e.valueToOtherSlice(mtype, mval)
|
return e.valueToOtherSlice(mtype, mval)
|
||||||
default:
|
default:
|
||||||
switch mtype.Kind() {
|
switch mtype.Kind() {
|
||||||
case reflect.Bool:
|
case reflect.Bool:
|
||||||
return mval.Bool(), nil
|
return mval.Bool(), nil
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||||
|
if mtype.Kind() == reflect.Int64 && mtype == reflect.TypeOf(time.Duration(1)) {
|
||||||
|
return fmt.Sprint(mval), nil
|
||||||
|
}
|
||||||
return mval.Int(), nil
|
return mval.Int(), nil
|
||||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||||
return mval.Uint(), nil
|
return mval.Uint(), nil
|
||||||
@ -315,7 +433,7 @@ func (e *Encoder) valueToToml(mtype reflect.Type, mval reflect.Value) (interface
|
|||||||
case reflect.String:
|
case reflect.String:
|
||||||
return mval.String(), nil
|
return mval.String(), nil
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
return mval.Interface().(time.Time), nil
|
return mval.Interface(), nil
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Marshal can't handle %v(%v)", mtype, mtype.Kind())
|
return nil, fmt.Errorf("Marshal can't handle %v(%v)", mtype, mtype.Kind())
|
||||||
}
|
}
|
||||||
@ -326,7 +444,7 @@ func (e *Encoder) valueToToml(mtype reflect.Type, mval reflect.Value) (interface
|
|||||||
// Neither Unmarshaler interfaces nor UnmarshalTOML functions are supported for
|
// Neither Unmarshaler interfaces nor UnmarshalTOML functions are supported for
|
||||||
// sub-structs, and only definite types can be unmarshaled.
|
// sub-structs, and only definite types can be unmarshaled.
|
||||||
func (t *Tree) Unmarshal(v interface{}) error {
|
func (t *Tree) Unmarshal(v interface{}) error {
|
||||||
d := Decoder{tval: t}
|
d := Decoder{tval: t, tagName: tagFieldName}
|
||||||
return d.unmarshal(v)
|
return d.unmarshal(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,8 +452,11 @@ func (t *Tree) Unmarshal(v interface{}) error {
|
|||||||
// See Marshal() documentation for types mapping table.
|
// See Marshal() documentation for types mapping table.
|
||||||
func (t *Tree) Marshal() ([]byte, error) {
|
func (t *Tree) Marshal() ([]byte, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
err := NewEncoder(&buf).Encode(t)
|
_, err := t.WriteTo(&buf)
|
||||||
return buf.Bytes(), err
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal parses the TOML-encoded data and stores the result in the value
|
// Unmarshal parses the TOML-encoded data and stores the result in the value
|
||||||
@ -347,6 +468,14 @@ func (t *Tree) Marshal() ([]byte, error) {
|
|||||||
// The following struct annotations are supported:
|
// The following struct annotations are supported:
|
||||||
//
|
//
|
||||||
// toml:"Field" Overrides the field's name to map to.
|
// toml:"Field" Overrides the field's name to map to.
|
||||||
|
// default:"foo" Provides a default value.
|
||||||
|
//
|
||||||
|
// For default values, only fields of the following types are supported:
|
||||||
|
// * string
|
||||||
|
// * bool
|
||||||
|
// * int
|
||||||
|
// * int64
|
||||||
|
// * float64
|
||||||
//
|
//
|
||||||
// See Marshal() documentation for types mapping table.
|
// See Marshal() documentation for types mapping table.
|
||||||
func Unmarshal(data []byte, v interface{}) error {
|
func Unmarshal(data []byte, v interface{}) error {
|
||||||
@ -362,6 +491,7 @@ type Decoder struct {
|
|||||||
r io.Reader
|
r io.Reader
|
||||||
tval *Tree
|
tval *Tree
|
||||||
encOpts
|
encOpts
|
||||||
|
tagName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDecoder returns a new decoder that reads from r.
|
// NewDecoder returns a new decoder that reads from r.
|
||||||
@ -369,6 +499,7 @@ func NewDecoder(r io.Reader) *Decoder {
|
|||||||
return &Decoder{
|
return &Decoder{
|
||||||
r: r,
|
r: r,
|
||||||
encOpts: encOptsDefaults,
|
encOpts: encOptsDefaults,
|
||||||
|
tagName: tagFieldName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,13 +516,29 @@ func (d *Decoder) Decode(v interface{}) error {
|
|||||||
return d.unmarshal(v)
|
return d.unmarshal(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetTagName allows changing default tag "toml"
|
||||||
|
func (d *Decoder) SetTagName(v string) *Decoder {
|
||||||
|
d.tagName = v
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Decoder) unmarshal(v interface{}) error {
|
func (d *Decoder) unmarshal(v interface{}) error {
|
||||||
mtype := reflect.TypeOf(v)
|
mtype := reflect.TypeOf(v)
|
||||||
if mtype.Kind() != reflect.Ptr || mtype.Elem().Kind() != reflect.Struct {
|
if mtype.Kind() != reflect.Ptr {
|
||||||
return errors.New("Only a pointer to struct can be unmarshaled from TOML")
|
return errors.New("only a pointer to struct or map can be unmarshaled from TOML")
|
||||||
}
|
}
|
||||||
|
|
||||||
sval, err := d.valueFromTree(mtype.Elem(), d.tval)
|
elem := mtype.Elem()
|
||||||
|
|
||||||
|
switch elem.Kind() {
|
||||||
|
case reflect.Struct, reflect.Map:
|
||||||
|
default:
|
||||||
|
return errors.New("only a pointer to struct or map can be unmarshaled from TOML")
|
||||||
|
}
|
||||||
|
|
||||||
|
vv := reflect.ValueOf(v).Elem()
|
||||||
|
|
||||||
|
sval, err := d.valueFromTree(elem, d.tval, &vv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -399,34 +546,92 @@ func (d *Decoder) unmarshal(v interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert toml tree to marshal struct or map, using marshal type
|
// Convert toml tree to marshal struct or map, using marshal type. When mval1
|
||||||
func (d *Decoder) valueFromTree(mtype reflect.Type, tval *Tree) (reflect.Value, error) {
|
// is non-nil, merge fields into the given value instead of allocating a new one.
|
||||||
|
func (d *Decoder) valueFromTree(mtype reflect.Type, tval *Tree, mval1 *reflect.Value) (reflect.Value, error) {
|
||||||
if mtype.Kind() == reflect.Ptr {
|
if mtype.Kind() == reflect.Ptr {
|
||||||
return d.unwrapPointer(mtype, tval)
|
return d.unwrapPointer(mtype, tval, mval1)
|
||||||
}
|
}
|
||||||
var mval reflect.Value
|
var mval reflect.Value
|
||||||
switch mtype.Kind() {
|
switch mtype.Kind() {
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
mval = reflect.New(mtype).Elem()
|
if mval1 != nil {
|
||||||
|
mval = *mval1
|
||||||
|
} else {
|
||||||
|
mval = reflect.New(mtype).Elem()
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0; i < mtype.NumField(); i++ {
|
for i := 0; i < mtype.NumField(); i++ {
|
||||||
mtypef := mtype.Field(i)
|
mtypef := mtype.Field(i)
|
||||||
opts := tomlOptions(mtypef)
|
an := annotation{tag: d.tagName}
|
||||||
|
opts := tomlOptions(mtypef, an)
|
||||||
if opts.include {
|
if opts.include {
|
||||||
baseKey := opts.name
|
baseKey := opts.name
|
||||||
keysToTry := []string{baseKey, strings.ToLower(baseKey), strings.ToTitle(baseKey)}
|
keysToTry := []string{
|
||||||
|
baseKey,
|
||||||
|
strings.ToLower(baseKey),
|
||||||
|
strings.ToTitle(baseKey),
|
||||||
|
strings.ToLower(string(baseKey[0])) + baseKey[1:],
|
||||||
|
}
|
||||||
|
|
||||||
|
found := false
|
||||||
for _, key := range keysToTry {
|
for _, key := range keysToTry {
|
||||||
exists := tval.Has(key)
|
exists := tval.Has(key)
|
||||||
if !exists {
|
if !exists {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
val := tval.Get(key)
|
val := tval.Get(key)
|
||||||
mvalf, err := d.valueFromToml(mtypef.Type, val)
|
fval := mval.Field(i)
|
||||||
|
mvalf, err := d.valueFromToml(mtypef.Type, val, &fval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return mval, formatError(err, tval.GetPosition(key))
|
return mval, formatError(err, tval.GetPosition(key))
|
||||||
}
|
}
|
||||||
mval.Field(i).Set(mvalf)
|
mval.Field(i).Set(mvalf)
|
||||||
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !found && opts.defaultValue != "" {
|
||||||
|
mvalf := mval.Field(i)
|
||||||
|
var val interface{}
|
||||||
|
var err error
|
||||||
|
switch mvalf.Kind() {
|
||||||
|
case reflect.Bool:
|
||||||
|
val, err = strconv.ParseBool(opts.defaultValue)
|
||||||
|
if err != nil {
|
||||||
|
return mval.Field(i), err
|
||||||
|
}
|
||||||
|
case reflect.Int:
|
||||||
|
val, err = strconv.Atoi(opts.defaultValue)
|
||||||
|
if err != nil {
|
||||||
|
return mval.Field(i), err
|
||||||
|
}
|
||||||
|
case reflect.String:
|
||||||
|
val = opts.defaultValue
|
||||||
|
case reflect.Int64:
|
||||||
|
val, err = strconv.ParseInt(opts.defaultValue, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return mval.Field(i), err
|
||||||
|
}
|
||||||
|
case reflect.Float64:
|
||||||
|
val, err = strconv.ParseFloat(opts.defaultValue, 64)
|
||||||
|
if err != nil {
|
||||||
|
return mval.Field(i), err
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return mval.Field(i), fmt.Errorf("unsuported field type for default option")
|
||||||
|
}
|
||||||
|
mval.Field(i).Set(reflect.ValueOf(val))
|
||||||
|
}
|
||||||
|
|
||||||
|
// save the old behavior above and try to check anonymous structs
|
||||||
|
if !found && opts.defaultValue == "" && mtypef.Anonymous && mtypef.Type.Kind() == reflect.Struct {
|
||||||
|
v, err := d.valueFromTree(mtypef.Type, tval, nil)
|
||||||
|
if err != nil {
|
||||||
|
return v, err
|
||||||
|
}
|
||||||
|
mval.Field(i).Set(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case reflect.Map:
|
case reflect.Map:
|
||||||
@ -434,11 +639,11 @@ func (d *Decoder) valueFromTree(mtype reflect.Type, tval *Tree) (reflect.Value,
|
|||||||
for _, key := range tval.Keys() {
|
for _, key := range tval.Keys() {
|
||||||
// TODO: path splits key
|
// TODO: path splits key
|
||||||
val := tval.GetPath([]string{key})
|
val := tval.GetPath([]string{key})
|
||||||
mvalf, err := d.valueFromToml(mtype.Elem(), val)
|
mvalf, err := d.valueFromToml(mtype.Elem(), val, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return mval, formatError(err, tval.GetPosition(key))
|
return mval, formatError(err, tval.GetPosition(key))
|
||||||
}
|
}
|
||||||
mval.SetMapIndex(reflect.ValueOf(key), mvalf)
|
mval.SetMapIndex(reflect.ValueOf(key).Convert(mtype.Key()), mvalf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mval, nil
|
return mval, nil
|
||||||
@ -448,7 +653,7 @@ func (d *Decoder) valueFromTree(mtype reflect.Type, tval *Tree) (reflect.Value,
|
|||||||
func (d *Decoder) valueFromTreeSlice(mtype reflect.Type, tval []*Tree) (reflect.Value, error) {
|
func (d *Decoder) valueFromTreeSlice(mtype reflect.Type, tval []*Tree) (reflect.Value, error) {
|
||||||
mval := reflect.MakeSlice(mtype, len(tval), len(tval))
|
mval := reflect.MakeSlice(mtype, len(tval), len(tval))
|
||||||
for i := 0; i < len(tval); i++ {
|
for i := 0; i < len(tval); i++ {
|
||||||
val, err := d.valueFromTree(mtype.Elem(), tval[i])
|
val, err := d.valueFromTree(mtype.Elem(), tval[i], nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return mval, err
|
return mval, err
|
||||||
}
|
}
|
||||||
@ -461,7 +666,7 @@ func (d *Decoder) valueFromTreeSlice(mtype reflect.Type, tval []*Tree) (reflect.
|
|||||||
func (d *Decoder) valueFromOtherSlice(mtype reflect.Type, tval []interface{}) (reflect.Value, error) {
|
func (d *Decoder) valueFromOtherSlice(mtype reflect.Type, tval []interface{}) (reflect.Value, error) {
|
||||||
mval := reflect.MakeSlice(mtype, len(tval), len(tval))
|
mval := reflect.MakeSlice(mtype, len(tval), len(tval))
|
||||||
for i := 0; i < len(tval); i++ {
|
for i := 0; i < len(tval); i++ {
|
||||||
val, err := d.valueFromToml(mtype.Elem(), tval[i])
|
val, err := d.valueFromToml(mtype.Elem(), tval[i], nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return mval, err
|
return mval, err
|
||||||
}
|
}
|
||||||
@ -470,33 +675,63 @@ func (d *Decoder) valueFromOtherSlice(mtype reflect.Type, tval []interface{}) (r
|
|||||||
return mval, nil
|
return mval, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert toml value to marshal value, using marshal type
|
// Convert toml value to marshal value, using marshal type. When mval1 is non-nil
|
||||||
func (d *Decoder) valueFromToml(mtype reflect.Type, tval interface{}) (reflect.Value, error) {
|
// and the given type is a struct value, merge fields into it.
|
||||||
|
func (d *Decoder) valueFromToml(mtype reflect.Type, tval interface{}, mval1 *reflect.Value) (reflect.Value, error) {
|
||||||
if mtype.Kind() == reflect.Ptr {
|
if mtype.Kind() == reflect.Ptr {
|
||||||
return d.unwrapPointer(mtype, tval)
|
return d.unwrapPointer(mtype, tval, mval1)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch tval.(type) {
|
switch t := tval.(type) {
|
||||||
case *Tree:
|
case *Tree:
|
||||||
|
var mval11 *reflect.Value
|
||||||
|
if mtype.Kind() == reflect.Struct {
|
||||||
|
mval11 = mval1
|
||||||
|
}
|
||||||
|
|
||||||
if isTree(mtype) {
|
if isTree(mtype) {
|
||||||
return d.valueFromTree(mtype, tval.(*Tree))
|
return d.valueFromTree(mtype, t, mval11)
|
||||||
}
|
}
|
||||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to a tree", tval, tval)
|
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to a tree", tval, tval)
|
||||||
case []*Tree:
|
case []*Tree:
|
||||||
if isTreeSlice(mtype) {
|
if isTreeSequence(mtype) {
|
||||||
return d.valueFromTreeSlice(mtype, tval.([]*Tree))
|
return d.valueFromTreeSlice(mtype, t)
|
||||||
}
|
}
|
||||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to trees", tval, tval)
|
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to trees", tval, tval)
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
if isOtherSlice(mtype) {
|
if isOtherSequence(mtype) {
|
||||||
return d.valueFromOtherSlice(mtype, tval.([]interface{}))
|
return d.valueFromOtherSlice(mtype, t)
|
||||||
}
|
}
|
||||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to a slice", tval, tval)
|
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to a slice", tval, tval)
|
||||||
default:
|
default:
|
||||||
switch mtype.Kind() {
|
switch mtype.Kind() {
|
||||||
case reflect.Bool, reflect.Struct:
|
case reflect.Bool, reflect.Struct:
|
||||||
val := reflect.ValueOf(tval)
|
val := reflect.ValueOf(tval)
|
||||||
// if this passes for when mtype is reflect.Struct, tval is a time.Time
|
|
||||||
|
switch val.Type() {
|
||||||
|
case localDateType:
|
||||||
|
localDate := val.Interface().(LocalDate)
|
||||||
|
switch mtype {
|
||||||
|
case timeType:
|
||||||
|
return reflect.ValueOf(time.Date(localDate.Year, localDate.Month, localDate.Day, 0, 0, 0, 0, time.Local)), nil
|
||||||
|
}
|
||||||
|
case localDateTimeType:
|
||||||
|
localDateTime := val.Interface().(LocalDateTime)
|
||||||
|
switch mtype {
|
||||||
|
case timeType:
|
||||||
|
return reflect.ValueOf(time.Date(
|
||||||
|
localDateTime.Date.Year,
|
||||||
|
localDateTime.Date.Month,
|
||||||
|
localDateTime.Date.Day,
|
||||||
|
localDateTime.Time.Hour,
|
||||||
|
localDateTime.Time.Minute,
|
||||||
|
localDateTime.Time.Second,
|
||||||
|
localDateTime.Time.Nanosecond,
|
||||||
|
time.Local)), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if this passes for when mtype is reflect.Struct, tval is a time.LocalTime
|
||||||
if !val.Type().ConvertibleTo(mtype) {
|
if !val.Type().ConvertibleTo(mtype) {
|
||||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v", tval, tval, mtype.String())
|
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v", tval, tval, mtype.String())
|
||||||
}
|
}
|
||||||
@ -512,10 +747,17 @@ func (d *Decoder) valueFromToml(mtype reflect.Type, tval interface{}) (reflect.V
|
|||||||
return val.Convert(mtype), nil
|
return val.Convert(mtype), nil
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||||
val := reflect.ValueOf(tval)
|
val := reflect.ValueOf(tval)
|
||||||
|
if mtype.Kind() == reflect.Int64 && mtype == reflect.TypeOf(time.Duration(1)) && val.Kind() == reflect.String {
|
||||||
|
d, err := time.ParseDuration(val.String())
|
||||||
|
if err != nil {
|
||||||
|
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v. %s", tval, tval, mtype.String(), err)
|
||||||
|
}
|
||||||
|
return reflect.ValueOf(d), nil
|
||||||
|
}
|
||||||
if !val.Type().ConvertibleTo(mtype) {
|
if !val.Type().ConvertibleTo(mtype) {
|
||||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v", tval, tval, mtype.String())
|
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v", tval, tval, mtype.String())
|
||||||
}
|
}
|
||||||
if reflect.Indirect(reflect.New(mtype)).OverflowInt(val.Int()) {
|
if reflect.Indirect(reflect.New(mtype)).OverflowInt(val.Convert(mtype).Int()) {
|
||||||
return reflect.ValueOf(nil), fmt.Errorf("%v(%T) would overflow %v", tval, tval, mtype.String())
|
return reflect.ValueOf(nil), fmt.Errorf("%v(%T) would overflow %v", tval, tval, mtype.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,10 +767,11 @@ func (d *Decoder) valueFromToml(mtype reflect.Type, tval interface{}) (reflect.V
|
|||||||
if !val.Type().ConvertibleTo(mtype) {
|
if !val.Type().ConvertibleTo(mtype) {
|
||||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v", tval, tval, mtype.String())
|
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v", tval, tval, mtype.String())
|
||||||
}
|
}
|
||||||
if val.Int() < 0 {
|
|
||||||
|
if val.Convert(reflect.TypeOf(int(1))).Int() < 0 {
|
||||||
return reflect.ValueOf(nil), fmt.Errorf("%v(%T) is negative so does not fit in %v", tval, tval, mtype.String())
|
return reflect.ValueOf(nil), fmt.Errorf("%v(%T) is negative so does not fit in %v", tval, tval, mtype.String())
|
||||||
}
|
}
|
||||||
if reflect.Indirect(reflect.New(mtype)).OverflowUint(uint64(val.Int())) {
|
if reflect.Indirect(reflect.New(mtype)).OverflowUint(uint64(val.Convert(mtype).Uint())) {
|
||||||
return reflect.ValueOf(nil), fmt.Errorf("%v(%T) would overflow %v", tval, tval, mtype.String())
|
return reflect.ValueOf(nil), fmt.Errorf("%v(%T) would overflow %v", tval, tval, mtype.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,7 +781,7 @@ func (d *Decoder) valueFromToml(mtype reflect.Type, tval interface{}) (reflect.V
|
|||||||
if !val.Type().ConvertibleTo(mtype) {
|
if !val.Type().ConvertibleTo(mtype) {
|
||||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v", tval, tval, mtype.String())
|
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v", tval, tval, mtype.String())
|
||||||
}
|
}
|
||||||
if reflect.Indirect(reflect.New(mtype)).OverflowFloat(val.Float()) {
|
if reflect.Indirect(reflect.New(mtype)).OverflowFloat(val.Convert(mtype).Float()) {
|
||||||
return reflect.ValueOf(nil), fmt.Errorf("%v(%T) would overflow %v", tval, tval, mtype.String())
|
return reflect.ValueOf(nil), fmt.Errorf("%v(%T) would overflow %v", tval, tval, mtype.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -549,8 +792,15 @@ func (d *Decoder) valueFromToml(mtype reflect.Type, tval interface{}) (reflect.V
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) unwrapPointer(mtype reflect.Type, tval interface{}) (reflect.Value, error) {
|
func (d *Decoder) unwrapPointer(mtype reflect.Type, tval interface{}, mval1 *reflect.Value) (reflect.Value, error) {
|
||||||
val, err := d.valueFromToml(mtype.Elem(), tval)
|
var melem *reflect.Value
|
||||||
|
|
||||||
|
if mval1 != nil && !mval1.IsNil() && mtype.Elem().Kind() == reflect.Struct {
|
||||||
|
elem := mval1.Elem()
|
||||||
|
melem = &elem
|
||||||
|
}
|
||||||
|
|
||||||
|
val, err := d.valueFromToml(mtype.Elem(), tval, melem)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return reflect.ValueOf(nil), err
|
return reflect.ValueOf(nil), err
|
||||||
}
|
}
|
||||||
@ -559,16 +809,25 @@ func (d *Decoder) unwrapPointer(mtype reflect.Type, tval interface{}) (reflect.V
|
|||||||
return mval, nil
|
return mval, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func tomlOptions(vf reflect.StructField) tomlOpts {
|
func tomlOptions(vf reflect.StructField, an annotation) tomlOpts {
|
||||||
tag := vf.Tag.Get("toml")
|
tag := vf.Tag.Get(an.tag)
|
||||||
parse := strings.Split(tag, ",")
|
parse := strings.Split(tag, ",")
|
||||||
var comment string
|
var comment string
|
||||||
if c := vf.Tag.Get("comment"); c != "" {
|
if c := vf.Tag.Get(an.comment); c != "" {
|
||||||
comment = c
|
comment = c
|
||||||
}
|
}
|
||||||
commented, _ := strconv.ParseBool(vf.Tag.Get("commented"))
|
commented, _ := strconv.ParseBool(vf.Tag.Get(an.commented))
|
||||||
multiline, _ := strconv.ParseBool(vf.Tag.Get(tagKeyMultiline))
|
multiline, _ := strconv.ParseBool(vf.Tag.Get(an.multiline))
|
||||||
result := tomlOpts{name: vf.Name, comment: comment, commented: commented, multiline: multiline, include: true, omitempty: false}
|
defaultValue := vf.Tag.Get(tagDefault)
|
||||||
|
result := tomlOpts{
|
||||||
|
name: vf.Name,
|
||||||
|
comment: comment,
|
||||||
|
commented: commented,
|
||||||
|
multiline: multiline,
|
||||||
|
include: true,
|
||||||
|
omitempty: false,
|
||||||
|
defaultValue: defaultValue,
|
||||||
|
}
|
||||||
if parse[0] != "" {
|
if parse[0] != "" {
|
||||||
if parse[0] == "-" && len(parse) == 1 {
|
if parse[0] == "-" && len(parse) == 1 {
|
||||||
result.include = false
|
result.include = false
|
||||||
|
39
vendor/github.com/pelletier/go-toml/marshal_OrderPreserve_test.toml
generated
vendored
Normal file
39
vendor/github.com/pelletier/go-toml/marshal_OrderPreserve_test.toml
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
title = "TOML Marshal Testing"
|
||||||
|
|
||||||
|
[basic_lists]
|
||||||
|
floats = [12.3,45.6,78.9]
|
||||||
|
bools = [true,false,true]
|
||||||
|
dates = [1979-05-27T07:32:00Z,1980-05-27T07:32:00Z]
|
||||||
|
ints = [8001,8001,8002]
|
||||||
|
uints = [5002,5003]
|
||||||
|
strings = ["One","Two","Three"]
|
||||||
|
|
||||||
|
[[subdocptrs]]
|
||||||
|
name = "Second"
|
||||||
|
|
||||||
|
[basic_map]
|
||||||
|
one = "one"
|
||||||
|
two = "two"
|
||||||
|
|
||||||
|
[subdoc]
|
||||||
|
|
||||||
|
[subdoc.second]
|
||||||
|
name = "Second"
|
||||||
|
|
||||||
|
[subdoc.first]
|
||||||
|
name = "First"
|
||||||
|
|
||||||
|
[basic]
|
||||||
|
uint = 5001
|
||||||
|
bool = true
|
||||||
|
float = 123.4
|
||||||
|
float64 = 123.456782132399
|
||||||
|
int = 5000
|
||||||
|
string = "Bite me"
|
||||||
|
date = 1979-05-27T07:32:00Z
|
||||||
|
|
||||||
|
[[subdoclist]]
|
||||||
|
name = "List.First"
|
||||||
|
|
||||||
|
[[subdoclist]]
|
||||||
|
name = "List.Second"
|
1
vendor/github.com/pelletier/go-toml/marshal_test.toml
generated
vendored
1
vendor/github.com/pelletier/go-toml/marshal_test.toml
generated
vendored
@ -4,6 +4,7 @@ title = "TOML Marshal Testing"
|
|||||||
bool = true
|
bool = true
|
||||||
date = 1979-05-27T07:32:00Z
|
date = 1979-05-27T07:32:00Z
|
||||||
float = 123.4
|
float = 123.4
|
||||||
|
float64 = 123.456782132399
|
||||||
int = 5000
|
int = 5000
|
||||||
string = "Bite me"
|
string = "Bite me"
|
||||||
uint = 5001
|
uint = 5001
|
||||||
|
75
vendor/github.com/pelletier/go-toml/parser.go
generated
vendored
75
vendor/github.com/pelletier/go-toml/parser.go
generated
vendored
@ -77,8 +77,10 @@ func (p *tomlParser) parseStart() tomlParserStateFn {
|
|||||||
return p.parseAssign
|
return p.parseAssign
|
||||||
case tokenEOF:
|
case tokenEOF:
|
||||||
return nil
|
return nil
|
||||||
|
case tokenError:
|
||||||
|
p.raiseError(tok, "parsing error: %s", tok.String())
|
||||||
default:
|
default:
|
||||||
p.raiseError(tok, "unexpected token")
|
p.raiseError(tok, "unexpected token %s", tok.typ)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -165,6 +167,11 @@ func (p *tomlParser) parseAssign() tomlParserStateFn {
|
|||||||
key := p.getToken()
|
key := p.getToken()
|
||||||
p.assume(tokenEqual)
|
p.assume(tokenEqual)
|
||||||
|
|
||||||
|
parsedKey, err := parseKey(key.val)
|
||||||
|
if err != nil {
|
||||||
|
p.raiseError(key, "invalid key: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
value := p.parseRvalue()
|
value := p.parseRvalue()
|
||||||
var tableKey []string
|
var tableKey []string
|
||||||
if len(p.currentTable) > 0 {
|
if len(p.currentTable) > 0 {
|
||||||
@ -173,6 +180,9 @@ func (p *tomlParser) parseAssign() tomlParserStateFn {
|
|||||||
tableKey = []string{}
|
tableKey = []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefixKey := parsedKey[0 : len(parsedKey)-1]
|
||||||
|
tableKey = append(tableKey, prefixKey...)
|
||||||
|
|
||||||
// find the table to assign, looking out for arrays of tables
|
// find the table to assign, looking out for arrays of tables
|
||||||
var targetNode *Tree
|
var targetNode *Tree
|
||||||
switch node := p.tree.GetPath(tableKey).(type) {
|
switch node := p.tree.GetPath(tableKey).(type) {
|
||||||
@ -180,17 +190,19 @@ func (p *tomlParser) parseAssign() tomlParserStateFn {
|
|||||||
targetNode = node[len(node)-1]
|
targetNode = node[len(node)-1]
|
||||||
case *Tree:
|
case *Tree:
|
||||||
targetNode = node
|
targetNode = node
|
||||||
|
case nil:
|
||||||
|
// create intermediate
|
||||||
|
if err := p.tree.createSubTree(tableKey, key.Position); err != nil {
|
||||||
|
p.raiseError(key, "could not create intermediate group: %s", err)
|
||||||
|
}
|
||||||
|
targetNode = p.tree.GetPath(tableKey).(*Tree)
|
||||||
default:
|
default:
|
||||||
p.raiseError(key, "Unknown table type for path: %s",
|
p.raiseError(key, "Unknown table type for path: %s",
|
||||||
strings.Join(tableKey, "."))
|
strings.Join(tableKey, "."))
|
||||||
}
|
}
|
||||||
|
|
||||||
// assign value to the found table
|
// assign value to the found table
|
||||||
keyVals := []string{key.val}
|
keyVal := parsedKey[len(parsedKey)-1]
|
||||||
if len(keyVals) != 1 {
|
|
||||||
p.raiseError(key, "Invalid key")
|
|
||||||
}
|
|
||||||
keyVal := keyVals[0]
|
|
||||||
localKey := []string{keyVal}
|
localKey := []string{keyVal}
|
||||||
finalKey := append(tableKey, keyVal)
|
finalKey := append(tableKey, keyVal)
|
||||||
if targetNode.GetPath(localKey) != nil {
|
if targetNode.GetPath(localKey) != nil {
|
||||||
@ -301,7 +313,41 @@ func (p *tomlParser) parseRvalue() interface{} {
|
|||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
case tokenDate:
|
case tokenDate:
|
||||||
val, err := time.ParseInLocation(time.RFC3339Nano, tok.val, time.UTC)
|
layout := time.RFC3339Nano
|
||||||
|
if !strings.Contains(tok.val, "T") {
|
||||||
|
layout = strings.Replace(layout, "T", " ", 1)
|
||||||
|
}
|
||||||
|
val, err := time.ParseInLocation(layout, tok.val, time.UTC)
|
||||||
|
if err != nil {
|
||||||
|
p.raiseError(tok, "%s", err)
|
||||||
|
}
|
||||||
|
return val
|
||||||
|
case tokenLocalDate:
|
||||||
|
v := strings.Replace(tok.val, " ", "T", -1)
|
||||||
|
isDateTime := false
|
||||||
|
isTime := false
|
||||||
|
for _, c := range v {
|
||||||
|
if c == 'T' || c == 't' {
|
||||||
|
isDateTime = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if c == ':' {
|
||||||
|
isTime = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var val interface{}
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if isDateTime {
|
||||||
|
val, err = ParseLocalDateTime(v)
|
||||||
|
} else if isTime {
|
||||||
|
val, err = ParseLocalTime(v)
|
||||||
|
} else {
|
||||||
|
val, err = ParseLocalDate(v)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.raiseError(tok, "%s", err)
|
p.raiseError(tok, "%s", err)
|
||||||
}
|
}
|
||||||
@ -338,18 +384,21 @@ Loop:
|
|||||||
case tokenRightCurlyBrace:
|
case tokenRightCurlyBrace:
|
||||||
p.getToken()
|
p.getToken()
|
||||||
break Loop
|
break Loop
|
||||||
case tokenKey:
|
case tokenKey, tokenInteger, tokenString:
|
||||||
if !tokenIsComma(previous) && previous != nil {
|
if !tokenIsComma(previous) && previous != nil {
|
||||||
p.raiseError(follow, "comma expected between fields in inline table")
|
p.raiseError(follow, "comma expected between fields in inline table")
|
||||||
}
|
}
|
||||||
key := p.getToken()
|
key := p.getToken()
|
||||||
p.assume(tokenEqual)
|
p.assume(tokenEqual)
|
||||||
value := p.parseRvalue()
|
|
||||||
tree.Set(key.val, value)
|
parsedKey, err := parseKey(key.val)
|
||||||
case tokenComma:
|
if err != nil {
|
||||||
if previous == nil {
|
p.raiseError(key, "invalid key: %s", err)
|
||||||
p.raiseError(follow, "inline table cannot start with a comma")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value := p.parseRvalue()
|
||||||
|
tree.SetPath(parsedKey, value)
|
||||||
|
case tokenComma:
|
||||||
if tokenIsComma(previous) {
|
if tokenIsComma(previous) {
|
||||||
p.raiseError(follow, "need field between two commas in inline table")
|
p.raiseError(follow, "need field between two commas in inline table")
|
||||||
}
|
}
|
||||||
|
88
vendor/github.com/pelletier/go-toml/test.sh
generated
vendored
88
vendor/github.com/pelletier/go-toml/test.sh
generated
vendored
@ -1,88 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# fail out of the script if anything here fails
|
|
||||||
set -e
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
# set the path to the present working directory
|
|
||||||
export GOPATH=`pwd`
|
|
||||||
|
|
||||||
function git_clone() {
|
|
||||||
path=$1
|
|
||||||
branch=$2
|
|
||||||
version=$3
|
|
||||||
if [ ! -d "src/$path" ]; then
|
|
||||||
mkdir -p src/$path
|
|
||||||
git clone https://$path.git src/$path
|
|
||||||
fi
|
|
||||||
pushd src/$path
|
|
||||||
git checkout "$branch"
|
|
||||||
git reset --hard "$version"
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
# Remove potential previous runs
|
|
||||||
rm -rf src test_program_bin toml-test
|
|
||||||
|
|
||||||
go get github.com/pelletier/go-buffruneio
|
|
||||||
go get github.com/davecgh/go-spew/spew
|
|
||||||
go get gopkg.in/yaml.v2
|
|
||||||
go get github.com/BurntSushi/toml
|
|
||||||
|
|
||||||
# get code for BurntSushi TOML validation
|
|
||||||
# pinning all to 'HEAD' for version 0.3.x work (TODO: pin to commit hash when tests stabilize)
|
|
||||||
git_clone github.com/BurntSushi/toml master HEAD
|
|
||||||
git_clone github.com/BurntSushi/toml-test master HEAD #was: 0.2.0 HEAD
|
|
||||||
|
|
||||||
# build the BurntSushi test application
|
|
||||||
go build -o toml-test github.com/BurntSushi/toml-test
|
|
||||||
|
|
||||||
# vendorize the current lib for testing
|
|
||||||
# NOTE: this basically mocks an install without having to go back out to github for code
|
|
||||||
mkdir -p src/github.com/pelletier/go-toml/cmd
|
|
||||||
mkdir -p src/github.com/pelletier/go-toml/query
|
|
||||||
cp *.go *.toml src/github.com/pelletier/go-toml
|
|
||||||
cp -R cmd/* src/github.com/pelletier/go-toml/cmd
|
|
||||||
cp -R query/* src/github.com/pelletier/go-toml/query
|
|
||||||
go build -o test_program_bin src/github.com/pelletier/go-toml/cmd/test_program.go
|
|
||||||
|
|
||||||
# Run basic unit tests
|
|
||||||
go test github.com/pelletier/go-toml -covermode=count -coverprofile=coverage.out
|
|
||||||
go test github.com/pelletier/go-toml/cmd/tomljson
|
|
||||||
go test github.com/pelletier/go-toml/query
|
|
||||||
|
|
||||||
# run the entire BurntSushi test suite
|
|
||||||
if [[ $# -eq 0 ]] ; then
|
|
||||||
echo "Running all BurntSushi tests"
|
|
||||||
./toml-test ./test_program_bin | tee test_out
|
|
||||||
else
|
|
||||||
# run a specific test
|
|
||||||
test=$1
|
|
||||||
test_path='src/github.com/BurntSushi/toml-test/tests'
|
|
||||||
valid_test="$test_path/valid/$test"
|
|
||||||
invalid_test="$test_path/invalid/$test"
|
|
||||||
|
|
||||||
if [ -e "$valid_test.toml" ]; then
|
|
||||||
echo "Valid Test TOML for $test:"
|
|
||||||
echo "===="
|
|
||||||
cat "$valid_test.toml"
|
|
||||||
|
|
||||||
echo "Valid Test JSON for $test:"
|
|
||||||
echo "===="
|
|
||||||
cat "$valid_test.json"
|
|
||||||
|
|
||||||
echo "Go-TOML Output for $test:"
|
|
||||||
echo "===="
|
|
||||||
cat "$valid_test.toml" | ./test_program_bin
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -e "$invalid_test.toml" ]; then
|
|
||||||
echo "Invalid Test TOML for $test:"
|
|
||||||
echo "===="
|
|
||||||
cat "$invalid_test.toml"
|
|
||||||
|
|
||||||
echo "Go-TOML Output for $test:"
|
|
||||||
echo "===="
|
|
||||||
echo "go-toml Output:"
|
|
||||||
cat "$invalid_test.toml" | ./test_program_bin
|
|
||||||
fi
|
|
||||||
fi
|
|
13
vendor/github.com/pelletier/go-toml/token.go
generated
vendored
13
vendor/github.com/pelletier/go-toml/token.go
generated
vendored
@ -2,7 +2,6 @@ package toml
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,6 +34,7 @@ const (
|
|||||||
tokenDoubleLeftBracket
|
tokenDoubleLeftBracket
|
||||||
tokenDoubleRightBracket
|
tokenDoubleRightBracket
|
||||||
tokenDate
|
tokenDate
|
||||||
|
tokenLocalDate
|
||||||
tokenKeyGroup
|
tokenKeyGroup
|
||||||
tokenKeyGroupArray
|
tokenKeyGroupArray
|
||||||
tokenComma
|
tokenComma
|
||||||
@ -68,7 +68,8 @@ var tokenTypeNames = []string{
|
|||||||
")",
|
")",
|
||||||
"]]",
|
"]]",
|
||||||
"[[",
|
"[[",
|
||||||
"Date",
|
"LocalDate",
|
||||||
|
"LocalDate",
|
||||||
"KeyGroup",
|
"KeyGroup",
|
||||||
"KeyGroupArray",
|
"KeyGroupArray",
|
||||||
",",
|
",",
|
||||||
@ -95,14 +96,6 @@ func (tt tokenType) String() string {
|
|||||||
return "Unknown"
|
return "Unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t token) Int() int {
|
|
||||||
if result, err := strconv.Atoi(t.val); err != nil {
|
|
||||||
panic(err)
|
|
||||||
} else {
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t token) String() string {
|
func (t token) String() string {
|
||||||
switch t.typ {
|
switch t.typ {
|
||||||
case tokenEOF:
|
case tokenEOF:
|
||||||
|
120
vendor/github.com/pelletier/go-toml/toml.go
generated
vendored
120
vendor/github.com/pelletier/go-toml/toml.go
generated
vendored
@ -27,9 +27,13 @@ type Tree struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newTree() *Tree {
|
func newTree() *Tree {
|
||||||
|
return newTreeWithPosition(Position{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTreeWithPosition(pos Position) *Tree {
|
||||||
return &Tree{
|
return &Tree{
|
||||||
values: make(map[string]interface{}),
|
values: make(map[string]interface{}),
|
||||||
position: Position{},
|
position: pos,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,10 +198,10 @@ func (t *Tree) SetWithOptions(key string, opts SetOptions, value interface{}) {
|
|||||||
// formatting instructions to the key, that will be reused by Marshal().
|
// formatting instructions to the key, that will be reused by Marshal().
|
||||||
func (t *Tree) SetPathWithOptions(keys []string, opts SetOptions, value interface{}) {
|
func (t *Tree) SetPathWithOptions(keys []string, opts SetOptions, value interface{}) {
|
||||||
subtree := t
|
subtree := t
|
||||||
for _, intermediateKey := range keys[:len(keys)-1] {
|
for i, intermediateKey := range keys[:len(keys)-1] {
|
||||||
nextTree, exists := subtree.values[intermediateKey]
|
nextTree, exists := subtree.values[intermediateKey]
|
||||||
if !exists {
|
if !exists {
|
||||||
nextTree = newTree()
|
nextTree = newTreeWithPosition(Position{Line: t.position.Line + i, Col: t.position.Col})
|
||||||
subtree.values[intermediateKey] = nextTree // add new element here
|
subtree.values[intermediateKey] = nextTree // add new element here
|
||||||
}
|
}
|
||||||
switch node := nextTree.(type) {
|
switch node := nextTree.(type) {
|
||||||
@ -207,7 +211,7 @@ func (t *Tree) SetPathWithOptions(keys []string, opts SetOptions, value interfac
|
|||||||
// go to most recent element
|
// go to most recent element
|
||||||
if len(node) == 0 {
|
if len(node) == 0 {
|
||||||
// create element if it does not exist
|
// create element if it does not exist
|
||||||
subtree.values[intermediateKey] = append(node, newTree())
|
subtree.values[intermediateKey] = append(node, newTreeWithPosition(Position{Line: t.position.Line + i, Col: t.position.Col}))
|
||||||
}
|
}
|
||||||
subtree = node[len(node)-1]
|
subtree = node[len(node)-1]
|
||||||
}
|
}
|
||||||
@ -215,19 +219,21 @@ func (t *Tree) SetPathWithOptions(keys []string, opts SetOptions, value interfac
|
|||||||
|
|
||||||
var toInsert interface{}
|
var toInsert interface{}
|
||||||
|
|
||||||
switch value.(type) {
|
switch v := value.(type) {
|
||||||
case *Tree:
|
case *Tree:
|
||||||
tt := value.(*Tree)
|
v.comment = opts.Comment
|
||||||
tt.comment = opts.Comment
|
|
||||||
toInsert = value
|
toInsert = value
|
||||||
case []*Tree:
|
case []*Tree:
|
||||||
toInsert = value
|
toInsert = value
|
||||||
case *tomlValue:
|
case *tomlValue:
|
||||||
tt := value.(*tomlValue)
|
v.comment = opts.Comment
|
||||||
tt.comment = opts.Comment
|
toInsert = v
|
||||||
toInsert = tt
|
|
||||||
default:
|
default:
|
||||||
toInsert = &tomlValue{value: value, comment: opts.Comment, commented: opts.Commented, multiline: opts.Multiline}
|
toInsert = &tomlValue{value: value,
|
||||||
|
comment: opts.Comment,
|
||||||
|
commented: opts.Commented,
|
||||||
|
multiline: opts.Multiline,
|
||||||
|
position: Position{Line: subtree.position.Line + len(subtree.values) + 1, Col: subtree.position.Col}}
|
||||||
}
|
}
|
||||||
|
|
||||||
subtree.values[keys[len(keys)-1]] = toInsert
|
subtree.values[keys[len(keys)-1]] = toInsert
|
||||||
@ -256,44 +262,35 @@ func (t *Tree) SetPath(keys []string, value interface{}) {
|
|||||||
// SetPathWithComment is the same as SetPath, but allows you to provide comment
|
// SetPathWithComment is the same as SetPath, but allows you to provide comment
|
||||||
// information to the key, that will be reused by Marshal().
|
// information to the key, that will be reused by Marshal().
|
||||||
func (t *Tree) SetPathWithComment(keys []string, comment string, commented bool, value interface{}) {
|
func (t *Tree) SetPathWithComment(keys []string, comment string, commented bool, value interface{}) {
|
||||||
subtree := t
|
t.SetPathWithOptions(keys, SetOptions{Comment: comment, Commented: commented}, value)
|
||||||
for _, intermediateKey := range keys[:len(keys)-1] {
|
}
|
||||||
nextTree, exists := subtree.values[intermediateKey]
|
|
||||||
if !exists {
|
// Delete removes a key from the tree.
|
||||||
nextTree = newTree()
|
// Key is a dot-separated path (e.g. a.b.c).
|
||||||
subtree.values[intermediateKey] = nextTree // add new element here
|
func (t *Tree) Delete(key string) error {
|
||||||
}
|
keys, err := parseKey(key)
|
||||||
switch node := nextTree.(type) {
|
if err != nil {
|
||||||
case *Tree:
|
return err
|
||||||
subtree = node
|
|
||||||
case []*Tree:
|
|
||||||
// go to most recent element
|
|
||||||
if len(node) == 0 {
|
|
||||||
// create element if it does not exist
|
|
||||||
subtree.values[intermediateKey] = append(node, newTree())
|
|
||||||
}
|
|
||||||
subtree = node[len(node)-1]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return t.DeletePath(keys)
|
||||||
|
}
|
||||||
|
|
||||||
var toInsert interface{}
|
// DeletePath removes a key from the tree.
|
||||||
|
// Keys is an array of path elements (e.g. {"a","b","c"}).
|
||||||
switch value.(type) {
|
func (t *Tree) DeletePath(keys []string) error {
|
||||||
|
keyLen := len(keys)
|
||||||
|
if keyLen == 1 {
|
||||||
|
delete(t.values, keys[0])
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
tree := t.GetPath(keys[:keyLen-1])
|
||||||
|
item := keys[keyLen-1]
|
||||||
|
switch node := tree.(type) {
|
||||||
case *Tree:
|
case *Tree:
|
||||||
tt := value.(*Tree)
|
delete(node.values, item)
|
||||||
tt.comment = comment
|
return nil
|
||||||
toInsert = value
|
|
||||||
case []*Tree:
|
|
||||||
toInsert = value
|
|
||||||
case *tomlValue:
|
|
||||||
tt := value.(*tomlValue)
|
|
||||||
tt.comment = comment
|
|
||||||
toInsert = tt
|
|
||||||
default:
|
|
||||||
toInsert = &tomlValue{value: value, comment: comment, commented: commented}
|
|
||||||
}
|
}
|
||||||
|
return errors.New("no such key to delete")
|
||||||
subtree.values[keys[len(keys)-1]] = toInsert
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// createSubTree takes a tree and a key and create the necessary intermediate
|
// createSubTree takes a tree and a key and create the necessary intermediate
|
||||||
@ -305,10 +302,10 @@ func (t *Tree) SetPathWithComment(keys []string, comment string, commented bool,
|
|||||||
// Returns nil on success, error object on failure
|
// Returns nil on success, error object on failure
|
||||||
func (t *Tree) createSubTree(keys []string, pos Position) error {
|
func (t *Tree) createSubTree(keys []string, pos Position) error {
|
||||||
subtree := t
|
subtree := t
|
||||||
for _, intermediateKey := range keys {
|
for i, intermediateKey := range keys {
|
||||||
nextTree, exists := subtree.values[intermediateKey]
|
nextTree, exists := subtree.values[intermediateKey]
|
||||||
if !exists {
|
if !exists {
|
||||||
tree := newTree()
|
tree := newTreeWithPosition(Position{Line: t.position.Line + i, Col: t.position.Col})
|
||||||
tree.position = pos
|
tree.position = pos
|
||||||
subtree.values[intermediateKey] = tree
|
subtree.values[intermediateKey] = tree
|
||||||
nextTree = tree
|
nextTree = tree
|
||||||
@ -337,10 +334,39 @@ func LoadBytes(b []byte) (tree *Tree, err error) {
|
|||||||
err = errors.New(r.(string))
|
err = errors.New(r.(string))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if len(b) >= 4 && (hasUTF32BigEndianBOM4(b) || hasUTF32LittleEndianBOM4(b)) {
|
||||||
|
b = b[4:]
|
||||||
|
} else if len(b) >= 3 && hasUTF8BOM3(b) {
|
||||||
|
b = b[3:]
|
||||||
|
} else if len(b) >= 2 && (hasUTF16BigEndianBOM2(b) || hasUTF16LittleEndianBOM2(b)) {
|
||||||
|
b = b[2:]
|
||||||
|
}
|
||||||
|
|
||||||
tree = parseToml(lexToml(b))
|
tree = parseToml(lexToml(b))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasUTF16BigEndianBOM2(b []byte) bool {
|
||||||
|
return b[0] == 0xFE && b[1] == 0xFF
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasUTF16LittleEndianBOM2(b []byte) bool {
|
||||||
|
return b[0] == 0xFF && b[1] == 0xFE
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasUTF8BOM3(b []byte) bool {
|
||||||
|
return b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasUTF32BigEndianBOM4(b []byte) bool {
|
||||||
|
return b[0] == 0x00 && b[1] == 0x00 && b[2] == 0xFE && b[3] == 0xFF
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasUTF32LittleEndianBOM4(b []byte) bool {
|
||||||
|
return b[0] == 0xFF && b[1] == 0xFE && b[2] == 0x00 && b[3] == 0x00
|
||||||
|
}
|
||||||
|
|
||||||
// LoadReader creates a Tree from any io.Reader.
|
// LoadReader creates a Tree from any io.Reader.
|
||||||
func LoadReader(reader io.Reader) (tree *Tree, err error) {
|
func LoadReader(reader io.Reader) (tree *Tree, err error) {
|
||||||
inputBytes, err := ioutil.ReadAll(reader)
|
inputBytes, err := ioutil.ReadAll(reader)
|
||||||
|
310
vendor/github.com/pelletier/go-toml/tomltree_write.go
generated
vendored
310
vendor/github.com/pelletier/go-toml/tomltree_write.go
generated
vendored
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -12,6 +13,18 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type valueComplexity int
|
||||||
|
|
||||||
|
const (
|
||||||
|
valueSimple valueComplexity = iota + 1
|
||||||
|
valueComplex
|
||||||
|
)
|
||||||
|
|
||||||
|
type sortNode struct {
|
||||||
|
key string
|
||||||
|
complexity valueComplexity
|
||||||
|
}
|
||||||
|
|
||||||
// Encodes a string to a TOML-compliant multi-line string value
|
// Encodes a string to a TOML-compliant multi-line string value
|
||||||
// This function is a clone of the existing encodeTomlString function, except that whitespace characters
|
// This function is a clone of the existing encodeTomlString function, except that whitespace characters
|
||||||
// are preserved. Quotation marks and backslashes are also not escaped.
|
// are preserved. Quotation marks and backslashes are also not escaped.
|
||||||
@ -94,12 +107,20 @@ func tomlValueStringRepresentation(v interface{}, indent string, arraysOneElemen
|
|||||||
case int64:
|
case int64:
|
||||||
return strconv.FormatInt(value, 10), nil
|
return strconv.FormatInt(value, 10), nil
|
||||||
case float64:
|
case float64:
|
||||||
// Ensure a round float does contain a decimal point. Otherwise feeding
|
// Default bit length is full 64
|
||||||
// the output back to the parser would convert to an integer.
|
bits := 64
|
||||||
if math.Trunc(value) == value {
|
// Float panics if nan is used
|
||||||
return strings.ToLower(strconv.FormatFloat(value, 'f', 1, 32)), nil
|
if !math.IsNaN(value) {
|
||||||
|
// if 32 bit accuracy is enough to exactly show, use 32
|
||||||
|
_, acc := big.NewFloat(value).Float32()
|
||||||
|
if acc == big.Exact {
|
||||||
|
bits = 32
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return strings.ToLower(strconv.FormatFloat(value, 'f', -1, 32)), nil
|
if math.Trunc(value) == value {
|
||||||
|
return strings.ToLower(strconv.FormatFloat(value, 'f', 1, bits)), nil
|
||||||
|
}
|
||||||
|
return strings.ToLower(strconv.FormatFloat(value, 'f', -1, bits)), nil
|
||||||
case string:
|
case string:
|
||||||
if tv.multiline {
|
if tv.multiline {
|
||||||
return "\"\"\"\n" + encodeMultilineTomlString(value) + "\"\"\"", nil
|
return "\"\"\"\n" + encodeMultilineTomlString(value) + "\"\"\"", nil
|
||||||
@ -115,6 +136,12 @@ func tomlValueStringRepresentation(v interface{}, indent string, arraysOneElemen
|
|||||||
return "false", nil
|
return "false", nil
|
||||||
case time.Time:
|
case time.Time:
|
||||||
return value.Format(time.RFC3339), nil
|
return value.Format(time.RFC3339), nil
|
||||||
|
case LocalDate:
|
||||||
|
return value.String(), nil
|
||||||
|
case LocalDateTime:
|
||||||
|
return value.String(), nil
|
||||||
|
case LocalTime:
|
||||||
|
return value.String(), nil
|
||||||
case nil:
|
case nil:
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
@ -153,117 +180,233 @@ func tomlValueStringRepresentation(v interface{}, indent string, arraysOneElemen
|
|||||||
return "", fmt.Errorf("unsupported value type %T: %v", v, v)
|
return "", fmt.Errorf("unsupported value type %T: %v", v, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tree) writeTo(w io.Writer, indent, keyspace string, bytesCount int64, arraysOneElementPerLine bool) (int64, error) {
|
func getTreeArrayLine(trees []*Tree) (line int) {
|
||||||
simpleValuesKeys := make([]string, 0)
|
// get lowest line number that is not 0
|
||||||
complexValuesKeys := make([]string, 0)
|
for _, tv := range trees {
|
||||||
|
if tv.position.Line < line || line == 0 {
|
||||||
|
line = tv.position.Line
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func sortByLines(t *Tree) (vals []sortNode) {
|
||||||
|
var (
|
||||||
|
line int
|
||||||
|
lines []int
|
||||||
|
tv *Tree
|
||||||
|
tom *tomlValue
|
||||||
|
node sortNode
|
||||||
|
)
|
||||||
|
vals = make([]sortNode, 0)
|
||||||
|
m := make(map[int]sortNode)
|
||||||
|
|
||||||
|
for k := range t.values {
|
||||||
|
v := t.values[k]
|
||||||
|
switch v.(type) {
|
||||||
|
case *Tree:
|
||||||
|
tv = v.(*Tree)
|
||||||
|
line = tv.position.Line
|
||||||
|
node = sortNode{key: k, complexity: valueComplex}
|
||||||
|
case []*Tree:
|
||||||
|
line = getTreeArrayLine(v.([]*Tree))
|
||||||
|
node = sortNode{key: k, complexity: valueComplex}
|
||||||
|
default:
|
||||||
|
tom = v.(*tomlValue)
|
||||||
|
line = tom.position.Line
|
||||||
|
node = sortNode{key: k, complexity: valueSimple}
|
||||||
|
}
|
||||||
|
lines = append(lines, line)
|
||||||
|
vals = append(vals, node)
|
||||||
|
m[line] = node
|
||||||
|
}
|
||||||
|
sort.Ints(lines)
|
||||||
|
|
||||||
|
for i, line := range lines {
|
||||||
|
vals[i] = m[line]
|
||||||
|
}
|
||||||
|
|
||||||
|
return vals
|
||||||
|
}
|
||||||
|
|
||||||
|
func sortAlphabetical(t *Tree) (vals []sortNode) {
|
||||||
|
var (
|
||||||
|
node sortNode
|
||||||
|
simpVals []string
|
||||||
|
compVals []string
|
||||||
|
)
|
||||||
|
vals = make([]sortNode, 0)
|
||||||
|
m := make(map[string]sortNode)
|
||||||
|
|
||||||
for k := range t.values {
|
for k := range t.values {
|
||||||
v := t.values[k]
|
v := t.values[k]
|
||||||
switch v.(type) {
|
switch v.(type) {
|
||||||
case *Tree, []*Tree:
|
case *Tree, []*Tree:
|
||||||
complexValuesKeys = append(complexValuesKeys, k)
|
node = sortNode{key: k, complexity: valueComplex}
|
||||||
|
compVals = append(compVals, node.key)
|
||||||
default:
|
default:
|
||||||
simpleValuesKeys = append(simpleValuesKeys, k)
|
node = sortNode{key: k, complexity: valueSimple}
|
||||||
|
simpVals = append(simpVals, node.key)
|
||||||
}
|
}
|
||||||
|
vals = append(vals, node)
|
||||||
|
m[node.key] = node
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Strings(simpleValuesKeys)
|
// Simples first to match previous implementation
|
||||||
sort.Strings(complexValuesKeys)
|
sort.Strings(simpVals)
|
||||||
|
i := 0
|
||||||
for _, k := range simpleValuesKeys {
|
for _, key := range simpVals {
|
||||||
v, ok := t.values[k].(*tomlValue)
|
vals[i] = m[key]
|
||||||
if !ok {
|
i++
|
||||||
return bytesCount, fmt.Errorf("invalid value type at %s: %T", k, t.values[k])
|
|
||||||
}
|
|
||||||
|
|
||||||
repr, err := tomlValueStringRepresentation(v, indent, arraysOneElementPerLine)
|
|
||||||
if err != nil {
|
|
||||||
return bytesCount, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if v.comment != "" {
|
|
||||||
comment := strings.Replace(v.comment, "\n", "\n"+indent+"#", -1)
|
|
||||||
start := "# "
|
|
||||||
if strings.HasPrefix(comment, "#") {
|
|
||||||
start = ""
|
|
||||||
}
|
|
||||||
writtenBytesCountComment, errc := writeStrings(w, "\n", indent, start, comment, "\n")
|
|
||||||
bytesCount += int64(writtenBytesCountComment)
|
|
||||||
if errc != nil {
|
|
||||||
return bytesCount, errc
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var commented string
|
|
||||||
if v.commented {
|
|
||||||
commented = "# "
|
|
||||||
}
|
|
||||||
writtenBytesCount, err := writeStrings(w, indent, commented, k, " = ", repr, "\n")
|
|
||||||
bytesCount += int64(writtenBytesCount)
|
|
||||||
if err != nil {
|
|
||||||
return bytesCount, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, k := range complexValuesKeys {
|
sort.Strings(compVals)
|
||||||
v := t.values[k]
|
for _, key := range compVals {
|
||||||
|
vals[i] = m[key]
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
combinedKey := k
|
return vals
|
||||||
if keyspace != "" {
|
}
|
||||||
combinedKey = keyspace + "." + combinedKey
|
|
||||||
}
|
|
||||||
var commented string
|
|
||||||
if t.commented {
|
|
||||||
commented = "# "
|
|
||||||
}
|
|
||||||
|
|
||||||
switch node := v.(type) {
|
func (t *Tree) writeTo(w io.Writer, indent, keyspace string, bytesCount int64, arraysOneElementPerLine bool) (int64, error) {
|
||||||
// node has to be of those two types given how keys are sorted above
|
return t.writeToOrdered(w, indent, keyspace, bytesCount, arraysOneElementPerLine, OrderAlphabetical)
|
||||||
case *Tree:
|
}
|
||||||
tv, ok := t.values[k].(*Tree)
|
|
||||||
|
func (t *Tree) writeToOrdered(w io.Writer, indent, keyspace string, bytesCount int64, arraysOneElementPerLine bool, ord marshalOrder) (int64, error) {
|
||||||
|
var orderedVals []sortNode
|
||||||
|
|
||||||
|
switch ord {
|
||||||
|
case OrderPreserve:
|
||||||
|
orderedVals = sortByLines(t)
|
||||||
|
default:
|
||||||
|
orderedVals = sortAlphabetical(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, node := range orderedVals {
|
||||||
|
switch node.complexity {
|
||||||
|
case valueComplex:
|
||||||
|
k := node.key
|
||||||
|
v := t.values[k]
|
||||||
|
|
||||||
|
combinedKey := k
|
||||||
|
if keyspace != "" {
|
||||||
|
combinedKey = keyspace + "." + combinedKey
|
||||||
|
}
|
||||||
|
var commented string
|
||||||
|
if t.commented {
|
||||||
|
commented = "# "
|
||||||
|
}
|
||||||
|
|
||||||
|
switch node := v.(type) {
|
||||||
|
// node has to be of those two types given how keys are sorted above
|
||||||
|
case *Tree:
|
||||||
|
tv, ok := t.values[k].(*Tree)
|
||||||
|
if !ok {
|
||||||
|
return bytesCount, fmt.Errorf("invalid value type at %s: %T", k, t.values[k])
|
||||||
|
}
|
||||||
|
if tv.comment != "" {
|
||||||
|
comment := strings.Replace(tv.comment, "\n", "\n"+indent+"#", -1)
|
||||||
|
start := "# "
|
||||||
|
if strings.HasPrefix(comment, "#") {
|
||||||
|
start = ""
|
||||||
|
}
|
||||||
|
writtenBytesCountComment, errc := writeStrings(w, "\n", indent, start, comment)
|
||||||
|
bytesCount += int64(writtenBytesCountComment)
|
||||||
|
if errc != nil {
|
||||||
|
return bytesCount, errc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writtenBytesCount, err := writeStrings(w, "\n", indent, commented, "[", combinedKey, "]\n")
|
||||||
|
bytesCount += int64(writtenBytesCount)
|
||||||
|
if err != nil {
|
||||||
|
return bytesCount, err
|
||||||
|
}
|
||||||
|
bytesCount, err = node.writeToOrdered(w, indent+" ", combinedKey, bytesCount, arraysOneElementPerLine, ord)
|
||||||
|
if err != nil {
|
||||||
|
return bytesCount, err
|
||||||
|
}
|
||||||
|
case []*Tree:
|
||||||
|
for _, subTree := range node {
|
||||||
|
writtenBytesCount, err := writeStrings(w, "\n", indent, commented, "[[", combinedKey, "]]\n")
|
||||||
|
bytesCount += int64(writtenBytesCount)
|
||||||
|
if err != nil {
|
||||||
|
return bytesCount, err
|
||||||
|
}
|
||||||
|
|
||||||
|
bytesCount, err = subTree.writeToOrdered(w, indent+" ", combinedKey, bytesCount, arraysOneElementPerLine, ord)
|
||||||
|
if err != nil {
|
||||||
|
return bytesCount, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: // Simple
|
||||||
|
k := node.key
|
||||||
|
v, ok := t.values[k].(*tomlValue)
|
||||||
if !ok {
|
if !ok {
|
||||||
return bytesCount, fmt.Errorf("invalid value type at %s: %T", k, t.values[k])
|
return bytesCount, fmt.Errorf("invalid value type at %s: %T", k, t.values[k])
|
||||||
}
|
}
|
||||||
if tv.comment != "" {
|
|
||||||
comment := strings.Replace(tv.comment, "\n", "\n"+indent+"#", -1)
|
repr, err := tomlValueStringRepresentation(v, indent, arraysOneElementPerLine)
|
||||||
|
if err != nil {
|
||||||
|
return bytesCount, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.comment != "" {
|
||||||
|
comment := strings.Replace(v.comment, "\n", "\n"+indent+"#", -1)
|
||||||
start := "# "
|
start := "# "
|
||||||
if strings.HasPrefix(comment, "#") {
|
if strings.HasPrefix(comment, "#") {
|
||||||
start = ""
|
start = ""
|
||||||
}
|
}
|
||||||
writtenBytesCountComment, errc := writeStrings(w, "\n", indent, start, comment)
|
writtenBytesCountComment, errc := writeStrings(w, "\n", indent, start, comment, "\n")
|
||||||
bytesCount += int64(writtenBytesCountComment)
|
bytesCount += int64(writtenBytesCountComment)
|
||||||
if errc != nil {
|
if errc != nil {
|
||||||
return bytesCount, errc
|
return bytesCount, errc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writtenBytesCount, err := writeStrings(w, "\n", indent, commented, "[", combinedKey, "]\n")
|
|
||||||
|
var commented string
|
||||||
|
if v.commented {
|
||||||
|
commented = "# "
|
||||||
|
}
|
||||||
|
quotedKey := quoteKeyIfNeeded(k)
|
||||||
|
writtenBytesCount, err := writeStrings(w, indent, commented, quotedKey, " = ", repr, "\n")
|
||||||
bytesCount += int64(writtenBytesCount)
|
bytesCount += int64(writtenBytesCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bytesCount, err
|
return bytesCount, err
|
||||||
}
|
}
|
||||||
bytesCount, err = node.writeTo(w, indent+" ", combinedKey, bytesCount, arraysOneElementPerLine)
|
|
||||||
if err != nil {
|
|
||||||
return bytesCount, err
|
|
||||||
}
|
|
||||||
case []*Tree:
|
|
||||||
for _, subTree := range node {
|
|
||||||
writtenBytesCount, err := writeStrings(w, "\n", indent, commented, "[[", combinedKey, "]]\n")
|
|
||||||
bytesCount += int64(writtenBytesCount)
|
|
||||||
if err != nil {
|
|
||||||
return bytesCount, err
|
|
||||||
}
|
|
||||||
|
|
||||||
bytesCount, err = subTree.writeTo(w, indent+" ", combinedKey, bytesCount, arraysOneElementPerLine)
|
|
||||||
if err != nil {
|
|
||||||
return bytesCount, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytesCount, nil
|
return bytesCount, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// quote a key if it does not fit the bare key format (A-Za-z0-9_-)
|
||||||
|
// quoted keys use the same rules as strings
|
||||||
|
func quoteKeyIfNeeded(k string) string {
|
||||||
|
// when encoding a map with the 'quoteMapKeys' option enabled, the tree will contain
|
||||||
|
// keys that have already been quoted.
|
||||||
|
// not an ideal situation, but good enough of a stop gap.
|
||||||
|
if len(k) >= 2 && k[0] == '"' && k[len(k)-1] == '"' {
|
||||||
|
return k
|
||||||
|
}
|
||||||
|
isBare := true
|
||||||
|
for _, r := range k {
|
||||||
|
if !isValidBareChar(r) {
|
||||||
|
isBare = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if isBare {
|
||||||
|
return k
|
||||||
|
}
|
||||||
|
return quoteKey(k)
|
||||||
|
}
|
||||||
|
|
||||||
|
func quoteKey(k string) string {
|
||||||
|
return "\"" + encodeTomlString(k) + "\""
|
||||||
|
}
|
||||||
|
|
||||||
func writeStrings(w io.Writer, s ...string) (int, error) {
|
func writeStrings(w io.Writer, s ...string) (int, error) {
|
||||||
var n int
|
var n int
|
||||||
for i := range s {
|
for i := range s {
|
||||||
@ -286,12 +429,11 @@ func (t *Tree) WriteTo(w io.Writer) (int64, error) {
|
|||||||
// Output spans multiple lines, and is suitable for ingest by a TOML parser.
|
// Output spans multiple lines, and is suitable for ingest by a TOML parser.
|
||||||
// If the conversion cannot be performed, ToString returns a non-nil error.
|
// If the conversion cannot be performed, ToString returns a non-nil error.
|
||||||
func (t *Tree) ToTomlString() (string, error) {
|
func (t *Tree) ToTomlString() (string, error) {
|
||||||
var buf bytes.Buffer
|
b, err := t.Marshal()
|
||||||
_, err := t.WriteTo(&buf)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return buf.String(), nil
|
return string(b), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// String generates a human-readable representation of the current tree.
|
// String generates a human-readable representation of the current tree.
|
||||||
|
5
vendor/github.com/spf13/afero/copyOnWriteFs.go
generated
vendored
5
vendor/github.com/spf13/afero/copyOnWriteFs.go
generated
vendored
@ -267,7 +267,7 @@ func (u *CopyOnWriteFs) Mkdir(name string, perm os.FileMode) error {
|
|||||||
return u.layer.MkdirAll(name, perm)
|
return u.layer.MkdirAll(name, perm)
|
||||||
}
|
}
|
||||||
if dir {
|
if dir {
|
||||||
return syscall.EEXIST
|
return ErrFileExists
|
||||||
}
|
}
|
||||||
return u.layer.MkdirAll(name, perm)
|
return u.layer.MkdirAll(name, perm)
|
||||||
}
|
}
|
||||||
@ -282,7 +282,8 @@ func (u *CopyOnWriteFs) MkdirAll(name string, perm os.FileMode) error {
|
|||||||
return u.layer.MkdirAll(name, perm)
|
return u.layer.MkdirAll(name, perm)
|
||||||
}
|
}
|
||||||
if dir {
|
if dir {
|
||||||
return syscall.EEXIST
|
// This is in line with how os.MkdirAll behaves.
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return u.layer.MkdirAll(name, perm)
|
return u.layer.MkdirAll(name, perm)
|
||||||
}
|
}
|
||||||
|
2
vendor/github.com/spf13/afero/go.mod
generated
vendored
2
vendor/github.com/spf13/afero/go.mod
generated
vendored
@ -1 +1,3 @@
|
|||||||
module github.com/spf13/afero
|
module github.com/spf13/afero
|
||||||
|
|
||||||
|
require golang.org/x/text v0.3.0
|
||||||
|
2
vendor/github.com/spf13/afero/go.sum
generated
vendored
Normal file
2
vendor/github.com/spf13/afero/go.sum
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
19
vendor/github.com/spf13/afero/unionFile.go
generated
vendored
19
vendor/github.com/spf13/afero/unionFile.go
generated
vendored
@ -155,7 +155,8 @@ var defaultUnionMergeDirsFn = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Readdir will weave the two directories together and
|
// Readdir will weave the two directories together and
|
||||||
// return a single view of the overlayed directories
|
// return a single view of the overlayed directories.
|
||||||
|
// At the end of the directory view, the error is io.EOF if c > 0.
|
||||||
func (f *UnionFile) Readdir(c int) (ofi []os.FileInfo, err error) {
|
func (f *UnionFile) Readdir(c int) (ofi []os.FileInfo, err error) {
|
||||||
var merge DirsMerger = f.Merger
|
var merge DirsMerger = f.Merger
|
||||||
if merge == nil {
|
if merge == nil {
|
||||||
@ -185,9 +186,23 @@ func (f *UnionFile) Readdir(c int) (ofi []os.FileInfo, err error) {
|
|||||||
}
|
}
|
||||||
f.files = append(f.files, merged...)
|
f.files = append(f.files, merged...)
|
||||||
}
|
}
|
||||||
if c == -1 {
|
|
||||||
|
if c <= 0 && len(f.files) == 0 {
|
||||||
|
return f.files, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.off >= len(f.files) {
|
||||||
|
return nil, io.EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
if c <= 0 {
|
||||||
return f.files[f.off:], nil
|
return f.files[f.off:], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c > len(f.files) {
|
||||||
|
c = len(f.files)
|
||||||
|
}
|
||||||
|
|
||||||
defer func() { f.off += c }()
|
defer func() { f.off += c }()
|
||||||
return f.files[f.off:c], nil
|
return f.files[f.off:c], nil
|
||||||
}
|
}
|
||||||
|
2
vendor/github.com/spf13/jwalterweatherman/.gitignore
generated
vendored
2
vendor/github.com/spf13/jwalterweatherman/.gitignore
generated
vendored
@ -20,3 +20,5 @@ _cgo_export.*
|
|||||||
_testmain.go
|
_testmain.go
|
||||||
|
|
||||||
*.exe
|
*.exe
|
||||||
|
*.bench
|
||||||
|
go.sum
|
30
vendor/github.com/spf13/jwalterweatherman/default_notepad.go
generated
vendored
30
vendor/github.com/spf13/jwalterweatherman/default_notepad.go
generated
vendored
@ -64,6 +64,13 @@ func SetStdoutThreshold(threshold Threshold) {
|
|||||||
reloadDefaultNotepad()
|
reloadDefaultNotepad()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetStdoutOutput set the stdout output for the default notepad. Default is stdout.
|
||||||
|
func SetStdoutOutput(handle io.Writer) {
|
||||||
|
defaultNotepad.outHandle = handle
|
||||||
|
defaultNotepad.init()
|
||||||
|
reloadDefaultNotepad()
|
||||||
|
}
|
||||||
|
|
||||||
// SetPrefix set the prefix for the default logger. Empty by default.
|
// SetPrefix set the prefix for the default logger. Empty by default.
|
||||||
func SetPrefix(prefix string) {
|
func SetPrefix(prefix string) {
|
||||||
defaultNotepad.SetPrefix(prefix)
|
defaultNotepad.SetPrefix(prefix)
|
||||||
@ -76,6 +83,13 @@ func SetFlags(flags int) {
|
|||||||
reloadDefaultNotepad()
|
reloadDefaultNotepad()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetLogListeners configures the default logger with one or more log listeners.
|
||||||
|
func SetLogListeners(l ...LogListener) {
|
||||||
|
defaultNotepad.logListeners = l
|
||||||
|
defaultNotepad.init()
|
||||||
|
reloadDefaultNotepad()
|
||||||
|
}
|
||||||
|
|
||||||
// Level returns the current global log threshold.
|
// Level returns the current global log threshold.
|
||||||
func LogThreshold() Threshold {
|
func LogThreshold() Threshold {
|
||||||
return defaultNotepad.logThreshold
|
return defaultNotepad.logThreshold
|
||||||
@ -95,19 +109,3 @@ func GetLogThreshold() Threshold {
|
|||||||
func GetStdoutThreshold() Threshold {
|
func GetStdoutThreshold() Threshold {
|
||||||
return defaultNotepad.GetStdoutThreshold()
|
return defaultNotepad.GetStdoutThreshold()
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogCountForLevel returns the number of log invocations for a given threshold.
|
|
||||||
func LogCountForLevel(l Threshold) uint64 {
|
|
||||||
return defaultNotepad.LogCountForLevel(l)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LogCountForLevelsGreaterThanorEqualTo returns the number of log invocations
|
|
||||||
// greater than or equal to a given threshold.
|
|
||||||
func LogCountForLevelsGreaterThanorEqualTo(threshold Threshold) uint64 {
|
|
||||||
return defaultNotepad.LogCountForLevelsGreaterThanorEqualTo(threshold)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResetLogCounters resets the invocation counters for all levels.
|
|
||||||
func ResetLogCounters() {
|
|
||||||
defaultNotepad.ResetLogCounters()
|
|
||||||
}
|
|
||||||
|
6
vendor/github.com/spf13/jwalterweatherman/go.mod
generated
vendored
6
vendor/github.com/spf13/jwalterweatherman/go.mod
generated
vendored
@ -1 +1,7 @@
|
|||||||
module github.com/spf13/jwalterweatherman
|
module github.com/spf13/jwalterweatherman
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/stretchr/testify v1.2.2
|
||||||
|
)
|
||||||
|
51
vendor/github.com/spf13/jwalterweatherman/log_counter.go
generated
vendored
51
vendor/github.com/spf13/jwalterweatherman/log_counter.go
generated
vendored
@ -6,50 +6,41 @@
|
|||||||
package jwalterweatherman
|
package jwalterweatherman
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type logCounter struct {
|
// Counter is an io.Writer that increments a counter on Write.
|
||||||
counter uint64
|
type Counter struct {
|
||||||
|
count uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *logCounter) incr() {
|
func (c *Counter) incr() {
|
||||||
atomic.AddUint64(&c.counter, 1)
|
atomic.AddUint64(&c.count, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *logCounter) resetCounter() {
|
// Reset resets the counter.
|
||||||
atomic.StoreUint64(&c.counter, 0)
|
func (c *Counter) Reset() {
|
||||||
|
atomic.StoreUint64(&c.count, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *logCounter) getCount() uint64 {
|
// Count returns the current count.
|
||||||
return atomic.LoadUint64(&c.counter)
|
func (c *Counter) Count() uint64 {
|
||||||
|
return atomic.LoadUint64(&c.count)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *logCounter) Write(p []byte) (n int, err error) {
|
func (c *Counter) Write(p []byte) (n int, err error) {
|
||||||
c.incr()
|
c.incr()
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogCountForLevel returns the number of log invocations for a given threshold.
|
// LogCounter creates a LogListener that counts log statements >= the given threshold.
|
||||||
func (n *Notepad) LogCountForLevel(l Threshold) uint64 {
|
func LogCounter(counter *Counter, t1 Threshold) LogListener {
|
||||||
return n.logCounters[l].getCount()
|
return func(t2 Threshold) io.Writer {
|
||||||
}
|
if t2 < t1 {
|
||||||
|
// Not interested in this threshold.
|
||||||
// LogCountForLevelsGreaterThanorEqualTo returns the number of log invocations
|
return nil
|
||||||
// greater than or equal to a given threshold.
|
}
|
||||||
func (n *Notepad) LogCountForLevelsGreaterThanorEqualTo(threshold Threshold) uint64 {
|
return counter
|
||||||
var cnt uint64
|
|
||||||
|
|
||||||
for i := int(threshold); i < len(n.logCounters); i++ {
|
|
||||||
cnt += n.LogCountForLevel(Threshold(i))
|
|
||||||
}
|
|
||||||
|
|
||||||
return cnt
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResetLogCounters resets the invocation counters for all levels.
|
|
||||||
func (n *Notepad) ResetLogCounters() {
|
|
||||||
for _, np := range n.logCounters {
|
|
||||||
np.resetCounter()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
57
vendor/github.com/spf13/jwalterweatherman/notepad.go
generated
vendored
57
vendor/github.com/spf13/jwalterweatherman/notepad.go
generated
vendored
@ -8,6 +8,7 @@ package jwalterweatherman
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -58,13 +59,28 @@ type Notepad struct {
|
|||||||
prefix string
|
prefix string
|
||||||
flags int
|
flags int
|
||||||
|
|
||||||
// One per Threshold
|
logListeners []LogListener
|
||||||
logCounters [7]*logCounter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNotepad create a new notepad.
|
// A LogListener can ble supplied to a Notepad to listen on log writes for a given
|
||||||
func NewNotepad(outThreshold Threshold, logThreshold Threshold, outHandle, logHandle io.Writer, prefix string, flags int) *Notepad {
|
// threshold. This can be used to capture log events in unit tests and similar.
|
||||||
n := &Notepad{}
|
// Note that this function will be invoked once for each log threshold. If
|
||||||
|
// the given threshold is not of interest to you, return nil.
|
||||||
|
// Note that these listeners will receive log events for a given threshold, even
|
||||||
|
// if the current configuration says not to log it. That way you can count ERRORs even
|
||||||
|
// if you don't print them to the console.
|
||||||
|
type LogListener func(t Threshold) io.Writer
|
||||||
|
|
||||||
|
// NewNotepad creates a new Notepad.
|
||||||
|
func NewNotepad(
|
||||||
|
outThreshold Threshold,
|
||||||
|
logThreshold Threshold,
|
||||||
|
outHandle, logHandle io.Writer,
|
||||||
|
prefix string, flags int,
|
||||||
|
logListeners ...LogListener,
|
||||||
|
) *Notepad {
|
||||||
|
|
||||||
|
n := &Notepad{logListeners: logListeners}
|
||||||
|
|
||||||
n.loggers = [7]**log.Logger{&n.TRACE, &n.DEBUG, &n.INFO, &n.WARN, &n.ERROR, &n.CRITICAL, &n.FATAL}
|
n.loggers = [7]**log.Logger{&n.TRACE, &n.DEBUG, &n.INFO, &n.WARN, &n.ERROR, &n.CRITICAL, &n.FATAL}
|
||||||
n.outHandle = outHandle
|
n.outHandle = outHandle
|
||||||
@ -95,28 +111,43 @@ func (n *Notepad) init() {
|
|||||||
|
|
||||||
for t, logger := range n.loggers {
|
for t, logger := range n.loggers {
|
||||||
threshold := Threshold(t)
|
threshold := Threshold(t)
|
||||||
counter := &logCounter{}
|
|
||||||
n.logCounters[t] = counter
|
|
||||||
prefix := n.prefix + threshold.String() + " "
|
prefix := n.prefix + threshold.String() + " "
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case threshold >= n.logThreshold && threshold >= n.stdoutThreshold:
|
case threshold >= n.logThreshold && threshold >= n.stdoutThreshold:
|
||||||
*logger = log.New(io.MultiWriter(counter, logAndOut), prefix, n.flags)
|
*logger = log.New(n.createLogWriters(threshold, logAndOut), prefix, n.flags)
|
||||||
|
|
||||||
case threshold >= n.logThreshold:
|
case threshold >= n.logThreshold:
|
||||||
*logger = log.New(io.MultiWriter(counter, n.logHandle), prefix, n.flags)
|
*logger = log.New(n.createLogWriters(threshold, n.logHandle), prefix, n.flags)
|
||||||
|
|
||||||
case threshold >= n.stdoutThreshold:
|
case threshold >= n.stdoutThreshold:
|
||||||
*logger = log.New(io.MultiWriter(counter, n.outHandle), prefix, n.flags)
|
*logger = log.New(n.createLogWriters(threshold, n.outHandle), prefix, n.flags)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// counter doesn't care about prefix and flags, so don't use them
|
*logger = log.New(n.createLogWriters(threshold, ioutil.Discard), prefix, n.flags)
|
||||||
// for performance.
|
|
||||||
*logger = log.New(counter, "", 0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *Notepad) createLogWriters(t Threshold, handle io.Writer) io.Writer {
|
||||||
|
if len(n.logListeners) == 0 {
|
||||||
|
return handle
|
||||||
|
}
|
||||||
|
writers := []io.Writer{handle}
|
||||||
|
for _, l := range n.logListeners {
|
||||||
|
w := l(t)
|
||||||
|
if w != nil {
|
||||||
|
writers = append(writers, w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(writers) == 1 {
|
||||||
|
return handle
|
||||||
|
}
|
||||||
|
|
||||||
|
return io.MultiWriter(writers...)
|
||||||
|
}
|
||||||
|
|
||||||
// SetLogThreshold changes the threshold above which messages are written to the
|
// SetLogThreshold changes the threshold above which messages are written to the
|
||||||
// log file.
|
// log file.
|
||||||
func (n *Notepad) SetLogThreshold(threshold Threshold) {
|
func (n *Notepad) SetLogThreshold(threshold Threshold) {
|
||||||
|
4
vendor/github.com/spf13/pflag/README.md
generated
vendored
4
vendor/github.com/spf13/pflag/README.md
generated
vendored
@ -86,8 +86,8 @@ fmt.Println("ip has value ", *ip)
|
|||||||
fmt.Println("flagvar has value ", flagvar)
|
fmt.Println("flagvar has value ", flagvar)
|
||||||
```
|
```
|
||||||
|
|
||||||
There are helpers function to get values later if you have the FlagSet but
|
There are helper functions available to get the value stored in a Flag if you have a FlagSet but find
|
||||||
it was difficult to keep up with all of the flag pointers in your code.
|
it difficult to keep up with all of the pointers in your code.
|
||||||
If you have a pflag.FlagSet with a flag called 'flagname' of type int you
|
If you have a pflag.FlagSet with a flag called 'flagname' of type int you
|
||||||
can use GetInt() to get the int value. But notice that 'flagname' must exist
|
can use GetInt() to get the int value. But notice that 'flagname' must exist
|
||||||
and it must be an int. GetString("flagname") will fail.
|
and it must be an int. GetString("flagname") will fail.
|
||||||
|
38
vendor/github.com/spf13/pflag/bool_slice.go
generated
vendored
38
vendor/github.com/spf13/pflag/bool_slice.go
generated
vendored
@ -71,6 +71,44 @@ func (s *boolSliceValue) String() string {
|
|||||||
return "[" + out + "]"
|
return "[" + out + "]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *boolSliceValue) fromString(val string) (bool, error) {
|
||||||
|
return strconv.ParseBool(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *boolSliceValue) toString(val bool) string {
|
||||||
|
return strconv.FormatBool(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *boolSliceValue) Append(val string) error {
|
||||||
|
i, err := s.fromString(val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*s.value = append(*s.value, i)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *boolSliceValue) Replace(val []string) error {
|
||||||
|
out := make([]bool, len(val))
|
||||||
|
for i, d := range val {
|
||||||
|
var err error
|
||||||
|
out[i], err = s.fromString(d)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*s.value = out
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *boolSliceValue) GetSlice() []string {
|
||||||
|
out := make([]string, len(*s.value))
|
||||||
|
for i, d := range *s.value {
|
||||||
|
out[i] = s.toString(d)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
func boolSliceConv(val string) (interface{}, error) {
|
func boolSliceConv(val string) (interface{}, error) {
|
||||||
val = strings.Trim(val, "[]")
|
val = strings.Trim(val, "[]")
|
||||||
// Empty string would cause a slice with one (empty) entry
|
// Empty string would cause a slice with one (empty) entry
|
||||||
|
4
vendor/github.com/spf13/pflag/count.go
generated
vendored
4
vendor/github.com/spf13/pflag/count.go
generated
vendored
@ -46,7 +46,7 @@ func (f *FlagSet) GetCount(name string) (int, error) {
|
|||||||
|
|
||||||
// CountVar defines a count flag with specified name, default value, and usage string.
|
// CountVar defines a count flag with specified name, default value, and usage string.
|
||||||
// The argument p points to an int variable in which to store the value of the flag.
|
// The argument p points to an int variable in which to store the value of the flag.
|
||||||
// A count flag will add 1 to its value evey time it is found on the command line
|
// A count flag will add 1 to its value every time it is found on the command line
|
||||||
func (f *FlagSet) CountVar(p *int, name string, usage string) {
|
func (f *FlagSet) CountVar(p *int, name string, usage string) {
|
||||||
f.CountVarP(p, name, "", usage)
|
f.CountVarP(p, name, "", usage)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func CountVarP(p *int, name, shorthand string, usage string) {
|
|||||||
|
|
||||||
// Count defines a count flag with specified name, default value, and usage string.
|
// Count defines a count flag with specified name, default value, and usage string.
|
||||||
// The return value is the address of an int variable that stores the value of the flag.
|
// The return value is the address of an int variable that stores the value of the flag.
|
||||||
// A count flag will add 1 to its value evey time it is found on the command line
|
// A count flag will add 1 to its value every time it is found on the command line
|
||||||
func (f *FlagSet) Count(name string, usage string) *int {
|
func (f *FlagSet) Count(name string, usage string) *int {
|
||||||
p := new(int)
|
p := new(int)
|
||||||
f.CountVarP(p, name, "", usage)
|
f.CountVarP(p, name, "", usage)
|
||||||
|
38
vendor/github.com/spf13/pflag/duration_slice.go
generated
vendored
38
vendor/github.com/spf13/pflag/duration_slice.go
generated
vendored
@ -51,6 +51,44 @@ func (s *durationSliceValue) String() string {
|
|||||||
return "[" + strings.Join(out, ",") + "]"
|
return "[" + strings.Join(out, ",") + "]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *durationSliceValue) fromString(val string) (time.Duration, error) {
|
||||||
|
return time.ParseDuration(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *durationSliceValue) toString(val time.Duration) string {
|
||||||
|
return fmt.Sprintf("%s", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *durationSliceValue) Append(val string) error {
|
||||||
|
i, err := s.fromString(val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*s.value = append(*s.value, i)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *durationSliceValue) Replace(val []string) error {
|
||||||
|
out := make([]time.Duration, len(val))
|
||||||
|
for i, d := range val {
|
||||||
|
var err error
|
||||||
|
out[i], err = s.fromString(d)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*s.value = out
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *durationSliceValue) GetSlice() []string {
|
||||||
|
out := make([]string, len(*s.value))
|
||||||
|
for i, d := range *s.value {
|
||||||
|
out[i] = s.toString(d)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
func durationSliceConv(val string) (interface{}, error) {
|
func durationSliceConv(val string) (interface{}, error) {
|
||||||
val = strings.Trim(val, "[]")
|
val = strings.Trim(val, "[]")
|
||||||
// Empty string would cause a slice with one (empty) entry
|
// Empty string would cause a slice with one (empty) entry
|
||||||
|
16
vendor/github.com/spf13/pflag/flag.go
generated
vendored
16
vendor/github.com/spf13/pflag/flag.go
generated
vendored
@ -57,9 +57,9 @@ that give one-letter shorthands for flags. You can use these by appending
|
|||||||
var ip = flag.IntP("flagname", "f", 1234, "help message")
|
var ip = flag.IntP("flagname", "f", 1234, "help message")
|
||||||
var flagvar bool
|
var flagvar bool
|
||||||
func init() {
|
func init() {
|
||||||
flag.BoolVarP("boolname", "b", true, "help message")
|
flag.BoolVarP(&flagvar, "boolname", "b", true, "help message")
|
||||||
}
|
}
|
||||||
flag.VarP(&flagVar, "varname", "v", 1234, "help message")
|
flag.VarP(&flagval, "varname", "v", "help message")
|
||||||
Shorthand letters can be used with single dashes on the command line.
|
Shorthand letters can be used with single dashes on the command line.
|
||||||
Boolean shorthand flags can be combined with other shorthand flags.
|
Boolean shorthand flags can be combined with other shorthand flags.
|
||||||
|
|
||||||
@ -190,6 +190,18 @@ type Value interface {
|
|||||||
Type() string
|
Type() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SliceValue is a secondary interface to all flags which hold a list
|
||||||
|
// of values. This allows full control over the value of list flags,
|
||||||
|
// and avoids complicated marshalling and unmarshalling to csv.
|
||||||
|
type SliceValue interface {
|
||||||
|
// Append adds the specified value to the end of the flag value list.
|
||||||
|
Append(string) error
|
||||||
|
// Replace will fully overwrite any data currently in the flag value list.
|
||||||
|
Replace([]string) error
|
||||||
|
// GetSlice returns the flag value list as an array of strings.
|
||||||
|
GetSlice() []string
|
||||||
|
}
|
||||||
|
|
||||||
// sortFlags returns the flags as a slice in lexicographical sorted order.
|
// sortFlags returns the flags as a slice in lexicographical sorted order.
|
||||||
func sortFlags(flags map[NormalizedName]*Flag) []*Flag {
|
func sortFlags(flags map[NormalizedName]*Flag) []*Flag {
|
||||||
list := make(sort.StringSlice, len(flags))
|
list := make(sort.StringSlice, len(flags))
|
||||||
|
174
vendor/github.com/spf13/pflag/float32_slice.go
generated
vendored
Normal file
174
vendor/github.com/spf13/pflag/float32_slice.go
generated
vendored
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
package pflag
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// -- float32Slice Value
|
||||||
|
type float32SliceValue struct {
|
||||||
|
value *[]float32
|
||||||
|
changed bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func newFloat32SliceValue(val []float32, p *[]float32) *float32SliceValue {
|
||||||
|
isv := new(float32SliceValue)
|
||||||
|
isv.value = p
|
||||||
|
*isv.value = val
|
||||||
|
return isv
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float32SliceValue) Set(val string) error {
|
||||||
|
ss := strings.Split(val, ",")
|
||||||
|
out := make([]float32, len(ss))
|
||||||
|
for i, d := range ss {
|
||||||
|
var err error
|
||||||
|
var temp64 float64
|
||||||
|
temp64, err = strconv.ParseFloat(d, 32)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out[i] = float32(temp64)
|
||||||
|
|
||||||
|
}
|
||||||
|
if !s.changed {
|
||||||
|
*s.value = out
|
||||||
|
} else {
|
||||||
|
*s.value = append(*s.value, out...)
|
||||||
|
}
|
||||||
|
s.changed = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float32SliceValue) Type() string {
|
||||||
|
return "float32Slice"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float32SliceValue) String() string {
|
||||||
|
out := make([]string, len(*s.value))
|
||||||
|
for i, d := range *s.value {
|
||||||
|
out[i] = fmt.Sprintf("%f", d)
|
||||||
|
}
|
||||||
|
return "[" + strings.Join(out, ",") + "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float32SliceValue) fromString(val string) (float32, error) {
|
||||||
|
t64, err := strconv.ParseFloat(val, 32)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return float32(t64), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float32SliceValue) toString(val float32) string {
|
||||||
|
return fmt.Sprintf("%f", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float32SliceValue) Append(val string) error {
|
||||||
|
i, err := s.fromString(val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*s.value = append(*s.value, i)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float32SliceValue) Replace(val []string) error {
|
||||||
|
out := make([]float32, len(val))
|
||||||
|
for i, d := range val {
|
||||||
|
var err error
|
||||||
|
out[i], err = s.fromString(d)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*s.value = out
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float32SliceValue) GetSlice() []string {
|
||||||
|
out := make([]string, len(*s.value))
|
||||||
|
for i, d := range *s.value {
|
||||||
|
out[i] = s.toString(d)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func float32SliceConv(val string) (interface{}, error) {
|
||||||
|
val = strings.Trim(val, "[]")
|
||||||
|
// Empty string would cause a slice with one (empty) entry
|
||||||
|
if len(val) == 0 {
|
||||||
|
return []float32{}, nil
|
||||||
|
}
|
||||||
|
ss := strings.Split(val, ",")
|
||||||
|
out := make([]float32, len(ss))
|
||||||
|
for i, d := range ss {
|
||||||
|
var err error
|
||||||
|
var temp64 float64
|
||||||
|
temp64, err = strconv.ParseFloat(d, 32)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out[i] = float32(temp64)
|
||||||
|
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFloat32Slice return the []float32 value of a flag with the given name
|
||||||
|
func (f *FlagSet) GetFloat32Slice(name string) ([]float32, error) {
|
||||||
|
val, err := f.getFlagType(name, "float32Slice", float32SliceConv)
|
||||||
|
if err != nil {
|
||||||
|
return []float32{}, err
|
||||||
|
}
|
||||||
|
return val.([]float32), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float32SliceVar defines a float32Slice flag with specified name, default value, and usage string.
|
||||||
|
// The argument p points to a []float32 variable in which to store the value of the flag.
|
||||||
|
func (f *FlagSet) Float32SliceVar(p *[]float32, name string, value []float32, usage string) {
|
||||||
|
f.VarP(newFloat32SliceValue(value, p), name, "", usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func (f *FlagSet) Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string) {
|
||||||
|
f.VarP(newFloat32SliceValue(value, p), name, shorthand, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float32SliceVar defines a float32[] flag with specified name, default value, and usage string.
|
||||||
|
// The argument p points to a float32[] variable in which to store the value of the flag.
|
||||||
|
func Float32SliceVar(p *[]float32, name string, value []float32, usage string) {
|
||||||
|
CommandLine.VarP(newFloat32SliceValue(value, p), name, "", usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string) {
|
||||||
|
CommandLine.VarP(newFloat32SliceValue(value, p), name, shorthand, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float32Slice defines a []float32 flag with specified name, default value, and usage string.
|
||||||
|
// The return value is the address of a []float32 variable that stores the value of the flag.
|
||||||
|
func (f *FlagSet) Float32Slice(name string, value []float32, usage string) *[]float32 {
|
||||||
|
p := []float32{}
|
||||||
|
f.Float32SliceVarP(&p, name, "", value, usage)
|
||||||
|
return &p
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func (f *FlagSet) Float32SliceP(name, shorthand string, value []float32, usage string) *[]float32 {
|
||||||
|
p := []float32{}
|
||||||
|
f.Float32SliceVarP(&p, name, shorthand, value, usage)
|
||||||
|
return &p
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float32Slice defines a []float32 flag with specified name, default value, and usage string.
|
||||||
|
// The return value is the address of a []float32 variable that stores the value of the flag.
|
||||||
|
func Float32Slice(name string, value []float32, usage string) *[]float32 {
|
||||||
|
return CommandLine.Float32SliceP(name, "", value, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func Float32SliceP(name, shorthand string, value []float32, usage string) *[]float32 {
|
||||||
|
return CommandLine.Float32SliceP(name, shorthand, value, usage)
|
||||||
|
}
|
166
vendor/github.com/spf13/pflag/float64_slice.go
generated
vendored
Normal file
166
vendor/github.com/spf13/pflag/float64_slice.go
generated
vendored
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
package pflag
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// -- float64Slice Value
|
||||||
|
type float64SliceValue struct {
|
||||||
|
value *[]float64
|
||||||
|
changed bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func newFloat64SliceValue(val []float64, p *[]float64) *float64SliceValue {
|
||||||
|
isv := new(float64SliceValue)
|
||||||
|
isv.value = p
|
||||||
|
*isv.value = val
|
||||||
|
return isv
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float64SliceValue) Set(val string) error {
|
||||||
|
ss := strings.Split(val, ",")
|
||||||
|
out := make([]float64, len(ss))
|
||||||
|
for i, d := range ss {
|
||||||
|
var err error
|
||||||
|
out[i], err = strconv.ParseFloat(d, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if !s.changed {
|
||||||
|
*s.value = out
|
||||||
|
} else {
|
||||||
|
*s.value = append(*s.value, out...)
|
||||||
|
}
|
||||||
|
s.changed = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float64SliceValue) Type() string {
|
||||||
|
return "float64Slice"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float64SliceValue) String() string {
|
||||||
|
out := make([]string, len(*s.value))
|
||||||
|
for i, d := range *s.value {
|
||||||
|
out[i] = fmt.Sprintf("%f", d)
|
||||||
|
}
|
||||||
|
return "[" + strings.Join(out, ",") + "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float64SliceValue) fromString(val string) (float64, error) {
|
||||||
|
return strconv.ParseFloat(val, 64)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float64SliceValue) toString(val float64) string {
|
||||||
|
return fmt.Sprintf("%f", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float64SliceValue) Append(val string) error {
|
||||||
|
i, err := s.fromString(val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*s.value = append(*s.value, i)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float64SliceValue) Replace(val []string) error {
|
||||||
|
out := make([]float64, len(val))
|
||||||
|
for i, d := range val {
|
||||||
|
var err error
|
||||||
|
out[i], err = s.fromString(d)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*s.value = out
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *float64SliceValue) GetSlice() []string {
|
||||||
|
out := make([]string, len(*s.value))
|
||||||
|
for i, d := range *s.value {
|
||||||
|
out[i] = s.toString(d)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func float64SliceConv(val string) (interface{}, error) {
|
||||||
|
val = strings.Trim(val, "[]")
|
||||||
|
// Empty string would cause a slice with one (empty) entry
|
||||||
|
if len(val) == 0 {
|
||||||
|
return []float64{}, nil
|
||||||
|
}
|
||||||
|
ss := strings.Split(val, ",")
|
||||||
|
out := make([]float64, len(ss))
|
||||||
|
for i, d := range ss {
|
||||||
|
var err error
|
||||||
|
out[i], err = strconv.ParseFloat(d, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFloat64Slice return the []float64 value of a flag with the given name
|
||||||
|
func (f *FlagSet) GetFloat64Slice(name string) ([]float64, error) {
|
||||||
|
val, err := f.getFlagType(name, "float64Slice", float64SliceConv)
|
||||||
|
if err != nil {
|
||||||
|
return []float64{}, err
|
||||||
|
}
|
||||||
|
return val.([]float64), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64SliceVar defines a float64Slice flag with specified name, default value, and usage string.
|
||||||
|
// The argument p points to a []float64 variable in which to store the value of the flag.
|
||||||
|
func (f *FlagSet) Float64SliceVar(p *[]float64, name string, value []float64, usage string) {
|
||||||
|
f.VarP(newFloat64SliceValue(value, p), name, "", usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func (f *FlagSet) Float64SliceVarP(p *[]float64, name, shorthand string, value []float64, usage string) {
|
||||||
|
f.VarP(newFloat64SliceValue(value, p), name, shorthand, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64SliceVar defines a float64[] flag with specified name, default value, and usage string.
|
||||||
|
// The argument p points to a float64[] variable in which to store the value of the flag.
|
||||||
|
func Float64SliceVar(p *[]float64, name string, value []float64, usage string) {
|
||||||
|
CommandLine.VarP(newFloat64SliceValue(value, p), name, "", usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func Float64SliceVarP(p *[]float64, name, shorthand string, value []float64, usage string) {
|
||||||
|
CommandLine.VarP(newFloat64SliceValue(value, p), name, shorthand, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64Slice defines a []float64 flag with specified name, default value, and usage string.
|
||||||
|
// The return value is the address of a []float64 variable that stores the value of the flag.
|
||||||
|
func (f *FlagSet) Float64Slice(name string, value []float64, usage string) *[]float64 {
|
||||||
|
p := []float64{}
|
||||||
|
f.Float64SliceVarP(&p, name, "", value, usage)
|
||||||
|
return &p
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func (f *FlagSet) Float64SliceP(name, shorthand string, value []float64, usage string) *[]float64 {
|
||||||
|
p := []float64{}
|
||||||
|
f.Float64SliceVarP(&p, name, shorthand, value, usage)
|
||||||
|
return &p
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64Slice defines a []float64 flag with specified name, default value, and usage string.
|
||||||
|
// The return value is the address of a []float64 variable that stores the value of the flag.
|
||||||
|
func Float64Slice(name string, value []float64, usage string) *[]float64 {
|
||||||
|
return CommandLine.Float64SliceP(name, "", value, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func Float64SliceP(name, shorthand string, value []float64, usage string) *[]float64 {
|
||||||
|
return CommandLine.Float64SliceP(name, shorthand, value, usage)
|
||||||
|
}
|
3
vendor/github.com/spf13/pflag/go.mod
generated
vendored
Normal file
3
vendor/github.com/spf13/pflag/go.mod
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module github.com/spf13/pflag
|
||||||
|
|
||||||
|
go 1.12
|
0
vendor/github.com/spf13/pflag/go.sum
generated
vendored
Normal file
0
vendor/github.com/spf13/pflag/go.sum
generated
vendored
Normal file
174
vendor/github.com/spf13/pflag/int32_slice.go
generated
vendored
Normal file
174
vendor/github.com/spf13/pflag/int32_slice.go
generated
vendored
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
package pflag
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// -- int32Slice Value
|
||||||
|
type int32SliceValue struct {
|
||||||
|
value *[]int32
|
||||||
|
changed bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func newInt32SliceValue(val []int32, p *[]int32) *int32SliceValue {
|
||||||
|
isv := new(int32SliceValue)
|
||||||
|
isv.value = p
|
||||||
|
*isv.value = val
|
||||||
|
return isv
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int32SliceValue) Set(val string) error {
|
||||||
|
ss := strings.Split(val, ",")
|
||||||
|
out := make([]int32, len(ss))
|
||||||
|
for i, d := range ss {
|
||||||
|
var err error
|
||||||
|
var temp64 int64
|
||||||
|
temp64, err = strconv.ParseInt(d, 0, 32)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out[i] = int32(temp64)
|
||||||
|
|
||||||
|
}
|
||||||
|
if !s.changed {
|
||||||
|
*s.value = out
|
||||||
|
} else {
|
||||||
|
*s.value = append(*s.value, out...)
|
||||||
|
}
|
||||||
|
s.changed = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int32SliceValue) Type() string {
|
||||||
|
return "int32Slice"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int32SliceValue) String() string {
|
||||||
|
out := make([]string, len(*s.value))
|
||||||
|
for i, d := range *s.value {
|
||||||
|
out[i] = fmt.Sprintf("%d", d)
|
||||||
|
}
|
||||||
|
return "[" + strings.Join(out, ",") + "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int32SliceValue) fromString(val string) (int32, error) {
|
||||||
|
t64, err := strconv.ParseInt(val, 0, 32)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return int32(t64), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int32SliceValue) toString(val int32) string {
|
||||||
|
return fmt.Sprintf("%d", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int32SliceValue) Append(val string) error {
|
||||||
|
i, err := s.fromString(val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*s.value = append(*s.value, i)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int32SliceValue) Replace(val []string) error {
|
||||||
|
out := make([]int32, len(val))
|
||||||
|
for i, d := range val {
|
||||||
|
var err error
|
||||||
|
out[i], err = s.fromString(d)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*s.value = out
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int32SliceValue) GetSlice() []string {
|
||||||
|
out := make([]string, len(*s.value))
|
||||||
|
for i, d := range *s.value {
|
||||||
|
out[i] = s.toString(d)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func int32SliceConv(val string) (interface{}, error) {
|
||||||
|
val = strings.Trim(val, "[]")
|
||||||
|
// Empty string would cause a slice with one (empty) entry
|
||||||
|
if len(val) == 0 {
|
||||||
|
return []int32{}, nil
|
||||||
|
}
|
||||||
|
ss := strings.Split(val, ",")
|
||||||
|
out := make([]int32, len(ss))
|
||||||
|
for i, d := range ss {
|
||||||
|
var err error
|
||||||
|
var temp64 int64
|
||||||
|
temp64, err = strconv.ParseInt(d, 0, 32)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out[i] = int32(temp64)
|
||||||
|
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetInt32Slice return the []int32 value of a flag with the given name
|
||||||
|
func (f *FlagSet) GetInt32Slice(name string) ([]int32, error) {
|
||||||
|
val, err := f.getFlagType(name, "int32Slice", int32SliceConv)
|
||||||
|
if err != nil {
|
||||||
|
return []int32{}, err
|
||||||
|
}
|
||||||
|
return val.([]int32), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int32SliceVar defines a int32Slice flag with specified name, default value, and usage string.
|
||||||
|
// The argument p points to a []int32 variable in which to store the value of the flag.
|
||||||
|
func (f *FlagSet) Int32SliceVar(p *[]int32, name string, value []int32, usage string) {
|
||||||
|
f.VarP(newInt32SliceValue(value, p), name, "", usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func (f *FlagSet) Int32SliceVarP(p *[]int32, name, shorthand string, value []int32, usage string) {
|
||||||
|
f.VarP(newInt32SliceValue(value, p), name, shorthand, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int32SliceVar defines a int32[] flag with specified name, default value, and usage string.
|
||||||
|
// The argument p points to a int32[] variable in which to store the value of the flag.
|
||||||
|
func Int32SliceVar(p *[]int32, name string, value []int32, usage string) {
|
||||||
|
CommandLine.VarP(newInt32SliceValue(value, p), name, "", usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func Int32SliceVarP(p *[]int32, name, shorthand string, value []int32, usage string) {
|
||||||
|
CommandLine.VarP(newInt32SliceValue(value, p), name, shorthand, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int32Slice defines a []int32 flag with specified name, default value, and usage string.
|
||||||
|
// The return value is the address of a []int32 variable that stores the value of the flag.
|
||||||
|
func (f *FlagSet) Int32Slice(name string, value []int32, usage string) *[]int32 {
|
||||||
|
p := []int32{}
|
||||||
|
f.Int32SliceVarP(&p, name, "", value, usage)
|
||||||
|
return &p
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func (f *FlagSet) Int32SliceP(name, shorthand string, value []int32, usage string) *[]int32 {
|
||||||
|
p := []int32{}
|
||||||
|
f.Int32SliceVarP(&p, name, shorthand, value, usage)
|
||||||
|
return &p
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int32Slice defines a []int32 flag with specified name, default value, and usage string.
|
||||||
|
// The return value is the address of a []int32 variable that stores the value of the flag.
|
||||||
|
func Int32Slice(name string, value []int32, usage string) *[]int32 {
|
||||||
|
return CommandLine.Int32SliceP(name, "", value, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func Int32SliceP(name, shorthand string, value []int32, usage string) *[]int32 {
|
||||||
|
return CommandLine.Int32SliceP(name, shorthand, value, usage)
|
||||||
|
}
|
166
vendor/github.com/spf13/pflag/int64_slice.go
generated
vendored
Normal file
166
vendor/github.com/spf13/pflag/int64_slice.go
generated
vendored
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
package pflag
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// -- int64Slice Value
|
||||||
|
type int64SliceValue struct {
|
||||||
|
value *[]int64
|
||||||
|
changed bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func newInt64SliceValue(val []int64, p *[]int64) *int64SliceValue {
|
||||||
|
isv := new(int64SliceValue)
|
||||||
|
isv.value = p
|
||||||
|
*isv.value = val
|
||||||
|
return isv
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int64SliceValue) Set(val string) error {
|
||||||
|
ss := strings.Split(val, ",")
|
||||||
|
out := make([]int64, len(ss))
|
||||||
|
for i, d := range ss {
|
||||||
|
var err error
|
||||||
|
out[i], err = strconv.ParseInt(d, 0, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if !s.changed {
|
||||||
|
*s.value = out
|
||||||
|
} else {
|
||||||
|
*s.value = append(*s.value, out...)
|
||||||
|
}
|
||||||
|
s.changed = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int64SliceValue) Type() string {
|
||||||
|
return "int64Slice"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int64SliceValue) String() string {
|
||||||
|
out := make([]string, len(*s.value))
|
||||||
|
for i, d := range *s.value {
|
||||||
|
out[i] = fmt.Sprintf("%d", d)
|
||||||
|
}
|
||||||
|
return "[" + strings.Join(out, ",") + "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int64SliceValue) fromString(val string) (int64, error) {
|
||||||
|
return strconv.ParseInt(val, 0, 64)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int64SliceValue) toString(val int64) string {
|
||||||
|
return fmt.Sprintf("%d", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int64SliceValue) Append(val string) error {
|
||||||
|
i, err := s.fromString(val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*s.value = append(*s.value, i)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int64SliceValue) Replace(val []string) error {
|
||||||
|
out := make([]int64, len(val))
|
||||||
|
for i, d := range val {
|
||||||
|
var err error
|
||||||
|
out[i], err = s.fromString(d)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*s.value = out
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *int64SliceValue) GetSlice() []string {
|
||||||
|
out := make([]string, len(*s.value))
|
||||||
|
for i, d := range *s.value {
|
||||||
|
out[i] = s.toString(d)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func int64SliceConv(val string) (interface{}, error) {
|
||||||
|
val = strings.Trim(val, "[]")
|
||||||
|
// Empty string would cause a slice with one (empty) entry
|
||||||
|
if len(val) == 0 {
|
||||||
|
return []int64{}, nil
|
||||||
|
}
|
||||||
|
ss := strings.Split(val, ",")
|
||||||
|
out := make([]int64, len(ss))
|
||||||
|
for i, d := range ss {
|
||||||
|
var err error
|
||||||
|
out[i], err = strconv.ParseInt(d, 0, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetInt64Slice return the []int64 value of a flag with the given name
|
||||||
|
func (f *FlagSet) GetInt64Slice(name string) ([]int64, error) {
|
||||||
|
val, err := f.getFlagType(name, "int64Slice", int64SliceConv)
|
||||||
|
if err != nil {
|
||||||
|
return []int64{}, err
|
||||||
|
}
|
||||||
|
return val.([]int64), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64SliceVar defines a int64Slice flag with specified name, default value, and usage string.
|
||||||
|
// The argument p points to a []int64 variable in which to store the value of the flag.
|
||||||
|
func (f *FlagSet) Int64SliceVar(p *[]int64, name string, value []int64, usage string) {
|
||||||
|
f.VarP(newInt64SliceValue(value, p), name, "", usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func (f *FlagSet) Int64SliceVarP(p *[]int64, name, shorthand string, value []int64, usage string) {
|
||||||
|
f.VarP(newInt64SliceValue(value, p), name, shorthand, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64SliceVar defines a int64[] flag with specified name, default value, and usage string.
|
||||||
|
// The argument p points to a int64[] variable in which to store the value of the flag.
|
||||||
|
func Int64SliceVar(p *[]int64, name string, value []int64, usage string) {
|
||||||
|
CommandLine.VarP(newInt64SliceValue(value, p), name, "", usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func Int64SliceVarP(p *[]int64, name, shorthand string, value []int64, usage string) {
|
||||||
|
CommandLine.VarP(newInt64SliceValue(value, p), name, shorthand, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64Slice defines a []int64 flag with specified name, default value, and usage string.
|
||||||
|
// The return value is the address of a []int64 variable that stores the value of the flag.
|
||||||
|
func (f *FlagSet) Int64Slice(name string, value []int64, usage string) *[]int64 {
|
||||||
|
p := []int64{}
|
||||||
|
f.Int64SliceVarP(&p, name, "", value, usage)
|
||||||
|
return &p
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func (f *FlagSet) Int64SliceP(name, shorthand string, value []int64, usage string) *[]int64 {
|
||||||
|
p := []int64{}
|
||||||
|
f.Int64SliceVarP(&p, name, shorthand, value, usage)
|
||||||
|
return &p
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64Slice defines a []int64 flag with specified name, default value, and usage string.
|
||||||
|
// The return value is the address of a []int64 variable that stores the value of the flag.
|
||||||
|
func Int64Slice(name string, value []int64, usage string) *[]int64 {
|
||||||
|
return CommandLine.Int64SliceP(name, "", value, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func Int64SliceP(name, shorthand string, value []int64, usage string) *[]int64 {
|
||||||
|
return CommandLine.Int64SliceP(name, shorthand, value, usage)
|
||||||
|
}
|
30
vendor/github.com/spf13/pflag/int_slice.go
generated
vendored
30
vendor/github.com/spf13/pflag/int_slice.go
generated
vendored
@ -51,6 +51,36 @@ func (s *intSliceValue) String() string {
|
|||||||
return "[" + strings.Join(out, ",") + "]"
|
return "[" + strings.Join(out, ",") + "]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *intSliceValue) Append(val string) error {
|
||||||
|
i, err := strconv.Atoi(val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*s.value = append(*s.value, i)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *intSliceValue) Replace(val []string) error {
|
||||||
|
out := make([]int, len(val))
|
||||||
|
for i, d := range val {
|
||||||
|
var err error
|
||||||
|
out[i], err = strconv.Atoi(d)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*s.value = out
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *intSliceValue) GetSlice() []string {
|
||||||
|
out := make([]string, len(*s.value))
|
||||||
|
for i, d := range *s.value {
|
||||||
|
out[i] = strconv.Itoa(d)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
func intSliceConv(val string) (interface{}, error) {
|
func intSliceConv(val string) (interface{}, error) {
|
||||||
val = strings.Trim(val, "[]")
|
val = strings.Trim(val, "[]")
|
||||||
// Empty string would cause a slice with one (empty) entry
|
// Empty string would cause a slice with one (empty) entry
|
||||||
|
40
vendor/github.com/spf13/pflag/ip_slice.go
generated
vendored
40
vendor/github.com/spf13/pflag/ip_slice.go
generated
vendored
@ -72,9 +72,47 @@ func (s *ipSliceValue) String() string {
|
|||||||
return "[" + out + "]"
|
return "[" + out + "]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ipSliceValue) fromString(val string) (net.IP, error) {
|
||||||
|
return net.ParseIP(strings.TrimSpace(val)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ipSliceValue) toString(val net.IP) string {
|
||||||
|
return val.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ipSliceValue) Append(val string) error {
|
||||||
|
i, err := s.fromString(val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*s.value = append(*s.value, i)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ipSliceValue) Replace(val []string) error {
|
||||||
|
out := make([]net.IP, len(val))
|
||||||
|
for i, d := range val {
|
||||||
|
var err error
|
||||||
|
out[i], err = s.fromString(d)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*s.value = out
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ipSliceValue) GetSlice() []string {
|
||||||
|
out := make([]string, len(*s.value))
|
||||||
|
for i, d := range *s.value {
|
||||||
|
out[i] = s.toString(d)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
func ipSliceConv(val string) (interface{}, error) {
|
func ipSliceConv(val string) (interface{}, error) {
|
||||||
val = strings.Trim(val, "[]")
|
val = strings.Trim(val, "[]")
|
||||||
// Emtpy string would cause a slice with one (empty) entry
|
// Empty string would cause a slice with one (empty) entry
|
||||||
if len(val) == 0 {
|
if len(val) == 0 {
|
||||||
return []net.IP{}, nil
|
return []net.IP{}, nil
|
||||||
}
|
}
|
||||||
|
26
vendor/github.com/spf13/pflag/string_array.go
generated
vendored
26
vendor/github.com/spf13/pflag/string_array.go
generated
vendored
@ -23,6 +23,32 @@ func (s *stringArrayValue) Set(val string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *stringArrayValue) Append(val string) error {
|
||||||
|
*s.value = append(*s.value, val)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stringArrayValue) Replace(val []string) error {
|
||||||
|
out := make([]string, len(val))
|
||||||
|
for i, d := range val {
|
||||||
|
var err error
|
||||||
|
out[i] = d
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*s.value = out
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stringArrayValue) GetSlice() []string {
|
||||||
|
out := make([]string, len(*s.value))
|
||||||
|
for i, d := range *s.value {
|
||||||
|
out[i] = d
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
func (s *stringArrayValue) Type() string {
|
func (s *stringArrayValue) Type() string {
|
||||||
return "stringArray"
|
return "stringArray"
|
||||||
}
|
}
|
||||||
|
22
vendor/github.com/spf13/pflag/string_slice.go
generated
vendored
22
vendor/github.com/spf13/pflag/string_slice.go
generated
vendored
@ -62,6 +62,20 @@ func (s *stringSliceValue) String() string {
|
|||||||
return "[" + str + "]"
|
return "[" + str + "]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *stringSliceValue) Append(val string) error {
|
||||||
|
*s.value = append(*s.value, val)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stringSliceValue) Replace(val []string) error {
|
||||||
|
*s.value = val
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stringSliceValue) GetSlice() []string {
|
||||||
|
return *s.value
|
||||||
|
}
|
||||||
|
|
||||||
func stringSliceConv(sval string) (interface{}, error) {
|
func stringSliceConv(sval string) (interface{}, error) {
|
||||||
sval = sval[1 : len(sval)-1]
|
sval = sval[1 : len(sval)-1]
|
||||||
// An empty string would cause a slice with one (empty) string
|
// An empty string would cause a slice with one (empty) string
|
||||||
@ -84,7 +98,7 @@ func (f *FlagSet) GetStringSlice(name string) ([]string, error) {
|
|||||||
// The argument p points to a []string variable in which to store the value of the flag.
|
// The argument p points to a []string variable in which to store the value of the flag.
|
||||||
// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
|
// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
|
||||||
// For example:
|
// For example:
|
||||||
// --ss="v1,v2" -ss="v3"
|
// --ss="v1,v2" --ss="v3"
|
||||||
// will result in
|
// will result in
|
||||||
// []string{"v1", "v2", "v3"}
|
// []string{"v1", "v2", "v3"}
|
||||||
func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage string) {
|
func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage string) {
|
||||||
@ -100,7 +114,7 @@ func (f *FlagSet) StringSliceVarP(p *[]string, name, shorthand string, value []s
|
|||||||
// The argument p points to a []string variable in which to store the value of the flag.
|
// The argument p points to a []string variable in which to store the value of the flag.
|
||||||
// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
|
// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
|
||||||
// For example:
|
// For example:
|
||||||
// --ss="v1,v2" -ss="v3"
|
// --ss="v1,v2" --ss="v3"
|
||||||
// will result in
|
// will result in
|
||||||
// []string{"v1", "v2", "v3"}
|
// []string{"v1", "v2", "v3"}
|
||||||
func StringSliceVar(p *[]string, name string, value []string, usage string) {
|
func StringSliceVar(p *[]string, name string, value []string, usage string) {
|
||||||
@ -116,7 +130,7 @@ func StringSliceVarP(p *[]string, name, shorthand string, value []string, usage
|
|||||||
// The return value is the address of a []string variable that stores the value of the flag.
|
// The return value is the address of a []string variable that stores the value of the flag.
|
||||||
// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
|
// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
|
||||||
// For example:
|
// For example:
|
||||||
// --ss="v1,v2" -ss="v3"
|
// --ss="v1,v2" --ss="v3"
|
||||||
// will result in
|
// will result in
|
||||||
// []string{"v1", "v2", "v3"}
|
// []string{"v1", "v2", "v3"}
|
||||||
func (f *FlagSet) StringSlice(name string, value []string, usage string) *[]string {
|
func (f *FlagSet) StringSlice(name string, value []string, usage string) *[]string {
|
||||||
@ -136,7 +150,7 @@ func (f *FlagSet) StringSliceP(name, shorthand string, value []string, usage str
|
|||||||
// The return value is the address of a []string variable that stores the value of the flag.
|
// The return value is the address of a []string variable that stores the value of the flag.
|
||||||
// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
|
// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.
|
||||||
// For example:
|
// For example:
|
||||||
// --ss="v1,v2" -ss="v3"
|
// --ss="v1,v2" --ss="v3"
|
||||||
// will result in
|
// will result in
|
||||||
// []string{"v1", "v2", "v3"}
|
// []string{"v1", "v2", "v3"}
|
||||||
func StringSlice(name string, value []string, usage string) *[]string {
|
func StringSlice(name string, value []string, usage string) *[]string {
|
||||||
|
149
vendor/github.com/spf13/pflag/string_to_int64.go
generated
vendored
Normal file
149
vendor/github.com/spf13/pflag/string_to_int64.go
generated
vendored
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
package pflag
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// -- stringToInt64 Value
|
||||||
|
type stringToInt64Value struct {
|
||||||
|
value *map[string]int64
|
||||||
|
changed bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func newStringToInt64Value(val map[string]int64, p *map[string]int64) *stringToInt64Value {
|
||||||
|
ssv := new(stringToInt64Value)
|
||||||
|
ssv.value = p
|
||||||
|
*ssv.value = val
|
||||||
|
return ssv
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format: a=1,b=2
|
||||||
|
func (s *stringToInt64Value) Set(val string) error {
|
||||||
|
ss := strings.Split(val, ",")
|
||||||
|
out := make(map[string]int64, len(ss))
|
||||||
|
for _, pair := range ss {
|
||||||
|
kv := strings.SplitN(pair, "=", 2)
|
||||||
|
if len(kv) != 2 {
|
||||||
|
return fmt.Errorf("%s must be formatted as key=value", pair)
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
out[kv[0]], err = strconv.ParseInt(kv[1], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !s.changed {
|
||||||
|
*s.value = out
|
||||||
|
} else {
|
||||||
|
for k, v := range out {
|
||||||
|
(*s.value)[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.changed = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stringToInt64Value) Type() string {
|
||||||
|
return "stringToInt64"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stringToInt64Value) String() string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
i := 0
|
||||||
|
for k, v := range *s.value {
|
||||||
|
if i > 0 {
|
||||||
|
buf.WriteRune(',')
|
||||||
|
}
|
||||||
|
buf.WriteString(k)
|
||||||
|
buf.WriteRune('=')
|
||||||
|
buf.WriteString(strconv.FormatInt(v, 10))
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "[" + buf.String() + "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
func stringToInt64Conv(val string) (interface{}, error) {
|
||||||
|
val = strings.Trim(val, "[]")
|
||||||
|
// An empty string would cause an empty map
|
||||||
|
if len(val) == 0 {
|
||||||
|
return map[string]int64{}, nil
|
||||||
|
}
|
||||||
|
ss := strings.Split(val, ",")
|
||||||
|
out := make(map[string]int64, len(ss))
|
||||||
|
for _, pair := range ss {
|
||||||
|
kv := strings.SplitN(pair, "=", 2)
|
||||||
|
if len(kv) != 2 {
|
||||||
|
return nil, fmt.Errorf("%s must be formatted as key=value", pair)
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
out[kv[0]], err = strconv.ParseInt(kv[1], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetStringToInt64 return the map[string]int64 value of a flag with the given name
|
||||||
|
func (f *FlagSet) GetStringToInt64(name string) (map[string]int64, error) {
|
||||||
|
val, err := f.getFlagType(name, "stringToInt64", stringToInt64Conv)
|
||||||
|
if err != nil {
|
||||||
|
return map[string]int64{}, err
|
||||||
|
}
|
||||||
|
return val.(map[string]int64), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringToInt64Var defines a string flag with specified name, default value, and usage string.
|
||||||
|
// The argument p point64s to a map[string]int64 variable in which to store the values of the multiple flags.
|
||||||
|
// The value of each argument will not try to be separated by comma
|
||||||
|
func (f *FlagSet) StringToInt64Var(p *map[string]int64, name string, value map[string]int64, usage string) {
|
||||||
|
f.VarP(newStringToInt64Value(value, p), name, "", usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringToInt64VarP is like StringToInt64Var, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func (f *FlagSet) StringToInt64VarP(p *map[string]int64, name, shorthand string, value map[string]int64, usage string) {
|
||||||
|
f.VarP(newStringToInt64Value(value, p), name, shorthand, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringToInt64Var defines a string flag with specified name, default value, and usage string.
|
||||||
|
// The argument p point64s to a map[string]int64 variable in which to store the value of the flag.
|
||||||
|
// The value of each argument will not try to be separated by comma
|
||||||
|
func StringToInt64Var(p *map[string]int64, name string, value map[string]int64, usage string) {
|
||||||
|
CommandLine.VarP(newStringToInt64Value(value, p), name, "", usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringToInt64VarP is like StringToInt64Var, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func StringToInt64VarP(p *map[string]int64, name, shorthand string, value map[string]int64, usage string) {
|
||||||
|
CommandLine.VarP(newStringToInt64Value(value, p), name, shorthand, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringToInt64 defines a string flag with specified name, default value, and usage string.
|
||||||
|
// The return value is the address of a map[string]int64 variable that stores the value of the flag.
|
||||||
|
// The value of each argument will not try to be separated by comma
|
||||||
|
func (f *FlagSet) StringToInt64(name string, value map[string]int64, usage string) *map[string]int64 {
|
||||||
|
p := map[string]int64{}
|
||||||
|
f.StringToInt64VarP(&p, name, "", value, usage)
|
||||||
|
return &p
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringToInt64P is like StringToInt64, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func (f *FlagSet) StringToInt64P(name, shorthand string, value map[string]int64, usage string) *map[string]int64 {
|
||||||
|
p := map[string]int64{}
|
||||||
|
f.StringToInt64VarP(&p, name, shorthand, value, usage)
|
||||||
|
return &p
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringToInt64 defines a string flag with specified name, default value, and usage string.
|
||||||
|
// The return value is the address of a map[string]int64 variable that stores the value of the flag.
|
||||||
|
// The value of each argument will not try to be separated by comma
|
||||||
|
func StringToInt64(name string, value map[string]int64, usage string) *map[string]int64 {
|
||||||
|
return CommandLine.StringToInt64P(name, "", value, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringToInt64P is like StringToInt64, but accepts a shorthand letter that can be used after a single dash.
|
||||||
|
func StringToInt64P(name, shorthand string, value map[string]int64, usage string) *map[string]int64 {
|
||||||
|
return CommandLine.StringToInt64P(name, shorthand, value, usage)
|
||||||
|
}
|
42
vendor/github.com/spf13/pflag/uint_slice.go
generated
vendored
42
vendor/github.com/spf13/pflag/uint_slice.go
generated
vendored
@ -50,6 +50,48 @@ func (s *uintSliceValue) String() string {
|
|||||||
return "[" + strings.Join(out, ",") + "]"
|
return "[" + strings.Join(out, ",") + "]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *uintSliceValue) fromString(val string) (uint, error) {
|
||||||
|
t, err := strconv.ParseUint(val, 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return uint(t), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *uintSliceValue) toString(val uint) string {
|
||||||
|
return fmt.Sprintf("%d", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *uintSliceValue) Append(val string) error {
|
||||||
|
i, err := s.fromString(val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*s.value = append(*s.value, i)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *uintSliceValue) Replace(val []string) error {
|
||||||
|
out := make([]uint, len(val))
|
||||||
|
for i, d := range val {
|
||||||
|
var err error
|
||||||
|
out[i], err = s.fromString(d)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*s.value = out
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *uintSliceValue) GetSlice() []string {
|
||||||
|
out := make([]string, len(*s.value))
|
||||||
|
for i, d := range *s.value {
|
||||||
|
out[i] = s.toString(d)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
func uintSliceConv(val string) (interface{}, error) {
|
func uintSliceConv(val string) (interface{}, error) {
|
||||||
val = strings.Trim(val, "[]")
|
val = strings.Trim(val, "[]")
|
||||||
// Empty string would cause a slice with one (empty) entry
|
// Empty string would cause a slice with one (empty) entry
|
||||||
|
47
vendor/github.com/spf13/viper/.gitignore
generated
vendored
47
vendor/github.com/spf13/viper/.gitignore
generated
vendored
@ -1,29 +1,20 @@
|
|||||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
/bin/
|
||||||
*.o
|
/build/
|
||||||
*.a
|
/var/
|
||||||
*.so
|
/vendor/
|
||||||
|
|
||||||
# Folders
|
# IDE integration
|
||||||
_obj
|
/.vscode/*
|
||||||
_test
|
!/.vscode/launch.json
|
||||||
|
!/.vscode/tasks.json
|
||||||
# Architecture specific extensions/prefixes
|
/.idea/*
|
||||||
*.[568vq]
|
!/.idea/codeStyles/
|
||||||
[568vq].out
|
!/.idea/copyright/
|
||||||
|
!/.idea/dataSources.xml
|
||||||
*.cgo1.go
|
!/.idea/*.iml
|
||||||
*.cgo2.c
|
!/.idea/externalDependencies.xml
|
||||||
_cgo_defun.c
|
!/.idea/go.imports.xml
|
||||||
_cgo_gotypes.go
|
!/.idea/modules.xml
|
||||||
_cgo_export.*
|
!/.idea/runConfigurations/
|
||||||
|
!/.idea/scopes/
|
||||||
_testmain.go
|
!/.idea/sqldialects.xml
|
||||||
|
|
||||||
*.exe
|
|
||||||
*.test
|
|
||||||
*.bench
|
|
||||||
|
|
||||||
.vscode
|
|
||||||
|
|
||||||
# exclude dependencies in the `/vendor` folder
|
|
||||||
vendor
|
|
||||||
|
71
vendor/github.com/spf13/viper/Makefile
generated
vendored
Normal file
71
vendor/github.com/spf13/viper/Makefile
generated
vendored
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
|
||||||
|
|
||||||
|
OS = $(shell uname | tr A-Z a-z)
|
||||||
|
|
||||||
|
# Build variables
|
||||||
|
BUILD_DIR ?= build
|
||||||
|
ifeq (${VERBOSE}, 1)
|
||||||
|
ifeq ($(filter -v,${GOARGS}),)
|
||||||
|
GOARGS += -v
|
||||||
|
endif
|
||||||
|
TEST_FORMAT = short-verbose
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Dependency versions
|
||||||
|
GOTESTSUM_VERSION = 0.3.5
|
||||||
|
GOLANGCI_VERSION = 1.21.0
|
||||||
|
|
||||||
|
# Add the ability to override some variables
|
||||||
|
# Use with care
|
||||||
|
-include override.mk
|
||||||
|
|
||||||
|
.PHONY: clear
|
||||||
|
clear: ## Clear the working area and the project
|
||||||
|
rm -rf bin/
|
||||||
|
|
||||||
|
.PHONY: check
|
||||||
|
check: test lint ## Run tests and linters
|
||||||
|
|
||||||
|
bin/gotestsum: bin/gotestsum-${GOTESTSUM_VERSION}
|
||||||
|
@ln -sf gotestsum-${GOTESTSUM_VERSION} bin/gotestsum
|
||||||
|
bin/gotestsum-${GOTESTSUM_VERSION}:
|
||||||
|
@mkdir -p bin
|
||||||
|
curl -L https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_${OS}_amd64.tar.gz | tar -zOxf - gotestsum > ./bin/gotestsum-${GOTESTSUM_VERSION} && chmod +x ./bin/gotestsum-${GOTESTSUM_VERSION}
|
||||||
|
|
||||||
|
TEST_PKGS ?= ./...
|
||||||
|
TEST_REPORT_NAME ?= results.xml
|
||||||
|
.PHONY: test
|
||||||
|
test: TEST_REPORT ?= main
|
||||||
|
test: TEST_FORMAT ?= short
|
||||||
|
test: SHELL = /bin/bash
|
||||||
|
test: bin/gotestsum ## Run tests
|
||||||
|
@mkdir -p ${BUILD_DIR}/test_results/${TEST_REPORT}
|
||||||
|
bin/gotestsum --no-summary=skipped --junitfile ${BUILD_DIR}/test_results/${TEST_REPORT}/${TEST_REPORT_NAME} --format ${TEST_FORMAT} -- $(filter-out -v,${GOARGS}) $(if ${TEST_PKGS},${TEST_PKGS},./...)
|
||||||
|
|
||||||
|
bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION}
|
||||||
|
@ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint
|
||||||
|
bin/golangci-lint-${GOLANGCI_VERSION}:
|
||||||
|
@mkdir -p bin
|
||||||
|
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | BINARY=golangci-lint bash -s -- v${GOLANGCI_VERSION}
|
||||||
|
@mv bin/golangci-lint $@
|
||||||
|
|
||||||
|
.PHONY: lint
|
||||||
|
lint: bin/golangci-lint ## Run linter
|
||||||
|
bin/golangci-lint run
|
||||||
|
|
||||||
|
.PHONY: fix
|
||||||
|
fix: bin/golangci-lint ## Fix lint violations
|
||||||
|
bin/golangci-lint run --fix
|
||||||
|
|
||||||
|
.PHONY: list
|
||||||
|
list: ## List all make targets
|
||||||
|
@${MAKE} -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
|
||||||
|
|
||||||
|
.PHONY: help
|
||||||
|
.DEFAULT_GOAL := help
|
||||||
|
help:
|
||||||
|
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
||||||
|
|
||||||
|
# Variable outputting/exporting rules
|
||||||
|
var-%: ; @echo $($*)
|
||||||
|
varexport-%: ; @echo $*=$($*)
|
79
vendor/github.com/spf13/viper/README.md
generated
vendored
79
vendor/github.com/spf13/viper/README.md
generated
vendored
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
Go configuration with fangs!
|
Go configuration with fangs!
|
||||||
|
|
||||||
|
[](https://github.com/spf13/viper)
|
||||||
|
[](https://gitter.im/spf13/viper?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
[](https://godoc.org/github.com/spf13/viper)
|
||||||
|
|
||||||
Many Go projects are built using Viper including:
|
Many Go projects are built using Viper including:
|
||||||
|
|
||||||
* [Hugo](http://gohugo.io)
|
* [Hugo](http://gohugo.io)
|
||||||
@ -12,14 +16,16 @@ Many Go projects are built using Viper including:
|
|||||||
* [BloomApi](https://www.bloomapi.com/)
|
* [BloomApi](https://www.bloomapi.com/)
|
||||||
* [doctl](https://github.com/digitalocean/doctl)
|
* [doctl](https://github.com/digitalocean/doctl)
|
||||||
* [Clairctl](https://github.com/jgsqware/clairctl)
|
* [Clairctl](https://github.com/jgsqware/clairctl)
|
||||||
|
* [Mercure](https://mercure.rocks)
|
||||||
|
|
||||||
[](https://travis-ci.org/spf13/viper) [](https://gitter.im/spf13/viper?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://godoc.org/github.com/spf13/viper)
|
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
```console
|
```console
|
||||||
go get -u github.com/spf13/viper
|
go get github.com/spf13/viper
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## What is Viper?
|
## What is Viper?
|
||||||
|
|
||||||
Viper is a complete configuration solution for Go applications including 12-Factor apps. It is designed
|
Viper is a complete configuration solution for Go applications including 12-Factor apps. It is designed
|
||||||
@ -35,8 +41,8 @@ and formats. It supports:
|
|||||||
* reading from buffer
|
* reading from buffer
|
||||||
* setting explicit values
|
* setting explicit values
|
||||||
|
|
||||||
Viper can be thought of as a registry for all of your applications
|
Viper can be thought of as a registry for all of your applications configuration needs.
|
||||||
configuration needs.
|
|
||||||
|
|
||||||
## Why Viper?
|
## Why Viper?
|
||||||
|
|
||||||
@ -46,34 +52,31 @@ Viper is here to help with that.
|
|||||||
|
|
||||||
Viper does the following for you:
|
Viper does the following for you:
|
||||||
|
|
||||||
1. Find, load, and unmarshal a configuration file in JSON, TOML, YAML, HCL, envfile or Java properties formats.
|
1. Find, load, and unmarshal a configuration file in JSON, TOML, YAML, HCL, INI, envfile or Java properties formats.
|
||||||
2. Provide a mechanism to set default values for your different
|
2. Provide a mechanism to set default values for your different configuration options.
|
||||||
configuration options.
|
3. Provide a mechanism to set override values for options specified through command line flags.
|
||||||
3. Provide a mechanism to set override values for options specified through
|
4. Provide an alias system to easily rename parameters without breaking existing code.
|
||||||
command line flags.
|
5. Make it easy to tell the difference between when a user has provided a command line or config file which is the same as the default.
|
||||||
4. Provide an alias system to easily rename parameters without breaking existing
|
|
||||||
code.
|
|
||||||
5. Make it easy to tell the difference between when a user has provided a
|
|
||||||
command line or config file which is the same as the default.
|
|
||||||
|
|
||||||
Viper uses the following precedence order. Each item takes precedence over the
|
Viper uses the following precedence order. Each item takes precedence over the item below it:
|
||||||
item below it:
|
|
||||||
|
|
||||||
* explicit call to Set
|
* explicit call to `Set`
|
||||||
* flag
|
* flag
|
||||||
* env
|
* env
|
||||||
* config
|
* config
|
||||||
* key/value store
|
* key/value store
|
||||||
* default
|
* default
|
||||||
|
|
||||||
Viper configuration keys are case insensitive.
|
**Important:** Viper configuration keys are case insensitive.
|
||||||
|
There are ongoing discussions about making that optional.
|
||||||
|
|
||||||
|
|
||||||
## Putting Values into Viper
|
## Putting Values into Viper
|
||||||
|
|
||||||
### Establishing Defaults
|
### Establishing Defaults
|
||||||
|
|
||||||
A good configuration system will support default values. A default value is not
|
A good configuration system will support default values. A default value is not
|
||||||
required for a key, but it’s useful in the event that a key hasn’t been set via
|
required for a key, but it’s useful in the event that a key hasn't been set via
|
||||||
config file, environment variable, remote configuration or flag.
|
config file, environment variable, remote configuration or flag.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
@ -87,7 +90,7 @@ viper.SetDefault("Taxonomies", map[string]string{"tag": "tags", "category": "cat
|
|||||||
### Reading Config Files
|
### Reading Config Files
|
||||||
|
|
||||||
Viper requires minimal configuration so it knows where to look for config files.
|
Viper requires minimal configuration so it knows where to look for config files.
|
||||||
Viper supports JSON, TOML, YAML, HCL, envfile and Java Properties files. Viper can search multiple paths, but
|
Viper supports JSON, TOML, YAML, HCL, INI, envfile and Java Properties files. Viper can search multiple paths, but
|
||||||
currently a single Viper instance only supports a single configuration file.
|
currently a single Viper instance only supports a single configuration file.
|
||||||
Viper does not default to any configuration search paths leaving defaults decision
|
Viper does not default to any configuration search paths leaving defaults decision
|
||||||
to an application.
|
to an application.
|
||||||
@ -121,6 +124,8 @@ if err := viper.ReadInConfig(); err != nil {
|
|||||||
// Config file found and successfully parsed
|
// Config file found and successfully parsed
|
||||||
```
|
```
|
||||||
|
|
||||||
|
*NOTE:* You can also have a file without an extension and specify the format programmaticaly. For those configuration files that lie in the home of the user without any extension like `.bashrc`
|
||||||
|
|
||||||
### Writing Config Files
|
### Writing Config Files
|
||||||
|
|
||||||
Reading from config files is useful, but at times you want to store all modifications made at run time.
|
Reading from config files is useful, but at times you want to store all modifications made at run time.
|
||||||
@ -258,6 +263,9 @@ keys to an extent. This is useful if you want to use `-` or something in your
|
|||||||
`Get()` calls, but want your environmental variables to use `_` delimiters. An
|
`Get()` calls, but want your environmental variables to use `_` delimiters. An
|
||||||
example of using it can be found in `viper_test.go`.
|
example of using it can be found in `viper_test.go`.
|
||||||
|
|
||||||
|
Alternatively, you can use `EnvKeyReplacer` with `NewWithOptions` factory function.
|
||||||
|
Unlike `SetEnvKeyReplacer`, it accepts a `StringReplacer` interface allowing you to write custom string replacing logic.
|
||||||
|
|
||||||
By default empty environment variables are considered unset and will fall back to
|
By default empty environment variables are considered unset and will fall back to
|
||||||
the next configuration source. To treat empty environment variables as set, use
|
the next configuration source. To treat empty environment variables as set, use
|
||||||
the `AllowEmptyEnv` method.
|
the `AllowEmptyEnv` method.
|
||||||
@ -658,6 +666,32 @@ if err != nil {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you want to unmarshal configuration where the keys themselves contain dot (the default key delimiter),
|
||||||
|
you have to change the delimiter:
|
||||||
|
|
||||||
|
```go
|
||||||
|
v := viper.NewWithOptions(viper.KeyDelimiter("::"))
|
||||||
|
|
||||||
|
v.SetDefault("chart::values", map[string]interface{}{
|
||||||
|
"ingress": map[string]interface{}{
|
||||||
|
"annotations": map[string]interface{}{
|
||||||
|
"traefik.frontend.rule.type": "PathPrefix",
|
||||||
|
"traefik.ingress.kubernetes.io/ssl-redirect": "true",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
type config struct {
|
||||||
|
Chart struct{
|
||||||
|
Values map[string]interface{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var C config
|
||||||
|
|
||||||
|
v.Unmarshal(&C)
|
||||||
|
```
|
||||||
|
|
||||||
Viper uses [github.com/mitchellh/mapstructure](https://github.com/mitchellh/mapstructure) under the hood for unmarshaling values which uses `mapstructure` tags by default.
|
Viper uses [github.com/mitchellh/mapstructure](https://github.com/mitchellh/mapstructure) under the hood for unmarshaling values which uses `mapstructure` tags by default.
|
||||||
|
|
||||||
### Marshalling to string
|
### Marshalling to string
|
||||||
@ -715,13 +749,6 @@ different vipers.
|
|||||||
|
|
||||||
## Q & A
|
## Q & A
|
||||||
|
|
||||||
Q: Why not INI files?
|
|
||||||
|
|
||||||
A: Ini files are pretty awful. There’s no standard format, and they are hard to
|
|
||||||
validate. Viper is designed to work with JSON, TOML or YAML files. If someone
|
|
||||||
really wants to add this feature, I’d be happy to merge it. It’s easy to specify
|
|
||||||
which formats your application will permit.
|
|
||||||
|
|
||||||
Q: Why is it called “Viper”?
|
Q: Why is it called “Viper”?
|
||||||
|
|
||||||
A: Viper is designed to be a [companion](http://en.wikipedia.org/wiki/Viper_(G.I._Joe))
|
A: Viper is designed to be a [companion](http://en.wikipedia.org/wiki/Viper_(G.I._Joe))
|
||||||
|
2
vendor/github.com/spf13/viper/go.mod
generated
vendored
2
vendor/github.com/spf13/viper/go.mod
generated
vendored
@ -24,6 +24,7 @@ require (
|
|||||||
github.com/mitchellh/mapstructure v1.1.2
|
github.com/mitchellh/mapstructure v1.1.2
|
||||||
github.com/pelletier/go-toml v1.2.0
|
github.com/pelletier/go-toml v1.2.0
|
||||||
github.com/prometheus/client_golang v0.9.3 // indirect
|
github.com/prometheus/client_golang v0.9.3 // indirect
|
||||||
|
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||||
github.com/soheilhy/cmux v0.1.4 // indirect
|
github.com/soheilhy/cmux v0.1.4 // indirect
|
||||||
github.com/spf13/afero v1.1.2
|
github.com/spf13/afero v1.1.2
|
||||||
github.com/spf13/cast v1.3.0
|
github.com/spf13/cast v1.3.0
|
||||||
@ -42,5 +43,6 @@ require (
|
|||||||
golang.org/x/net v0.0.0-20190522155817-f3200d17e092 // indirect
|
golang.org/x/net v0.0.0-20190522155817-f3200d17e092 // indirect
|
||||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
|
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
|
||||||
google.golang.org/grpc v1.21.0 // indirect
|
google.golang.org/grpc v1.21.0 // indirect
|
||||||
|
gopkg.in/ini.v1 v1.51.0
|
||||||
gopkg.in/yaml.v2 v2.2.4
|
gopkg.in/yaml.v2 v2.2.4
|
||||||
)
|
)
|
||||||
|
12
vendor/github.com/spf13/viper/go.sum
generated
vendored
12
vendor/github.com/spf13/viper/go.sum
generated
vendored
@ -48,6 +48,8 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
|
|||||||
github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
|
github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
|
||||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
||||||
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
|
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
|
||||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmonfrMlCDdsejg4CZE7c=
|
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmonfrMlCDdsejg4CZE7c=
|
||||||
@ -60,6 +62,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
|||||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||||
github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo=
|
github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo=
|
||||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||||
|
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||||
|
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
@ -101,6 +105,10 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T
|
|||||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||||
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
|
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
|
||||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||||
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||||
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||||
|
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
||||||
|
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||||
github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E=
|
github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E=
|
||||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||||
@ -161,6 +169,8 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb
|
|||||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384 h1:TFlARGu6Czu1z7q93HTxcP1P+/ZFC/IKythI5RzrnRg=
|
||||||
|
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
|
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
|
||||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||||
@ -172,6 +182,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
|
|||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
|
||||||
|
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||||
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
||||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
6
vendor/github.com/spf13/viper/util.go
generated
vendored
6
vendor/github.com/spf13/viper/util.go
generated
vendored
@ -114,11 +114,11 @@ func absPathify(inPath string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if File / Directory Exists
|
// Check if file Exists
|
||||||
func exists(fs afero.Fs, path string) (bool, error) {
|
func exists(fs afero.Fs, path string) (bool, error) {
|
||||||
_, err := fs.Stat(path)
|
stat, err := fs.Stat(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return true, nil
|
return !stat.IsDir(), nil
|
||||||
}
|
}
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return false, nil
|
return false, nil
|
||||||
|
195
vendor/github.com/spf13/viper/viper.go
generated
vendored
195
vendor/github.com/spf13/viper/viper.go
generated
vendored
@ -23,6 +23,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@ -33,19 +34,19 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v2"
|
|
||||||
|
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/hashicorp/hcl"
|
"github.com/hashicorp/hcl"
|
||||||
"github.com/hashicorp/hcl/hcl/printer"
|
"github.com/hashicorp/hcl/hcl/printer"
|
||||||
"github.com/magiconair/properties"
|
"github.com/magiconair/properties"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
toml "github.com/pelletier/go-toml"
|
"github.com/pelletier/go-toml"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
jww "github.com/spf13/jwalterweatherman"
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"github.com/subosito/gotenv"
|
"github.com/subosito/gotenv"
|
||||||
|
"gopkg.in/ini.v1"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConfigMarshalError happens when failing to marshal the configuration.
|
// ConfigMarshalError happens when failing to marshal the configuration.
|
||||||
@ -115,6 +116,14 @@ func (fnfe ConfigFileNotFoundError) Error() string {
|
|||||||
return fmt.Sprintf("Config File %q Not Found in %q", fnfe.name, fnfe.locations)
|
return fmt.Sprintf("Config File %q Not Found in %q", fnfe.name, fnfe.locations)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConfigFileAlreadyExistsError denotes failure to write new configuration file.
|
||||||
|
type ConfigFileAlreadyExistsError string
|
||||||
|
|
||||||
|
// Error returns the formatted error when configuration already exists.
|
||||||
|
func (faee ConfigFileAlreadyExistsError) Error() string {
|
||||||
|
return fmt.Sprintf("Config File %q Already Exists", string(faee))
|
||||||
|
}
|
||||||
|
|
||||||
// A DecoderConfigOption can be passed to viper.Unmarshal to configure
|
// A DecoderConfigOption can be passed to viper.Unmarshal to configure
|
||||||
// mapstructure.DecoderConfig options
|
// mapstructure.DecoderConfig options
|
||||||
type DecoderConfigOption func(*mapstructure.DecoderConfig)
|
type DecoderConfigOption func(*mapstructure.DecoderConfig)
|
||||||
@ -188,7 +197,7 @@ type Viper struct {
|
|||||||
envPrefix string
|
envPrefix string
|
||||||
|
|
||||||
automaticEnvApplied bool
|
automaticEnvApplied bool
|
||||||
envKeyReplacer *strings.Replacer
|
envKeyReplacer StringReplacer
|
||||||
allowEmptyEnv bool
|
allowEmptyEnv bool
|
||||||
|
|
||||||
config map[string]interface{}
|
config map[string]interface{}
|
||||||
@ -226,12 +235,58 @@ func New() *Viper {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Option configures Viper using the functional options paradigm popularized by Rob Pike and Dave Cheney.
|
||||||
|
// If you're unfamiliar with this style,
|
||||||
|
// see https://commandcenter.blogspot.com/2014/01/self-referential-functions-and-design.html and
|
||||||
|
// https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis.
|
||||||
|
type Option interface {
|
||||||
|
apply(v *Viper)
|
||||||
|
}
|
||||||
|
|
||||||
|
type optionFunc func(v *Viper)
|
||||||
|
|
||||||
|
func (fn optionFunc) apply(v *Viper) {
|
||||||
|
fn(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyDelimiter sets the delimiter used for determining key parts.
|
||||||
|
// By default it's value is ".".
|
||||||
|
func KeyDelimiter(d string) Option {
|
||||||
|
return optionFunc(func(v *Viper) {
|
||||||
|
v.keyDelim = d
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringReplacer applies a set of replacements to a string.
|
||||||
|
type StringReplacer interface {
|
||||||
|
// Replace returns a copy of s with all replacements performed.
|
||||||
|
Replace(s string) string
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnvKeyReplacer sets a replacer used for mapping environment variables to internal keys.
|
||||||
|
func EnvKeyReplacer(r StringReplacer) Option {
|
||||||
|
return optionFunc(func(v *Viper) {
|
||||||
|
v.envKeyReplacer = r
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewWithOptions creates a new Viper instance.
|
||||||
|
func NewWithOptions(opts ...Option) *Viper {
|
||||||
|
v := New()
|
||||||
|
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt.apply(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
// Reset is intended for testing, will reset all to default settings.
|
// Reset is intended for testing, will reset all to default settings.
|
||||||
// In the public interface for the viper package so applications
|
// In the public interface for the viper package so applications
|
||||||
// can use it in their testing as well.
|
// can use it in their testing as well.
|
||||||
func Reset() {
|
func Reset() {
|
||||||
v = New()
|
v = New()
|
||||||
SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "dotenv", "env"}
|
SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "dotenv", "env", "ini"}
|
||||||
SupportedRemoteProviders = []string{"etcd", "consul"}
|
SupportedRemoteProviders = []string{"etcd", "consul"}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +325,7 @@ type RemoteProvider interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SupportedExts are universally supported extensions.
|
// SupportedExts are universally supported extensions.
|
||||||
var SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "dotenv", "env"}
|
var SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "dotenv", "env", "ini"}
|
||||||
|
|
||||||
// SupportedRemoteProviders are universally supported remote providers.
|
// SupportedRemoteProviders are universally supported remote providers.
|
||||||
var SupportedRemoteProviders = []string{"etcd", "consul"}
|
var SupportedRemoteProviders = []string{"etcd", "consul"}
|
||||||
@ -670,7 +725,7 @@ func GetViper() *Viper {
|
|||||||
func Get(key string) interface{} { return v.Get(key) }
|
func Get(key string) interface{} { return v.Get(key) }
|
||||||
func (v *Viper) Get(key string) interface{} {
|
func (v *Viper) Get(key string) interface{} {
|
||||||
lcaseKey := strings.ToLower(key)
|
lcaseKey := strings.ToLower(key)
|
||||||
val := v.find(lcaseKey)
|
val := v.find(lcaseKey, true)
|
||||||
if val == nil {
|
if val == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -894,8 +949,11 @@ func decode(input interface{}, config *mapstructure.DecoderConfig) error {
|
|||||||
|
|
||||||
// UnmarshalExact unmarshals the config into a Struct, erroring if a field is nonexistent
|
// UnmarshalExact unmarshals the config into a Struct, erroring if a field is nonexistent
|
||||||
// in the destination struct.
|
// in the destination struct.
|
||||||
func (v *Viper) UnmarshalExact(rawVal interface{}) error {
|
func UnmarshalExact(rawVal interface{}, opts ...DecoderConfigOption) error {
|
||||||
config := defaultDecoderConfig(rawVal)
|
return v.UnmarshalExact(rawVal, opts...)
|
||||||
|
}
|
||||||
|
func (v *Viper) UnmarshalExact(rawVal interface{}, opts ...DecoderConfigOption) error {
|
||||||
|
config := defaultDecoderConfig(rawVal, opts...)
|
||||||
config.ErrorUnused = true
|
config.ErrorUnused = true
|
||||||
|
|
||||||
err := decode(v.AllSettings(), config)
|
err := decode(v.AllSettings(), config)
|
||||||
@ -960,7 +1018,7 @@ func BindEnv(input ...string) error { return v.BindEnv(input...) }
|
|||||||
func (v *Viper) BindEnv(input ...string) error {
|
func (v *Viper) BindEnv(input ...string) error {
|
||||||
var key, envkey string
|
var key, envkey string
|
||||||
if len(input) == 0 {
|
if len(input) == 0 {
|
||||||
return fmt.Errorf("BindEnv missing key to bind to")
|
return fmt.Errorf("missing key to bind to")
|
||||||
}
|
}
|
||||||
|
|
||||||
key = strings.ToLower(input[0])
|
key = strings.ToLower(input[0])
|
||||||
@ -977,12 +1035,15 @@ func (v *Viper) BindEnv(input ...string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Given a key, find the value.
|
// Given a key, find the value.
|
||||||
// Viper will check in the following order:
|
//
|
||||||
// flag, env, config file, key/value store, default.
|
|
||||||
// Viper will check to see if an alias exists first.
|
// Viper will check to see if an alias exists first.
|
||||||
|
// Viper will then check in the following order:
|
||||||
|
// flag, env, config file, key/value store.
|
||||||
|
// Lastly, if no value was found and flagDefault is true, and if the key
|
||||||
|
// corresponds to a flag, the flag's default value is returned.
|
||||||
|
//
|
||||||
// Note: this assumes a lower-cased key given.
|
// Note: this assumes a lower-cased key given.
|
||||||
func (v *Viper) find(lcaseKey string) interface{} {
|
func (v *Viper) find(lcaseKey string, flagDefault bool) interface{} {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
val interface{}
|
val interface{}
|
||||||
exists bool
|
exists bool
|
||||||
@ -1083,29 +1144,31 @@ func (v *Viper) find(lcaseKey string) interface{} {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// last chance: if no other value is returned and a flag does exist for the value,
|
if flagDefault {
|
||||||
// get the flag's value even if the flag's value has not changed
|
// last chance: if no value is found and a flag does exist for the key,
|
||||||
if flag, exists := v.pflags[lcaseKey]; exists {
|
// get the flag's default value even if the flag's value has not been set.
|
||||||
switch flag.ValueType() {
|
if flag, exists := v.pflags[lcaseKey]; exists {
|
||||||
case "int", "int8", "int16", "int32", "int64":
|
switch flag.ValueType() {
|
||||||
return cast.ToInt(flag.ValueString())
|
case "int", "int8", "int16", "int32", "int64":
|
||||||
case "bool":
|
return cast.ToInt(flag.ValueString())
|
||||||
return cast.ToBool(flag.ValueString())
|
case "bool":
|
||||||
case "stringSlice":
|
return cast.ToBool(flag.ValueString())
|
||||||
s := strings.TrimPrefix(flag.ValueString(), "[")
|
case "stringSlice":
|
||||||
s = strings.TrimSuffix(s, "]")
|
s := strings.TrimPrefix(flag.ValueString(), "[")
|
||||||
res, _ := readAsCSV(s)
|
s = strings.TrimSuffix(s, "]")
|
||||||
return res
|
res, _ := readAsCSV(s)
|
||||||
case "intSlice":
|
return res
|
||||||
s := strings.TrimPrefix(flag.ValueString(), "[")
|
case "intSlice":
|
||||||
s = strings.TrimSuffix(s, "]")
|
s := strings.TrimPrefix(flag.ValueString(), "[")
|
||||||
res, _ := readAsCSV(s)
|
s = strings.TrimSuffix(s, "]")
|
||||||
return cast.ToIntSlice(res)
|
res, _ := readAsCSV(s)
|
||||||
default:
|
return cast.ToIntSlice(res)
|
||||||
return flag.ValueString()
|
default:
|
||||||
|
return flag.ValueString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// last item, no need to check shadowing
|
||||||
}
|
}
|
||||||
// last item, no need to check shadowing
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -1124,7 +1187,7 @@ func readAsCSV(val string) ([]string, error) {
|
|||||||
func IsSet(key string) bool { return v.IsSet(key) }
|
func IsSet(key string) bool { return v.IsSet(key) }
|
||||||
func (v *Viper) IsSet(key string) bool {
|
func (v *Viper) IsSet(key string) bool {
|
||||||
lcaseKey := strings.ToLower(key)
|
lcaseKey := strings.ToLower(key)
|
||||||
val := v.find(lcaseKey)
|
val := v.find(lcaseKey, false)
|
||||||
return val != nil
|
return val != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1331,11 +1394,10 @@ func (v *Viper) WriteConfig() error {
|
|||||||
// SafeWriteConfig writes current configuration to file only if the file does not exist.
|
// SafeWriteConfig writes current configuration to file only if the file does not exist.
|
||||||
func SafeWriteConfig() error { return v.SafeWriteConfig() }
|
func SafeWriteConfig() error { return v.SafeWriteConfig() }
|
||||||
func (v *Viper) SafeWriteConfig() error {
|
func (v *Viper) SafeWriteConfig() error {
|
||||||
filename, err := v.getConfigFile()
|
if len(v.configPaths) < 1 {
|
||||||
if err != nil {
|
return errors.New("missing configuration for 'configPath'")
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
return v.writeConfig(filename, false)
|
return v.SafeWriteConfigAs(filepath.Join(v.configPaths[0], v.configName+"."+v.configType))
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteConfigAs writes current configuration to a given filename.
|
// WriteConfigAs writes current configuration to a given filename.
|
||||||
@ -1347,15 +1409,18 @@ func (v *Viper) WriteConfigAs(filename string) error {
|
|||||||
// SafeWriteConfigAs writes current configuration to a given filename if it does not exist.
|
// SafeWriteConfigAs writes current configuration to a given filename if it does not exist.
|
||||||
func SafeWriteConfigAs(filename string) error { return v.SafeWriteConfigAs(filename) }
|
func SafeWriteConfigAs(filename string) error { return v.SafeWriteConfigAs(filename) }
|
||||||
func (v *Viper) SafeWriteConfigAs(filename string) error {
|
func (v *Viper) SafeWriteConfigAs(filename string) error {
|
||||||
|
alreadyExists, err := afero.Exists(v.fs, filename)
|
||||||
|
if alreadyExists && err == nil {
|
||||||
|
return ConfigFileAlreadyExistsError(filename)
|
||||||
|
}
|
||||||
return v.writeConfig(filename, false)
|
return v.writeConfig(filename, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeConfig(filename string, force bool) error { return v.writeConfig(filename, force) }
|
|
||||||
func (v *Viper) writeConfig(filename string, force bool) error {
|
func (v *Viper) writeConfig(filename string, force bool) error {
|
||||||
jww.INFO.Println("Attempting to write configuration to file.")
|
jww.INFO.Println("Attempting to write configuration to file.")
|
||||||
ext := filepath.Ext(filename)
|
ext := filepath.Ext(filename)
|
||||||
if len(ext) <= 1 {
|
if len(ext) <= 1 {
|
||||||
return fmt.Errorf("Filename: %s requires valid extension.", filename)
|
return fmt.Errorf("filename: %s requires valid extension", filename)
|
||||||
}
|
}
|
||||||
configType := ext[1:]
|
configType := ext[1:]
|
||||||
if !stringInSlice(configType, SupportedExts) {
|
if !stringInSlice(configType, SupportedExts) {
|
||||||
@ -1444,6 +1509,23 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error {
|
|||||||
// set innermost value
|
// set innermost value
|
||||||
deepestMap[lastKey] = value
|
deepestMap[lastKey] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "ini":
|
||||||
|
cfg := ini.Empty()
|
||||||
|
err := cfg.Append(buf.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
return ConfigParseError{err}
|
||||||
|
}
|
||||||
|
sections := cfg.Sections()
|
||||||
|
for i := 0; i < len(sections); i++ {
|
||||||
|
section := sections[i]
|
||||||
|
keys := section.Keys()
|
||||||
|
for j := 0; j < len(keys); j++ {
|
||||||
|
key := keys[j]
|
||||||
|
value := cfg.Section(section.Name()).Key(key.Name()).String()
|
||||||
|
c[section.Name()+"."+key.Name()] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
insensitiviseMap(c)
|
insensitiviseMap(c)
|
||||||
@ -1451,9 +1533,6 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Marshal a map into Writer.
|
// Marshal a map into Writer.
|
||||||
func marshalWriter(f afero.File, configType string) error {
|
|
||||||
return v.marshalWriter(f, configType)
|
|
||||||
}
|
|
||||||
func (v *Viper) marshalWriter(f afero.File, configType string) error {
|
func (v *Viper) marshalWriter(f afero.File, configType string) error {
|
||||||
c := v.AllSettings()
|
c := v.AllSettings()
|
||||||
switch configType {
|
switch configType {
|
||||||
@ -1527,6 +1606,22 @@ func (v *Viper) marshalWriter(f afero.File, configType string) error {
|
|||||||
if _, err = f.WriteString(string(b)); err != nil {
|
if _, err = f.WriteString(string(b)); err != nil {
|
||||||
return ConfigMarshalError{err}
|
return ConfigMarshalError{err}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "ini":
|
||||||
|
keys := v.AllKeys()
|
||||||
|
cfg := ini.Empty()
|
||||||
|
ini.PrettyFormat = false
|
||||||
|
for i := 0; i < len(keys); i++ {
|
||||||
|
key := keys[i]
|
||||||
|
lastSep := strings.LastIndex(key, ".")
|
||||||
|
sectionName := key[:(lastSep)]
|
||||||
|
keyName := key[(lastSep + 1):]
|
||||||
|
if sectionName == "default" {
|
||||||
|
sectionName = ""
|
||||||
|
}
|
||||||
|
cfg.Section(sectionName).Key(keyName).SetValue(Get(key).(string))
|
||||||
|
}
|
||||||
|
cfg.WriteTo(f)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -1673,7 +1768,7 @@ func (v *Viper) getRemoteConfig(provider RemoteProvider) (map[string]interface{}
|
|||||||
func (v *Viper) watchKeyValueConfigOnChannel() error {
|
func (v *Viper) watchKeyValueConfigOnChannel() error {
|
||||||
for _, rp := range v.remoteProviders {
|
for _, rp := range v.remoteProviders {
|
||||||
respc, _ := RemoteConfig.WatchChannel(rp)
|
respc, _ := RemoteConfig.WatchChannel(rp)
|
||||||
//Todo: Add quit channel
|
// Todo: Add quit channel
|
||||||
go func(rc <-chan *RemoteResponse) {
|
go func(rc <-chan *RemoteResponse) {
|
||||||
for {
|
for {
|
||||||
b := <-rc
|
b := <-rc
|
||||||
@ -1709,7 +1804,7 @@ func (v *Viper) watchRemoteConfig(provider RemoteProvider) (map[string]interface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AllKeys returns all keys holding a value, regardless of where they are set.
|
// AllKeys returns all keys holding a value, regardless of where they are set.
|
||||||
// Nested keys are returned with a v.keyDelim (= ".") separator
|
// Nested keys are returned with a v.keyDelim separator
|
||||||
func AllKeys() []string { return v.AllKeys() }
|
func AllKeys() []string { return v.AllKeys() }
|
||||||
func (v *Viper) AllKeys() []string {
|
func (v *Viper) AllKeys() []string {
|
||||||
m := map[string]bool{}
|
m := map[string]bool{}
|
||||||
@ -1732,7 +1827,7 @@ func (v *Viper) AllKeys() []string {
|
|||||||
|
|
||||||
// flattenAndMergeMap recursively flattens the given map into a map[string]bool
|
// flattenAndMergeMap recursively flattens the given map into a map[string]bool
|
||||||
// of key paths (used as a set, easier to manipulate than a []string):
|
// of key paths (used as a set, easier to manipulate than a []string):
|
||||||
// - each path is merged into a single key string, delimited with v.keyDelim (= ".")
|
// - each path is merged into a single key string, delimited with v.keyDelim
|
||||||
// - if a path is shadowed by an earlier value in the initial shadow map,
|
// - if a path is shadowed by an earlier value in the initial shadow map,
|
||||||
// it is skipped.
|
// it is skipped.
|
||||||
// The resulting set of paths is merged to the given shadow set at the same time.
|
// The resulting set of paths is merged to the given shadow set at the same time.
|
||||||
@ -1881,6 +1976,10 @@ func (v *Viper) searchInPath(in string) (filename string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b, _ := exists(v.fs, filepath.Join(in, v.configName)); b {
|
||||||
|
return filepath.Join(in, v.configName)
|
||||||
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
vendor/golang.org/x/crypto/ssh/certs.go
generated
vendored
35
vendor/golang.org/x/crypto/ssh/certs.go
generated
vendored
@ -17,12 +17,14 @@ import (
|
|||||||
// These constants from [PROTOCOL.certkeys] represent the algorithm names
|
// These constants from [PROTOCOL.certkeys] represent the algorithm names
|
||||||
// for certificate types supported by this package.
|
// for certificate types supported by this package.
|
||||||
const (
|
const (
|
||||||
CertAlgoRSAv01 = "ssh-rsa-cert-v01@openssh.com"
|
CertAlgoRSAv01 = "ssh-rsa-cert-v01@openssh.com"
|
||||||
CertAlgoDSAv01 = "ssh-dss-cert-v01@openssh.com"
|
CertAlgoDSAv01 = "ssh-dss-cert-v01@openssh.com"
|
||||||
CertAlgoECDSA256v01 = "ecdsa-sha2-nistp256-cert-v01@openssh.com"
|
CertAlgoECDSA256v01 = "ecdsa-sha2-nistp256-cert-v01@openssh.com"
|
||||||
CertAlgoECDSA384v01 = "ecdsa-sha2-nistp384-cert-v01@openssh.com"
|
CertAlgoECDSA384v01 = "ecdsa-sha2-nistp384-cert-v01@openssh.com"
|
||||||
CertAlgoECDSA521v01 = "ecdsa-sha2-nistp521-cert-v01@openssh.com"
|
CertAlgoECDSA521v01 = "ecdsa-sha2-nistp521-cert-v01@openssh.com"
|
||||||
CertAlgoED25519v01 = "ssh-ed25519-cert-v01@openssh.com"
|
CertAlgoSKECDSA256v01 = "sk-ecdsa-sha2-nistp256-cert-v01@openssh.com"
|
||||||
|
CertAlgoED25519v01 = "ssh-ed25519-cert-v01@openssh.com"
|
||||||
|
CertAlgoSKED25519v01 = "sk-ssh-ed25519-cert-v01@openssh.com"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Certificate types distinguish between host and user
|
// Certificate types distinguish between host and user
|
||||||
@ -37,6 +39,7 @@ const (
|
|||||||
type Signature struct {
|
type Signature struct {
|
||||||
Format string
|
Format string
|
||||||
Blob []byte
|
Blob []byte
|
||||||
|
Rest []byte `ssh:"rest"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CertTimeInfinity can be used for OpenSSHCertV01.ValidBefore to indicate that
|
// CertTimeInfinity can be used for OpenSSHCertV01.ValidBefore to indicate that
|
||||||
@ -429,12 +432,14 @@ func (c *Certificate) SignCert(rand io.Reader, authority Signer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var certAlgoNames = map[string]string{
|
var certAlgoNames = map[string]string{
|
||||||
KeyAlgoRSA: CertAlgoRSAv01,
|
KeyAlgoRSA: CertAlgoRSAv01,
|
||||||
KeyAlgoDSA: CertAlgoDSAv01,
|
KeyAlgoDSA: CertAlgoDSAv01,
|
||||||
KeyAlgoECDSA256: CertAlgoECDSA256v01,
|
KeyAlgoECDSA256: CertAlgoECDSA256v01,
|
||||||
KeyAlgoECDSA384: CertAlgoECDSA384v01,
|
KeyAlgoECDSA384: CertAlgoECDSA384v01,
|
||||||
KeyAlgoECDSA521: CertAlgoECDSA521v01,
|
KeyAlgoECDSA521: CertAlgoECDSA521v01,
|
||||||
KeyAlgoED25519: CertAlgoED25519v01,
|
KeyAlgoSKECDSA256: CertAlgoSKECDSA256v01,
|
||||||
|
KeyAlgoED25519: CertAlgoED25519v01,
|
||||||
|
KeyAlgoSKED25519: CertAlgoSKED25519v01,
|
||||||
}
|
}
|
||||||
|
|
||||||
// certToPrivAlgo returns the underlying algorithm for a certificate algorithm.
|
// certToPrivAlgo returns the underlying algorithm for a certificate algorithm.
|
||||||
@ -518,6 +523,12 @@ func parseSignatureBody(in []byte) (out *Signature, rest []byte, ok bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch out.Format {
|
||||||
|
case KeyAlgoSKECDSA256, CertAlgoSKECDSA256v01, KeyAlgoSKED25519, CertAlgoSKED25519v01:
|
||||||
|
out.Rest = in
|
||||||
|
return out, nil, ok
|
||||||
|
}
|
||||||
|
|
||||||
return out, in, ok
|
return out, in, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
280
vendor/golang.org/x/crypto/ssh/keys.go
generated
vendored
280
vendor/golang.org/x/crypto/ssh/keys.go
generated
vendored
@ -30,12 +30,14 @@ import (
|
|||||||
// These constants represent the algorithm names for key types supported by this
|
// These constants represent the algorithm names for key types supported by this
|
||||||
// package.
|
// package.
|
||||||
const (
|
const (
|
||||||
KeyAlgoRSA = "ssh-rsa"
|
KeyAlgoRSA = "ssh-rsa"
|
||||||
KeyAlgoDSA = "ssh-dss"
|
KeyAlgoDSA = "ssh-dss"
|
||||||
KeyAlgoECDSA256 = "ecdsa-sha2-nistp256"
|
KeyAlgoECDSA256 = "ecdsa-sha2-nistp256"
|
||||||
KeyAlgoECDSA384 = "ecdsa-sha2-nistp384"
|
KeyAlgoSKECDSA256 = "sk-ecdsa-sha2-nistp256@openssh.com"
|
||||||
KeyAlgoECDSA521 = "ecdsa-sha2-nistp521"
|
KeyAlgoECDSA384 = "ecdsa-sha2-nistp384"
|
||||||
KeyAlgoED25519 = "ssh-ed25519"
|
KeyAlgoECDSA521 = "ecdsa-sha2-nistp521"
|
||||||
|
KeyAlgoED25519 = "ssh-ed25519"
|
||||||
|
KeyAlgoSKED25519 = "sk-ssh-ed25519@openssh.com"
|
||||||
)
|
)
|
||||||
|
|
||||||
// These constants represent non-default signature algorithms that are supported
|
// These constants represent non-default signature algorithms that are supported
|
||||||
@ -58,9 +60,13 @@ func parsePubKey(in []byte, algo string) (pubKey PublicKey, rest []byte, err err
|
|||||||
return parseDSA(in)
|
return parseDSA(in)
|
||||||
case KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521:
|
case KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521:
|
||||||
return parseECDSA(in)
|
return parseECDSA(in)
|
||||||
|
case KeyAlgoSKECDSA256:
|
||||||
|
return parseSKECDSA(in)
|
||||||
case KeyAlgoED25519:
|
case KeyAlgoED25519:
|
||||||
return parseED25519(in)
|
return parseED25519(in)
|
||||||
case CertAlgoRSAv01, CertAlgoDSAv01, CertAlgoECDSA256v01, CertAlgoECDSA384v01, CertAlgoECDSA521v01, CertAlgoED25519v01:
|
case KeyAlgoSKED25519:
|
||||||
|
return parseSKEd25519(in)
|
||||||
|
case CertAlgoRSAv01, CertAlgoDSAv01, CertAlgoECDSA256v01, CertAlgoECDSA384v01, CertAlgoECDSA521v01, CertAlgoSKECDSA256v01, CertAlgoED25519v01, CertAlgoSKED25519v01:
|
||||||
cert, err := parseCert(in, certToPrivAlgo(algo))
|
cert, err := parseCert(in, certToPrivAlgo(algo))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@ -685,6 +691,218 @@ func (k *ecdsaPublicKey) CryptoPublicKey() crypto.PublicKey {
|
|||||||
return (*ecdsa.PublicKey)(k)
|
return (*ecdsa.PublicKey)(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// skFields holds the additional fields present in U2F/FIDO2 signatures.
|
||||||
|
// See openssh/PROTOCOL.u2f 'SSH U2F Signatures' for details.
|
||||||
|
type skFields struct {
|
||||||
|
// Flags contains U2F/FIDO2 flags such as 'user present'
|
||||||
|
Flags byte
|
||||||
|
// Counter is a monotonic signature counter which can be
|
||||||
|
// used to detect concurrent use of a private key, should
|
||||||
|
// it be extracted from hardware.
|
||||||
|
Counter uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
type skECDSAPublicKey struct {
|
||||||
|
// application is a URL-like string, typically "ssh:" for SSH.
|
||||||
|
// see openssh/PROTOCOL.u2f for details.
|
||||||
|
application string
|
||||||
|
ecdsa.PublicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *skECDSAPublicKey) Type() string {
|
||||||
|
return KeyAlgoSKECDSA256
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *skECDSAPublicKey) nistID() string {
|
||||||
|
return "nistp256"
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseSKECDSA(in []byte) (out PublicKey, rest []byte, err error) {
|
||||||
|
var w struct {
|
||||||
|
Curve string
|
||||||
|
KeyBytes []byte
|
||||||
|
Application string
|
||||||
|
Rest []byte `ssh:"rest"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := Unmarshal(in, &w); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
key := new(skECDSAPublicKey)
|
||||||
|
key.application = w.Application
|
||||||
|
|
||||||
|
if w.Curve != "nistp256" {
|
||||||
|
return nil, nil, errors.New("ssh: unsupported curve")
|
||||||
|
}
|
||||||
|
key.Curve = elliptic.P256()
|
||||||
|
|
||||||
|
key.X, key.Y = elliptic.Unmarshal(key.Curve, w.KeyBytes)
|
||||||
|
if key.X == nil || key.Y == nil {
|
||||||
|
return nil, nil, errors.New("ssh: invalid curve point")
|
||||||
|
}
|
||||||
|
|
||||||
|
return key, w.Rest, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *skECDSAPublicKey) Marshal() []byte {
|
||||||
|
// See RFC 5656, section 3.1.
|
||||||
|
keyBytes := elliptic.Marshal(k.Curve, k.X, k.Y)
|
||||||
|
w := struct {
|
||||||
|
Name string
|
||||||
|
ID string
|
||||||
|
Key []byte
|
||||||
|
Application string
|
||||||
|
}{
|
||||||
|
k.Type(),
|
||||||
|
k.nistID(),
|
||||||
|
keyBytes,
|
||||||
|
k.application,
|
||||||
|
}
|
||||||
|
|
||||||
|
return Marshal(&w)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *skECDSAPublicKey) Verify(data []byte, sig *Signature) error {
|
||||||
|
if sig.Format != k.Type() {
|
||||||
|
return fmt.Errorf("ssh: signature type %s for key type %s", sig.Format, k.Type())
|
||||||
|
}
|
||||||
|
|
||||||
|
h := ecHash(k.Curve).New()
|
||||||
|
h.Write([]byte(k.application))
|
||||||
|
appDigest := h.Sum(nil)
|
||||||
|
|
||||||
|
h.Reset()
|
||||||
|
h.Write(data)
|
||||||
|
dataDigest := h.Sum(nil)
|
||||||
|
|
||||||
|
var ecSig struct {
|
||||||
|
R *big.Int
|
||||||
|
S *big.Int
|
||||||
|
}
|
||||||
|
if err := Unmarshal(sig.Blob, &ecSig); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var skf skFields
|
||||||
|
if err := Unmarshal(sig.Rest, &skf); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
blob := struct {
|
||||||
|
ApplicationDigest []byte `ssh:"rest"`
|
||||||
|
Flags byte
|
||||||
|
Counter uint32
|
||||||
|
MessageDigest []byte `ssh:"rest"`
|
||||||
|
}{
|
||||||
|
appDigest,
|
||||||
|
skf.Flags,
|
||||||
|
skf.Counter,
|
||||||
|
dataDigest,
|
||||||
|
}
|
||||||
|
|
||||||
|
original := Marshal(blob)
|
||||||
|
|
||||||
|
h.Reset()
|
||||||
|
h.Write(original)
|
||||||
|
digest := h.Sum(nil)
|
||||||
|
|
||||||
|
if ecdsa.Verify((*ecdsa.PublicKey)(&k.PublicKey), digest, ecSig.R, ecSig.S) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return errors.New("ssh: signature did not verify")
|
||||||
|
}
|
||||||
|
|
||||||
|
type skEd25519PublicKey struct {
|
||||||
|
// application is a URL-like string, typically "ssh:" for SSH.
|
||||||
|
// see openssh/PROTOCOL.u2f for details.
|
||||||
|
application string
|
||||||
|
ed25519.PublicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *skEd25519PublicKey) Type() string {
|
||||||
|
return KeyAlgoSKED25519
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseSKEd25519(in []byte) (out PublicKey, rest []byte, err error) {
|
||||||
|
var w struct {
|
||||||
|
KeyBytes []byte
|
||||||
|
Application string
|
||||||
|
Rest []byte `ssh:"rest"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := Unmarshal(in, &w); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
key := new(skEd25519PublicKey)
|
||||||
|
key.application = w.Application
|
||||||
|
key.PublicKey = ed25519.PublicKey(w.KeyBytes)
|
||||||
|
|
||||||
|
return key, w.Rest, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *skEd25519PublicKey) Marshal() []byte {
|
||||||
|
w := struct {
|
||||||
|
Name string
|
||||||
|
KeyBytes []byte
|
||||||
|
Application string
|
||||||
|
}{
|
||||||
|
KeyAlgoSKED25519,
|
||||||
|
[]byte(k.PublicKey),
|
||||||
|
k.application,
|
||||||
|
}
|
||||||
|
return Marshal(&w)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *skEd25519PublicKey) Verify(data []byte, sig *Signature) error {
|
||||||
|
if sig.Format != k.Type() {
|
||||||
|
return fmt.Errorf("ssh: signature type %s for key type %s", sig.Format, k.Type())
|
||||||
|
}
|
||||||
|
|
||||||
|
h := sha256.New()
|
||||||
|
h.Write([]byte(k.application))
|
||||||
|
appDigest := h.Sum(nil)
|
||||||
|
|
||||||
|
h.Reset()
|
||||||
|
h.Write(data)
|
||||||
|
dataDigest := h.Sum(nil)
|
||||||
|
|
||||||
|
var edSig struct {
|
||||||
|
Signature []byte `ssh:"rest"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := Unmarshal(sig.Blob, &edSig); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var skf skFields
|
||||||
|
if err := Unmarshal(sig.Rest, &skf); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
blob := struct {
|
||||||
|
ApplicationDigest []byte `ssh:"rest"`
|
||||||
|
Flags byte
|
||||||
|
Counter uint32
|
||||||
|
MessageDigest []byte `ssh:"rest"`
|
||||||
|
}{
|
||||||
|
appDigest,
|
||||||
|
skf.Flags,
|
||||||
|
skf.Counter,
|
||||||
|
dataDigest,
|
||||||
|
}
|
||||||
|
|
||||||
|
original := Marshal(blob)
|
||||||
|
|
||||||
|
edKey := (ed25519.PublicKey)(k.PublicKey)
|
||||||
|
if ok := ed25519.Verify(edKey, original, edSig.Signature); !ok {
|
||||||
|
return errors.New("ssh: signature did not verify")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// NewSignerFromKey takes an *rsa.PrivateKey, *dsa.PrivateKey,
|
// NewSignerFromKey takes an *rsa.PrivateKey, *dsa.PrivateKey,
|
||||||
// *ecdsa.PrivateKey or any other crypto.Signer and returns a
|
// *ecdsa.PrivateKey or any other crypto.Signer and returns a
|
||||||
// corresponding Signer instance. ECDSA keys must use P-256, P-384 or
|
// corresponding Signer instance. ECDSA keys must use P-256, P-384 or
|
||||||
@ -837,7 +1055,8 @@ func NewPublicKey(key interface{}) (PublicKey, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ParsePrivateKey returns a Signer from a PEM encoded private key. It supports
|
// ParsePrivateKey returns a Signer from a PEM encoded private key. It supports
|
||||||
// the same keys as ParseRawPrivateKey.
|
// the same keys as ParseRawPrivateKey. If the private key is encrypted, it
|
||||||
|
// will return a PassphraseMissingError.
|
||||||
func ParsePrivateKey(pemBytes []byte) (Signer, error) {
|
func ParsePrivateKey(pemBytes []byte) (Signer, error) {
|
||||||
key, err := ParseRawPrivateKey(pemBytes)
|
key, err := ParseRawPrivateKey(pemBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -850,8 +1069,8 @@ func ParsePrivateKey(pemBytes []byte) (Signer, error) {
|
|||||||
// ParsePrivateKeyWithPassphrase returns a Signer from a PEM encoded private
|
// ParsePrivateKeyWithPassphrase returns a Signer from a PEM encoded private
|
||||||
// key and passphrase. It supports the same keys as
|
// key and passphrase. It supports the same keys as
|
||||||
// ParseRawPrivateKeyWithPassphrase.
|
// ParseRawPrivateKeyWithPassphrase.
|
||||||
func ParsePrivateKeyWithPassphrase(pemBytes, passPhrase []byte) (Signer, error) {
|
func ParsePrivateKeyWithPassphrase(pemBytes, passphrase []byte) (Signer, error) {
|
||||||
key, err := ParseRawPrivateKeyWithPassphrase(pemBytes, passPhrase)
|
key, err := ParseRawPrivateKeyWithPassphrase(pemBytes, passphrase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -867,8 +1086,21 @@ func encryptedBlock(block *pem.Block) bool {
|
|||||||
return strings.Contains(block.Headers["Proc-Type"], "ENCRYPTED")
|
return strings.Contains(block.Headers["Proc-Type"], "ENCRYPTED")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A PassphraseMissingError indicates that parsing this private key requires a
|
||||||
|
// passphrase. Use ParsePrivateKeyWithPassphrase.
|
||||||
|
type PassphraseMissingError struct {
|
||||||
|
// PublicKey will be set if the private key format includes an unencrypted
|
||||||
|
// public key along with the encrypted private key.
|
||||||
|
PublicKey PublicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*PassphraseMissingError) Error() string {
|
||||||
|
return "ssh: this private key is passphrase protected"
|
||||||
|
}
|
||||||
|
|
||||||
// ParseRawPrivateKey returns a private key from a PEM encoded private key. It
|
// ParseRawPrivateKey returns a private key from a PEM encoded private key. It
|
||||||
// supports RSA (PKCS#1), PKCS#8, DSA (OpenSSL), and ECDSA private keys.
|
// supports RSA (PKCS#1), PKCS#8, DSA (OpenSSL), and ECDSA private keys. If the
|
||||||
|
// private key is encrypted, it will return a PassphraseMissingError.
|
||||||
func ParseRawPrivateKey(pemBytes []byte) (interface{}, error) {
|
func ParseRawPrivateKey(pemBytes []byte) (interface{}, error) {
|
||||||
block, _ := pem.Decode(pemBytes)
|
block, _ := pem.Decode(pemBytes)
|
||||||
if block == nil {
|
if block == nil {
|
||||||
@ -876,7 +1108,7 @@ func ParseRawPrivateKey(pemBytes []byte) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if encryptedBlock(block) {
|
if encryptedBlock(block) {
|
||||||
return nil, errors.New("ssh: cannot decode encrypted private keys")
|
return nil, &PassphraseMissingError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch block.Type {
|
switch block.Type {
|
||||||
@ -899,24 +1131,22 @@ func ParseRawPrivateKey(pemBytes []byte) (interface{}, error) {
|
|||||||
// ParseRawPrivateKeyWithPassphrase returns a private key decrypted with
|
// ParseRawPrivateKeyWithPassphrase returns a private key decrypted with
|
||||||
// passphrase from a PEM encoded private key. If wrong passphrase, return
|
// passphrase from a PEM encoded private key. If wrong passphrase, return
|
||||||
// x509.IncorrectPasswordError.
|
// x509.IncorrectPasswordError.
|
||||||
func ParseRawPrivateKeyWithPassphrase(pemBytes, passPhrase []byte) (interface{}, error) {
|
func ParseRawPrivateKeyWithPassphrase(pemBytes, passphrase []byte) (interface{}, error) {
|
||||||
block, _ := pem.Decode(pemBytes)
|
block, _ := pem.Decode(pemBytes)
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return nil, errors.New("ssh: no key found")
|
return nil, errors.New("ssh: no key found")
|
||||||
}
|
}
|
||||||
buf := block.Bytes
|
|
||||||
|
|
||||||
if encryptedBlock(block) {
|
if !encryptedBlock(block) || !x509.IsEncryptedPEMBlock(block) {
|
||||||
if x509.IsEncryptedPEMBlock(block) {
|
return nil, errors.New("ssh: not an encrypted key")
|
||||||
var err error
|
}
|
||||||
buf, err = x509.DecryptPEMBlock(block, passPhrase)
|
|
||||||
if err != nil {
|
buf, err := x509.DecryptPEMBlock(block, passphrase)
|
||||||
if err == x509.IncorrectPasswordError {
|
if err != nil {
|
||||||
return nil, err
|
if err == x509.IncorrectPasswordError {
|
||||||
}
|
return nil, err
|
||||||
return nil, fmt.Errorf("ssh: cannot decode encrypted private keys: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return nil, fmt.Errorf("ssh: cannot decode encrypted private keys: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch block.Type {
|
switch block.Type {
|
||||||
@ -926,8 +1156,6 @@ func ParseRawPrivateKeyWithPassphrase(pemBytes, passPhrase []byte) (interface{},
|
|||||||
return x509.ParseECPrivateKey(buf)
|
return x509.ParseECPrivateKey(buf)
|
||||||
case "DSA PRIVATE KEY":
|
case "DSA PRIVATE KEY":
|
||||||
return ParseDSAPrivateKey(buf)
|
return ParseDSAPrivateKey(buf)
|
||||||
case "OPENSSH PRIVATE KEY":
|
|
||||||
return parseOpenSSHPrivateKey(buf)
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("ssh: unsupported key type %q", block.Type)
|
return nil, fmt.Errorf("ssh: unsupported key type %q", block.Type)
|
||||||
}
|
}
|
||||||
|
4
vendor/golang.org/x/crypto/ssh/server.go
generated
vendored
4
vendor/golang.org/x/crypto/ssh/server.go
generated
vendored
@ -284,8 +284,8 @@ func (s *connection) serverHandshake(config *ServerConfig) (*Permissions, error)
|
|||||||
|
|
||||||
func isAcceptableAlgo(algo string) bool {
|
func isAcceptableAlgo(algo string) bool {
|
||||||
switch algo {
|
switch algo {
|
||||||
case KeyAlgoRSA, KeyAlgoDSA, KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521, KeyAlgoED25519,
|
case KeyAlgoRSA, KeyAlgoDSA, KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521, KeyAlgoSKECDSA256, KeyAlgoED25519, KeyAlgoSKED25519,
|
||||||
CertAlgoRSAv01, CertAlgoDSAv01, CertAlgoECDSA256v01, CertAlgoECDSA384v01, CertAlgoECDSA521v01, CertAlgoED25519v01:
|
CertAlgoRSAv01, CertAlgoDSAv01, CertAlgoECDSA256v01, CertAlgoECDSA384v01, CertAlgoECDSA521v01, CertAlgoSKECDSA256v01, CertAlgoED25519v01, CertAlgoSKED25519v01:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
134
vendor/golang.org/x/sys/cpu/cpu_arm64.go
generated
vendored
Normal file
134
vendor/golang.org/x/sys/cpu/cpu_arm64.go
generated
vendored
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
// Copyright 2019 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.
|
||||||
|
|
||||||
|
package cpu
|
||||||
|
|
||||||
|
import "runtime"
|
||||||
|
|
||||||
|
const cacheLineSize = 64
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "darwin":
|
||||||
|
// iOS does not seem to allow reading these registers
|
||||||
|
case "android", "linux":
|
||||||
|
doinit()
|
||||||
|
default:
|
||||||
|
readARM64Registers()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func readARM64Registers() {
|
||||||
|
Initialized = true
|
||||||
|
|
||||||
|
// ID_AA64ISAR0_EL1
|
||||||
|
isar0 := getisar0()
|
||||||
|
|
||||||
|
switch extractBits(isar0, 4, 7) {
|
||||||
|
case 1:
|
||||||
|
ARM64.HasAES = true
|
||||||
|
case 2:
|
||||||
|
ARM64.HasAES = true
|
||||||
|
ARM64.HasPMULL = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch extractBits(isar0, 8, 11) {
|
||||||
|
case 1:
|
||||||
|
ARM64.HasSHA1 = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch extractBits(isar0, 12, 15) {
|
||||||
|
case 1:
|
||||||
|
ARM64.HasSHA2 = true
|
||||||
|
case 2:
|
||||||
|
ARM64.HasSHA2 = true
|
||||||
|
ARM64.HasSHA512 = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch extractBits(isar0, 16, 19) {
|
||||||
|
case 1:
|
||||||
|
ARM64.HasCRC32 = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch extractBits(isar0, 20, 23) {
|
||||||
|
case 2:
|
||||||
|
ARM64.HasATOMICS = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch extractBits(isar0, 28, 31) {
|
||||||
|
case 1:
|
||||||
|
ARM64.HasASIMDRDM = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch extractBits(isar0, 32, 35) {
|
||||||
|
case 1:
|
||||||
|
ARM64.HasSHA3 = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch extractBits(isar0, 36, 39) {
|
||||||
|
case 1:
|
||||||
|
ARM64.HasSM3 = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch extractBits(isar0, 40, 43) {
|
||||||
|
case 1:
|
||||||
|
ARM64.HasSM4 = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch extractBits(isar0, 44, 47) {
|
||||||
|
case 1:
|
||||||
|
ARM64.HasASIMDDP = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ID_AA64ISAR1_EL1
|
||||||
|
isar1 := getisar1()
|
||||||
|
|
||||||
|
switch extractBits(isar1, 0, 3) {
|
||||||
|
case 1:
|
||||||
|
ARM64.HasDCPOP = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch extractBits(isar1, 12, 15) {
|
||||||
|
case 1:
|
||||||
|
ARM64.HasJSCVT = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch extractBits(isar1, 16, 19) {
|
||||||
|
case 1:
|
||||||
|
ARM64.HasFCMA = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch extractBits(isar1, 20, 23) {
|
||||||
|
case 1:
|
||||||
|
ARM64.HasLRCPC = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ID_AA64PFR0_EL1
|
||||||
|
pfr0 := getpfr0()
|
||||||
|
|
||||||
|
switch extractBits(pfr0, 16, 19) {
|
||||||
|
case 0:
|
||||||
|
ARM64.HasFP = true
|
||||||
|
case 1:
|
||||||
|
ARM64.HasFP = true
|
||||||
|
ARM64.HasFPHP = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch extractBits(pfr0, 20, 23) {
|
||||||
|
case 0:
|
||||||
|
ARM64.HasASIMD = true
|
||||||
|
case 1:
|
||||||
|
ARM64.HasASIMD = true
|
||||||
|
ARM64.HasASIMDHP = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch extractBits(pfr0, 32, 35) {
|
||||||
|
case 1:
|
||||||
|
ARM64.HasSVE = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractBits(data uint64, start, end uint) uint {
|
||||||
|
return (uint)(data>>start) & ((1 << (end - start + 1)) - 1)
|
||||||
|
}
|
31
vendor/golang.org/x/sys/cpu/cpu_arm64.s
generated
vendored
Normal file
31
vendor/golang.org/x/sys/cpu/cpu_arm64.s
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright 2019 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 !gccgo
|
||||||
|
|
||||||
|
#include "textflag.h"
|
||||||
|
|
||||||
|
// func getisar0() uint64
|
||||||
|
TEXT ·getisar0(SB),NOSPLIT,$0-8
|
||||||
|
// get Instruction Set Attributes 0 into x0
|
||||||
|
// mrs x0, ID_AA64ISAR0_EL1 = d5380600
|
||||||
|
WORD $0xd5380600
|
||||||
|
MOVD R0, ret+0(FP)
|
||||||
|
RET
|
||||||
|
|
||||||
|
// func getisar1() uint64
|
||||||
|
TEXT ·getisar1(SB),NOSPLIT,$0-8
|
||||||
|
// get Instruction Set Attributes 1 into x0
|
||||||
|
// mrs x0, ID_AA64ISAR1_EL1 = d5380620
|
||||||
|
WORD $0xd5380620
|
||||||
|
MOVD R0, ret+0(FP)
|
||||||
|
RET
|
||||||
|
|
||||||
|
// func getpfr0() uint64
|
||||||
|
TEXT ·getpfr0(SB),NOSPLIT,$0-8
|
||||||
|
// get Processor Feature Register 0 into x0
|
||||||
|
// mrs x0, ID_AA64PFR0_EL1 = d5380400
|
||||||
|
WORD $0xd5380400
|
||||||
|
MOVD R0, ret+0(FP)
|
||||||
|
RET
|
11
vendor/golang.org/x/sys/cpu/cpu_gc_arm64.go
generated
vendored
Normal file
11
vendor/golang.org/x/sys/cpu/cpu_gc_arm64.go
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright 2019 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 !gccgo
|
||||||
|
|
||||||
|
package cpu
|
||||||
|
|
||||||
|
func getisar0() uint64
|
||||||
|
func getisar1() uint64
|
||||||
|
func getpfr0() uint64
|
11
vendor/golang.org/x/sys/cpu/cpu_gccgo_arm64.go
generated
vendored
Normal file
11
vendor/golang.org/x/sys/cpu/cpu_gccgo_arm64.go
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright 2019 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 gccgo
|
||||||
|
|
||||||
|
package cpu
|
||||||
|
|
||||||
|
func getisar0() uint64 { return 0 }
|
||||||
|
func getisar1() uint64 { return 0 }
|
||||||
|
func getpfr0() uint64 { return 0 }
|
48
vendor/golang.org/x/sys/cpu/cpu_linux.go
generated
vendored
48
vendor/golang.org/x/sys/cpu/cpu_linux.go
generated
vendored
@ -2,58 +2,14 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// +build !amd64,!amd64p32,!386
|
// +build !386,!amd64,!amd64p32,!arm64
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
import (
|
|
||||||
"io/ioutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
_AT_HWCAP = 16
|
|
||||||
_AT_HWCAP2 = 26
|
|
||||||
|
|
||||||
procAuxv = "/proc/self/auxv"
|
|
||||||
|
|
||||||
uintSize = int(32 << (^uint(0) >> 63))
|
|
||||||
)
|
|
||||||
|
|
||||||
// For those platforms don't have a 'cpuid' equivalent we use HWCAP/HWCAP2
|
|
||||||
// These are initialized in cpu_$GOARCH.go
|
|
||||||
// and should not be changed after they are initialized.
|
|
||||||
var hwCap uint
|
|
||||||
var hwCap2 uint
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
buf, err := ioutil.ReadFile(procAuxv)
|
if err := readHWCAP(); err != nil {
|
||||||
if err != nil {
|
|
||||||
// e.g. on android /proc/self/auxv is not accessible, so silently
|
|
||||||
// ignore the error and leave Initialized = false
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
bo := hostByteOrder()
|
|
||||||
for len(buf) >= 2*(uintSize/8) {
|
|
||||||
var tag, val uint
|
|
||||||
switch uintSize {
|
|
||||||
case 32:
|
|
||||||
tag = uint(bo.Uint32(buf[0:]))
|
|
||||||
val = uint(bo.Uint32(buf[4:]))
|
|
||||||
buf = buf[8:]
|
|
||||||
case 64:
|
|
||||||
tag = uint(bo.Uint64(buf[0:]))
|
|
||||||
val = uint(bo.Uint64(buf[8:]))
|
|
||||||
buf = buf[16:]
|
|
||||||
}
|
|
||||||
switch tag {
|
|
||||||
case _AT_HWCAP:
|
|
||||||
hwCap = val
|
|
||||||
case _AT_HWCAP2:
|
|
||||||
hwCap2 = val
|
|
||||||
}
|
|
||||||
}
|
|
||||||
doinit()
|
doinit()
|
||||||
|
|
||||||
Initialized = true
|
Initialized = true
|
||||||
}
|
}
|
||||||
|
8
vendor/golang.org/x/sys/cpu/cpu_linux_arm64.go
generated
vendored
8
vendor/golang.org/x/sys/cpu/cpu_linux_arm64.go
generated
vendored
@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
const cacheLineSize = 64
|
|
||||||
|
|
||||||
// HWCAP/HWCAP2 bits. These are exposed by Linux.
|
// HWCAP/HWCAP2 bits. These are exposed by Linux.
|
||||||
const (
|
const (
|
||||||
hwcap_FP = 1 << 0
|
hwcap_FP = 1 << 0
|
||||||
@ -35,6 +33,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func doinit() {
|
func doinit() {
|
||||||
|
if err := readHWCAP(); err != nil {
|
||||||
|
// failed to read /proc/self/auxv, try reading registers directly
|
||||||
|
readARM64Registers()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// HWCAP feature bits
|
// HWCAP feature bits
|
||||||
ARM64.HasFP = isSet(hwCap, hwcap_FP)
|
ARM64.HasFP = isSet(hwCap, hwcap_FP)
|
||||||
ARM64.HasASIMD = isSet(hwCap, hwcap_ASIMD)
|
ARM64.HasASIMD = isSet(hwCap, hwcap_ASIMD)
|
||||||
|
9
vendor/golang.org/x/sys/cpu/cpu_linux_noinit.go
generated
vendored
Normal file
9
vendor/golang.org/x/sys/cpu/cpu_linux_noinit.go
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// Copyright 2019 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,!arm,!arm64,!ppc64,!ppc64le,!s390x
|
||||||
|
|
||||||
|
package cpu
|
||||||
|
|
||||||
|
func doinit() {}
|
2
vendor/golang.org/x/sys/cpu/cpu_mips64x.go
generated
vendored
2
vendor/golang.org/x/sys/cpu/cpu_mips64x.go
generated
vendored
@ -7,5 +7,3 @@
|
|||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
const cacheLineSize = 32
|
const cacheLineSize = 32
|
||||||
|
|
||||||
func doinit() {}
|
|
||||||
|
2
vendor/golang.org/x/sys/cpu/cpu_mipsx.go
generated
vendored
2
vendor/golang.org/x/sys/cpu/cpu_mipsx.go
generated
vendored
@ -7,5 +7,3 @@
|
|||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
const cacheLineSize = 32
|
const cacheLineSize = 32
|
||||||
|
|
||||||
func doinit() {}
|
|
||||||
|
2
vendor/golang.org/x/sys/cpu/cpu_other_arm64.go
generated
vendored
2
vendor/golang.org/x/sys/cpu/cpu_other_arm64.go
generated
vendored
@ -6,6 +6,4 @@
|
|||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
const cacheLineSize = 64
|
|
||||||
|
|
||||||
func doinit() {}
|
func doinit() {}
|
||||||
|
9
vendor/golang.org/x/sys/cpu/cpu_riscv64.go
generated
vendored
Normal file
9
vendor/golang.org/x/sys/cpu/cpu_riscv64.go
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// Copyright 2019 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 riscv64
|
||||||
|
|
||||||
|
package cpu
|
||||||
|
|
||||||
|
const cacheLineSize = 32
|
2
vendor/golang.org/x/sys/cpu/cpu_wasm.go
generated
vendored
2
vendor/golang.org/x/sys/cpu/cpu_wasm.go
generated
vendored
@ -11,5 +11,3 @@ package cpu
|
|||||||
// rules are good enough.
|
// rules are good enough.
|
||||||
|
|
||||||
const cacheLineSize = 0
|
const cacheLineSize = 0
|
||||||
|
|
||||||
func doinit() {}
|
|
||||||
|
56
vendor/golang.org/x/sys/cpu/hwcap_linux.go
generated
vendored
Normal file
56
vendor/golang.org/x/sys/cpu/hwcap_linux.go
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// Copyright 2019 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.
|
||||||
|
|
||||||
|
package cpu
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
_AT_HWCAP = 16
|
||||||
|
_AT_HWCAP2 = 26
|
||||||
|
|
||||||
|
procAuxv = "/proc/self/auxv"
|
||||||
|
|
||||||
|
uintSize = int(32 << (^uint(0) >> 63))
|
||||||
|
)
|
||||||
|
|
||||||
|
// For those platforms don't have a 'cpuid' equivalent we use HWCAP/HWCAP2
|
||||||
|
// These are initialized in cpu_$GOARCH.go
|
||||||
|
// and should not be changed after they are initialized.
|
||||||
|
var hwCap uint
|
||||||
|
var hwCap2 uint
|
||||||
|
|
||||||
|
func readHWCAP() error {
|
||||||
|
buf, err := ioutil.ReadFile(procAuxv)
|
||||||
|
if err != nil {
|
||||||
|
// e.g. on android /proc/self/auxv is not accessible, so silently
|
||||||
|
// ignore the error and leave Initialized = false. On some
|
||||||
|
// architectures (e.g. arm64) doinit() implements a fallback
|
||||||
|
// readout and will set Initialized = true again.
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
bo := hostByteOrder()
|
||||||
|
for len(buf) >= 2*(uintSize/8) {
|
||||||
|
var tag, val uint
|
||||||
|
switch uintSize {
|
||||||
|
case 32:
|
||||||
|
tag = uint(bo.Uint32(buf[0:]))
|
||||||
|
val = uint(bo.Uint32(buf[4:]))
|
||||||
|
buf = buf[8:]
|
||||||
|
case 64:
|
||||||
|
tag = uint(bo.Uint64(buf[0:]))
|
||||||
|
val = uint(bo.Uint64(buf[8:]))
|
||||||
|
buf = buf[16:]
|
||||||
|
}
|
||||||
|
switch tag {
|
||||||
|
case _AT_HWCAP:
|
||||||
|
hwCap = val
|
||||||
|
case _AT_HWCAP2:
|
||||||
|
hwCap2 = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
2
vendor/golang.org/x/sys/unix/mkall.sh
generated
vendored
2
vendor/golang.org/x/sys/unix/mkall.sh
generated
vendored
@ -50,7 +50,7 @@ if [[ "$GOOS" = "linux" ]]; then
|
|||||||
# Use the Docker-based build system
|
# Use the Docker-based build system
|
||||||
# Files generated through docker (use $cmd so you can Ctl-C the build or run)
|
# Files generated through docker (use $cmd so you can Ctl-C the build or run)
|
||||||
$cmd docker build --tag generate:$GOOS $GOOS
|
$cmd docker build --tag generate:$GOOS $GOOS
|
||||||
$cmd docker run --interactive --tty --volume $(dirname "$(readlink -f "$0")"):/build generate:$GOOS
|
$cmd docker run --interactive --tty --volume $(cd -- "$(dirname -- "$0")" && /bin/pwd):/build generate:$GOOS
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
78
vendor/golang.org/x/sys/unix/mkasm_darwin.go
generated
vendored
78
vendor/golang.org/x/sys/unix/mkasm_darwin.go
generated
vendored
@ -1,78 +0,0 @@
|
|||||||
// Copyright 2018 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 ignore
|
|
||||||
|
|
||||||
// mkasm_darwin.go generates assembly trampolines to call libSystem routines from Go.
|
|
||||||
//This program must be run after mksyscall.go.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func writeASMFile(in string, fileName string, buildTags string) {
|
|
||||||
trampolines := map[string]bool{}
|
|
||||||
|
|
||||||
var out bytes.Buffer
|
|
||||||
|
|
||||||
fmt.Fprintf(&out, "// go run mkasm_darwin.go %s\n", strings.Join(os.Args[1:], " "))
|
|
||||||
fmt.Fprintf(&out, "// Code generated by the command above; DO NOT EDIT.\n")
|
|
||||||
fmt.Fprintf(&out, "\n")
|
|
||||||
fmt.Fprintf(&out, "// +build %s\n", buildTags)
|
|
||||||
fmt.Fprintf(&out, "\n")
|
|
||||||
fmt.Fprintf(&out, "#include \"textflag.h\"\n")
|
|
||||||
for _, line := range strings.Split(in, "\n") {
|
|
||||||
if !strings.HasPrefix(line, "func ") || !strings.HasSuffix(line, "_trampoline()") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fn := line[5 : len(line)-13]
|
|
||||||
if !trampolines[fn] {
|
|
||||||
trampolines[fn] = true
|
|
||||||
fmt.Fprintf(&out, "TEXT ·%s_trampoline(SB),NOSPLIT,$0-0\n", fn)
|
|
||||||
fmt.Fprintf(&out, "\tJMP\t%s(SB)\n", fn)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err := ioutil.WriteFile(fileName, out.Bytes(), 0644)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("can't write %s: %s", fileName, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
in1, err := ioutil.ReadFile("syscall_darwin.go")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("can't open syscall_darwin.go: %s", err)
|
|
||||||
}
|
|
||||||
arch := os.Args[1]
|
|
||||||
in2, err := ioutil.ReadFile(fmt.Sprintf("syscall_darwin_%s.go", arch))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("can't open syscall_darwin_%s.go: %s", arch, err)
|
|
||||||
}
|
|
||||||
in3, err := ioutil.ReadFile(fmt.Sprintf("zsyscall_darwin_%s.go", arch))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("can't open zsyscall_darwin_%s.go: %s", arch, err)
|
|
||||||
}
|
|
||||||
in := string(in1) + string(in2) + string(in3)
|
|
||||||
|
|
||||||
writeASMFile(in, fmt.Sprintf("zsyscall_darwin_%s.s", arch), "go1.12")
|
|
||||||
|
|
||||||
in1, err = ioutil.ReadFile("syscall_darwin.1_13.go")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("can't open syscall_darwin.1_13.go: %s", err)
|
|
||||||
}
|
|
||||||
in2, err = ioutil.ReadFile(fmt.Sprintf("zsyscall_darwin_%s.1_13.go", arch))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("can't open zsyscall_darwin_%s.1_13.go: %s", arch, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
in = string(in1) + string(in2)
|
|
||||||
|
|
||||||
writeASMFile(in, fmt.Sprintf("zsyscall_darwin_%s.1_13.s", arch), "go1.13")
|
|
||||||
}
|
|
6
vendor/golang.org/x/sys/unix/mkerrors.sh
generated
vendored
6
vendor/golang.org/x/sys/unix/mkerrors.sh
generated
vendored
@ -44,6 +44,7 @@ includes_AIX='
|
|||||||
#include <sys/stropts.h>
|
#include <sys/stropts.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/poll.h>
|
#include <sys/poll.h>
|
||||||
|
#include <sys/select.h>
|
||||||
#include <sys/termio.h>
|
#include <sys/termio.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -196,6 +197,7 @@ struct ltchars {
|
|||||||
#include <linux/fanotify.h>
|
#include <linux/fanotify.h>
|
||||||
#include <linux/filter.h>
|
#include <linux/filter.h>
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
|
#include <linux/fscrypt.h>
|
||||||
#include <linux/genetlink.h>
|
#include <linux/genetlink.h>
|
||||||
#include <linux/hdreg.h>
|
#include <linux/hdreg.h>
|
||||||
#include <linux/icmpv6.h>
|
#include <linux/icmpv6.h>
|
||||||
@ -495,7 +497,9 @@ ccflags="$@"
|
|||||||
$2 ~ /^CAN_/ ||
|
$2 ~ /^CAN_/ ||
|
||||||
$2 ~ /^CAP_/ ||
|
$2 ~ /^CAP_/ ||
|
||||||
$2 ~ /^ALG_/ ||
|
$2 ~ /^ALG_/ ||
|
||||||
$2 ~ /^FS_(POLICY_FLAGS|KEY_DESC|ENCRYPTION_MODE|[A-Z0-9_]+_KEY_SIZE|IOC_(GET|SET)_ENCRYPTION)/ ||
|
$2 ~ /^FS_(POLICY_FLAGS|KEY_DESC|ENCRYPTION_MODE|[A-Z0-9_]+_KEY_SIZE)/ ||
|
||||||
|
$2 ~ /^FS_IOC_.*ENCRYPTION/ ||
|
||||||
|
$2 ~ /^FSCRYPT_/ ||
|
||||||
$2 ~ /^GRND_/ ||
|
$2 ~ /^GRND_/ ||
|
||||||
$2 ~ /^RND/ ||
|
$2 ~ /^RND/ ||
|
||||||
$2 ~ /^KEY_(SPEC|REQKEY_DEFL)_/ ||
|
$2 ~ /^KEY_(SPEC|REQKEY_DEFL)_/ ||
|
||||||
|
122
vendor/golang.org/x/sys/unix/mkpost.go
generated
vendored
122
vendor/golang.org/x/sys/unix/mkpost.go
generated
vendored
@ -1,122 +0,0 @@
|
|||||||
// Copyright 2016 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 ignore
|
|
||||||
|
|
||||||
// mkpost processes the output of cgo -godefs to
|
|
||||||
// modify the generated types. It is used to clean up
|
|
||||||
// the sys API in an architecture specific manner.
|
|
||||||
//
|
|
||||||
// mkpost is run after cgo -godefs; see README.md.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"go/format"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"regexp"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// Get the OS and architecture (using GOARCH_TARGET if it exists)
|
|
||||||
goos := os.Getenv("GOOS")
|
|
||||||
goarch := os.Getenv("GOARCH_TARGET")
|
|
||||||
if goarch == "" {
|
|
||||||
goarch = os.Getenv("GOARCH")
|
|
||||||
}
|
|
||||||
// Check that we are using the Docker-based build system if we should be.
|
|
||||||
if goos == "linux" {
|
|
||||||
if os.Getenv("GOLANG_SYS_BUILD") != "docker" {
|
|
||||||
os.Stderr.WriteString("In the Docker-based build system, mkpost should not be called directly.\n")
|
|
||||||
os.Stderr.WriteString("See README.md\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
b, err := ioutil.ReadAll(os.Stdin)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if goos == "aix" {
|
|
||||||
// Replace type of Atim, Mtim and Ctim by Timespec in Stat_t
|
|
||||||
// to avoid having both StTimespec and Timespec.
|
|
||||||
sttimespec := regexp.MustCompile(`_Ctype_struct_st_timespec`)
|
|
||||||
b = sttimespec.ReplaceAll(b, []byte("Timespec"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Intentionally export __val fields in Fsid and Sigset_t
|
|
||||||
valRegex := regexp.MustCompile(`type (Fsid|Sigset_t) struct {(\s+)X__(bits|val)(\s+\S+\s+)}`)
|
|
||||||
b = valRegex.ReplaceAll(b, []byte("type $1 struct {${2}Val$4}"))
|
|
||||||
|
|
||||||
// Intentionally export __fds_bits field in FdSet
|
|
||||||
fdSetRegex := regexp.MustCompile(`type (FdSet) struct {(\s+)X__fds_bits(\s+\S+\s+)}`)
|
|
||||||
b = fdSetRegex.ReplaceAll(b, []byte("type $1 struct {${2}Bits$3}"))
|
|
||||||
|
|
||||||
// If we have empty Ptrace structs, we should delete them. Only s390x emits
|
|
||||||
// nonempty Ptrace structs.
|
|
||||||
ptraceRexexp := regexp.MustCompile(`type Ptrace((Psw|Fpregs|Per) struct {\s*})`)
|
|
||||||
b = ptraceRexexp.ReplaceAll(b, nil)
|
|
||||||
|
|
||||||
// Replace the control_regs union with a blank identifier for now.
|
|
||||||
controlRegsRegex := regexp.MustCompile(`(Control_regs)\s+\[0\]uint64`)
|
|
||||||
b = controlRegsRegex.ReplaceAll(b, []byte("_ [0]uint64"))
|
|
||||||
|
|
||||||
// Remove fields that are added by glibc
|
|
||||||
// Note that this is unstable as the identifers are private.
|
|
||||||
removeFieldsRegex := regexp.MustCompile(`X__glibc\S*`)
|
|
||||||
b = removeFieldsRegex.ReplaceAll(b, []byte("_"))
|
|
||||||
|
|
||||||
// Convert [65]int8 to [65]byte in Utsname members to simplify
|
|
||||||
// conversion to string; see golang.org/issue/20753
|
|
||||||
convertUtsnameRegex := regexp.MustCompile(`((Sys|Node|Domain)name|Release|Version|Machine)(\s+)\[(\d+)\]u?int8`)
|
|
||||||
b = convertUtsnameRegex.ReplaceAll(b, []byte("$1$3[$4]byte"))
|
|
||||||
|
|
||||||
// Convert [1024]int8 to [1024]byte in Ptmget members
|
|
||||||
convertPtmget := regexp.MustCompile(`([SC]n)(\s+)\[(\d+)\]u?int8`)
|
|
||||||
b = convertPtmget.ReplaceAll(b, []byte("$1[$3]byte"))
|
|
||||||
|
|
||||||
// Remove spare fields (e.g. in Statx_t)
|
|
||||||
spareFieldsRegex := regexp.MustCompile(`X__spare\S*`)
|
|
||||||
b = spareFieldsRegex.ReplaceAll(b, []byte("_"))
|
|
||||||
|
|
||||||
// Remove cgo padding fields
|
|
||||||
removePaddingFieldsRegex := regexp.MustCompile(`Pad_cgo_\d+`)
|
|
||||||
b = removePaddingFieldsRegex.ReplaceAll(b, []byte("_"))
|
|
||||||
|
|
||||||
// Remove padding, hidden, or unused fields
|
|
||||||
removeFieldsRegex = regexp.MustCompile(`\b(X_\S+|Padding)`)
|
|
||||||
b = removeFieldsRegex.ReplaceAll(b, []byte("_"))
|
|
||||||
|
|
||||||
// Remove the first line of warning from cgo
|
|
||||||
b = b[bytes.IndexByte(b, '\n')+1:]
|
|
||||||
// Modify the command in the header to include:
|
|
||||||
// mkpost, our own warning, and a build tag.
|
|
||||||
replacement := fmt.Sprintf(`$1 | go run mkpost.go
|
|
||||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
|
||||||
|
|
||||||
// +build %s,%s`, goarch, goos)
|
|
||||||
cgoCommandRegex := regexp.MustCompile(`(cgo -godefs .*)`)
|
|
||||||
b = cgoCommandRegex.ReplaceAll(b, []byte(replacement))
|
|
||||||
|
|
||||||
// Rename Stat_t time fields
|
|
||||||
if goos == "freebsd" && goarch == "386" {
|
|
||||||
// Hide Stat_t.[AMCB]tim_ext fields
|
|
||||||
renameStatTimeExtFieldsRegex := regexp.MustCompile(`[AMCB]tim_ext`)
|
|
||||||
b = renameStatTimeExtFieldsRegex.ReplaceAll(b, []byte("_"))
|
|
||||||
}
|
|
||||||
renameStatTimeFieldsRegex := regexp.MustCompile(`([AMCB])(?:irth)?time?(?:spec)?\s+(Timespec|StTimespec)`)
|
|
||||||
b = renameStatTimeFieldsRegex.ReplaceAll(b, []byte("${1}tim ${2}"))
|
|
||||||
|
|
||||||
// gofmt
|
|
||||||
b, err = format.Source(b)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
os.Stdout.Write(b)
|
|
||||||
}
|
|
402
vendor/golang.org/x/sys/unix/mksyscall.go
generated
vendored
402
vendor/golang.org/x/sys/unix/mksyscall.go
generated
vendored
@ -1,402 +0,0 @@
|
|||||||
// Copyright 2018 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 ignore
|
|
||||||
|
|
||||||
/*
|
|
||||||
This program reads a file containing function prototypes
|
|
||||||
(like syscall_darwin.go) and generates system call bodies.
|
|
||||||
The prototypes are marked by lines beginning with "//sys"
|
|
||||||
and read like func declarations if //sys is replaced by func, but:
|
|
||||||
* The parameter lists must give a name for each argument.
|
|
||||||
This includes return parameters.
|
|
||||||
* The parameter lists must give a type for each argument:
|
|
||||||
the (x, y, z int) shorthand is not allowed.
|
|
||||||
* If the return parameter is an error number, it must be named errno.
|
|
||||||
|
|
||||||
A line beginning with //sysnb is like //sys, except that the
|
|
||||||
goroutine will not be suspended during the execution of the system
|
|
||||||
call. This must only be used for system calls which can never
|
|
||||||
block, as otherwise the system call could cause all goroutines to
|
|
||||||
hang.
|
|
||||||
*/
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
b32 = flag.Bool("b32", false, "32bit big-endian")
|
|
||||||
l32 = flag.Bool("l32", false, "32bit little-endian")
|
|
||||||
plan9 = flag.Bool("plan9", false, "plan9")
|
|
||||||
openbsd = flag.Bool("openbsd", false, "openbsd")
|
|
||||||
netbsd = flag.Bool("netbsd", false, "netbsd")
|
|
||||||
dragonfly = flag.Bool("dragonfly", false, "dragonfly")
|
|
||||||
arm = flag.Bool("arm", false, "arm") // 64-bit value should use (even, odd)-pair
|
|
||||||
tags = flag.String("tags", "", "build tags")
|
|
||||||
filename = flag.String("output", "", "output file name (standard output if omitted)")
|
|
||||||
)
|
|
||||||
|
|
||||||
// cmdLine returns this programs's commandline arguments
|
|
||||||
func cmdLine() string {
|
|
||||||
return "go run mksyscall.go " + strings.Join(os.Args[1:], " ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// buildTags returns build tags
|
|
||||||
func buildTags() string {
|
|
||||||
return *tags
|
|
||||||
}
|
|
||||||
|
|
||||||
// Param is function parameter
|
|
||||||
type Param struct {
|
|
||||||
Name string
|
|
||||||
Type string
|
|
||||||
}
|
|
||||||
|
|
||||||
// usage prints the program usage
|
|
||||||
func usage() {
|
|
||||||
fmt.Fprintf(os.Stderr, "usage: go run mksyscall.go [-b32 | -l32] [-tags x,y] [file ...]\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseParamList parses parameter list and returns a slice of parameters
|
|
||||||
func parseParamList(list string) []string {
|
|
||||||
list = strings.TrimSpace(list)
|
|
||||||
if list == "" {
|
|
||||||
return []string{}
|
|
||||||
}
|
|
||||||
return regexp.MustCompile(`\s*,\s*`).Split(list, -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseParam splits a parameter into name and type
|
|
||||||
func parseParam(p string) Param {
|
|
||||||
ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p)
|
|
||||||
if ps == nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
return Param{ps[1], ps[2]}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// Get the OS and architecture (using GOARCH_TARGET if it exists)
|
|
||||||
goos := os.Getenv("GOOS")
|
|
||||||
if goos == "" {
|
|
||||||
fmt.Fprintln(os.Stderr, "GOOS not defined in environment")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
goarch := os.Getenv("GOARCH_TARGET")
|
|
||||||
if goarch == "" {
|
|
||||||
goarch = os.Getenv("GOARCH")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that we are using the Docker-based build system if we should
|
|
||||||
if goos == "linux" {
|
|
||||||
if os.Getenv("GOLANG_SYS_BUILD") != "docker" {
|
|
||||||
fmt.Fprintf(os.Stderr, "In the Docker-based build system, mksyscall should not be called directly.\n")
|
|
||||||
fmt.Fprintf(os.Stderr, "See README.md\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
flag.Usage = usage
|
|
||||||
flag.Parse()
|
|
||||||
if len(flag.Args()) <= 0 {
|
|
||||||
fmt.Fprintf(os.Stderr, "no files to parse provided\n")
|
|
||||||
usage()
|
|
||||||
}
|
|
||||||
|
|
||||||
endianness := ""
|
|
||||||
if *b32 {
|
|
||||||
endianness = "big-endian"
|
|
||||||
} else if *l32 {
|
|
||||||
endianness = "little-endian"
|
|
||||||
}
|
|
||||||
|
|
||||||
libc := false
|
|
||||||
if goos == "darwin" && (strings.Contains(buildTags(), ",go1.12") || strings.Contains(buildTags(), ",go1.13")) {
|
|
||||||
libc = true
|
|
||||||
}
|
|
||||||
trampolines := map[string]bool{}
|
|
||||||
|
|
||||||
text := ""
|
|
||||||
for _, path := range flag.Args() {
|
|
||||||
file, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
s := bufio.NewScanner(file)
|
|
||||||
for s.Scan() {
|
|
||||||
t := s.Text()
|
|
||||||
t = strings.TrimSpace(t)
|
|
||||||
t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `)
|
|
||||||
nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t)
|
|
||||||
if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Line must be of the form
|
|
||||||
// func Open(path string, mode int, perm int) (fd int, errno error)
|
|
||||||
// Split into name, in params, out params.
|
|
||||||
f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*((?i)SYS_[A-Z0-9_]+))?$`).FindStringSubmatch(t)
|
|
||||||
if f == nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
funct, inps, outps, sysname := f[2], f[3], f[4], f[5]
|
|
||||||
|
|
||||||
// ClockGettime doesn't have a syscall number on Darwin, only generate libc wrappers.
|
|
||||||
if goos == "darwin" && !libc && funct == "ClockGettime" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Split argument lists on comma.
|
|
||||||
in := parseParamList(inps)
|
|
||||||
out := parseParamList(outps)
|
|
||||||
|
|
||||||
// Try in vain to keep people from editing this file.
|
|
||||||
// The theory is that they jump into the middle of the file
|
|
||||||
// without reading the header.
|
|
||||||
text += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
|
||||||
|
|
||||||
// Go function header.
|
|
||||||
outDecl := ""
|
|
||||||
if len(out) > 0 {
|
|
||||||
outDecl = fmt.Sprintf(" (%s)", strings.Join(out, ", "))
|
|
||||||
}
|
|
||||||
text += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outDecl)
|
|
||||||
|
|
||||||
// Check if err return available
|
|
||||||
errvar := ""
|
|
||||||
for _, param := range out {
|
|
||||||
p := parseParam(param)
|
|
||||||
if p.Type == "error" {
|
|
||||||
errvar = p.Name
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare arguments to Syscall.
|
|
||||||
var args []string
|
|
||||||
n := 0
|
|
||||||
for _, param := range in {
|
|
||||||
p := parseParam(param)
|
|
||||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
|
||||||
args = append(args, "uintptr(unsafe.Pointer("+p.Name+"))")
|
|
||||||
} else if p.Type == "string" && errvar != "" {
|
|
||||||
text += fmt.Sprintf("\tvar _p%d *byte\n", n)
|
|
||||||
text += fmt.Sprintf("\t_p%d, %s = BytePtrFromString(%s)\n", n, errvar, p.Name)
|
|
||||||
text += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar)
|
|
||||||
args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
|
||||||
n++
|
|
||||||
} else if p.Type == "string" {
|
|
||||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n")
|
|
||||||
text += fmt.Sprintf("\tvar _p%d *byte\n", n)
|
|
||||||
text += fmt.Sprintf("\t_p%d, _ = BytePtrFromString(%s)\n", n, p.Name)
|
|
||||||
args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
|
||||||
n++
|
|
||||||
} else if regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type) != nil {
|
|
||||||
// Convert slice into pointer, length.
|
|
||||||
// Have to be careful not to take address of &a[0] if len == 0:
|
|
||||||
// pass dummy pointer in that case.
|
|
||||||
// Used to pass nil, but some OSes or simulators reject write(fd, nil, 0).
|
|
||||||
text += fmt.Sprintf("\tvar _p%d unsafe.Pointer\n", n)
|
|
||||||
text += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = unsafe.Pointer(&%s[0])\n\t}", p.Name, n, p.Name)
|
|
||||||
text += fmt.Sprintf(" else {\n\t\t_p%d = unsafe.Pointer(&_zero)\n\t}\n", n)
|
|
||||||
args = append(args, fmt.Sprintf("uintptr(_p%d)", n), fmt.Sprintf("uintptr(len(%s))", p.Name))
|
|
||||||
n++
|
|
||||||
} else if p.Type == "int64" && (*openbsd || *netbsd) {
|
|
||||||
args = append(args, "0")
|
|
||||||
if endianness == "big-endian" {
|
|
||||||
args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
} else if endianness == "little-endian" {
|
|
||||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name))
|
|
||||||
} else {
|
|
||||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
}
|
|
||||||
} else if p.Type == "int64" && *dragonfly {
|
|
||||||
if regexp.MustCompile(`^(?i)extp(read|write)`).FindStringSubmatch(funct) == nil {
|
|
||||||
args = append(args, "0")
|
|
||||||
}
|
|
||||||
if endianness == "big-endian" {
|
|
||||||
args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
} else if endianness == "little-endian" {
|
|
||||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name))
|
|
||||||
} else {
|
|
||||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
}
|
|
||||||
} else if (p.Type == "int64" || p.Type == "uint64") && endianness != "" {
|
|
||||||
if len(args)%2 == 1 && *arm {
|
|
||||||
// arm abi specifies 64-bit argument uses
|
|
||||||
// (even, odd) pair
|
|
||||||
args = append(args, "0")
|
|
||||||
}
|
|
||||||
if endianness == "big-endian" {
|
|
||||||
args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
} else {
|
|
||||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine which form to use; pad args with zeros.
|
|
||||||
asm := "Syscall"
|
|
||||||
if nonblock != nil {
|
|
||||||
if errvar == "" && goos == "linux" {
|
|
||||||
asm = "RawSyscallNoError"
|
|
||||||
} else {
|
|
||||||
asm = "RawSyscall"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if errvar == "" && goos == "linux" {
|
|
||||||
asm = "SyscallNoError"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(args) <= 3 {
|
|
||||||
for len(args) < 3 {
|
|
||||||
args = append(args, "0")
|
|
||||||
}
|
|
||||||
} else if len(args) <= 6 {
|
|
||||||
asm += "6"
|
|
||||||
for len(args) < 6 {
|
|
||||||
args = append(args, "0")
|
|
||||||
}
|
|
||||||
} else if len(args) <= 9 {
|
|
||||||
asm += "9"
|
|
||||||
for len(args) < 9 {
|
|
||||||
args = append(args, "0")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(os.Stderr, "%s:%s too many arguments to system call\n", path, funct)
|
|
||||||
}
|
|
||||||
|
|
||||||
// System call number.
|
|
||||||
if sysname == "" {
|
|
||||||
sysname = "SYS_" + funct
|
|
||||||
sysname = regexp.MustCompile(`([a-z])([A-Z])`).ReplaceAllString(sysname, `${1}_$2`)
|
|
||||||
sysname = strings.ToUpper(sysname)
|
|
||||||
}
|
|
||||||
|
|
||||||
var libcFn string
|
|
||||||
if libc {
|
|
||||||
asm = "syscall_" + strings.ToLower(asm[:1]) + asm[1:] // internal syscall call
|
|
||||||
sysname = strings.TrimPrefix(sysname, "SYS_") // remove SYS_
|
|
||||||
sysname = strings.ToLower(sysname) // lowercase
|
|
||||||
libcFn = sysname
|
|
||||||
sysname = "funcPC(libc_" + sysname + "_trampoline)"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actual call.
|
|
||||||
arglist := strings.Join(args, ", ")
|
|
||||||
call := fmt.Sprintf("%s(%s, %s)", asm, sysname, arglist)
|
|
||||||
|
|
||||||
// Assign return values.
|
|
||||||
body := ""
|
|
||||||
ret := []string{"_", "_", "_"}
|
|
||||||
doErrno := false
|
|
||||||
for i := 0; i < len(out); i++ {
|
|
||||||
p := parseParam(out[i])
|
|
||||||
reg := ""
|
|
||||||
if p.Name == "err" && !*plan9 {
|
|
||||||
reg = "e1"
|
|
||||||
ret[2] = reg
|
|
||||||
doErrno = true
|
|
||||||
} else if p.Name == "err" && *plan9 {
|
|
||||||
ret[0] = "r0"
|
|
||||||
ret[2] = "e1"
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
reg = fmt.Sprintf("r%d", i)
|
|
||||||
ret[i] = reg
|
|
||||||
}
|
|
||||||
if p.Type == "bool" {
|
|
||||||
reg = fmt.Sprintf("%s != 0", reg)
|
|
||||||
}
|
|
||||||
if p.Type == "int64" && endianness != "" {
|
|
||||||
// 64-bit number in r1:r0 or r0:r1.
|
|
||||||
if i+2 > len(out) {
|
|
||||||
fmt.Fprintf(os.Stderr, "%s:%s not enough registers for int64 return\n", path, funct)
|
|
||||||
}
|
|
||||||
if endianness == "big-endian" {
|
|
||||||
reg = fmt.Sprintf("int64(r%d)<<32 | int64(r%d)", i, i+1)
|
|
||||||
} else {
|
|
||||||
reg = fmt.Sprintf("int64(r%d)<<32 | int64(r%d)", i+1, i)
|
|
||||||
}
|
|
||||||
ret[i] = fmt.Sprintf("r%d", i)
|
|
||||||
ret[i+1] = fmt.Sprintf("r%d", i+1)
|
|
||||||
}
|
|
||||||
if reg != "e1" || *plan9 {
|
|
||||||
body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ret[0] == "_" && ret[1] == "_" && ret[2] == "_" {
|
|
||||||
text += fmt.Sprintf("\t%s\n", call)
|
|
||||||
} else {
|
|
||||||
if errvar == "" && goos == "linux" {
|
|
||||||
// raw syscall without error on Linux, see golang.org/issue/22924
|
|
||||||
text += fmt.Sprintf("\t%s, %s := %s\n", ret[0], ret[1], call)
|
|
||||||
} else {
|
|
||||||
text += fmt.Sprintf("\t%s, %s, %s := %s\n", ret[0], ret[1], ret[2], call)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
text += body
|
|
||||||
|
|
||||||
if *plan9 && ret[2] == "e1" {
|
|
||||||
text += "\tif int32(r0) == -1 {\n"
|
|
||||||
text += "\t\terr = e1\n"
|
|
||||||
text += "\t}\n"
|
|
||||||
} else if doErrno {
|
|
||||||
text += "\tif e1 != 0 {\n"
|
|
||||||
text += "\t\terr = errnoErr(e1)\n"
|
|
||||||
text += "\t}\n"
|
|
||||||
}
|
|
||||||
text += "\treturn\n"
|
|
||||||
text += "}\n\n"
|
|
||||||
|
|
||||||
if libc && !trampolines[libcFn] {
|
|
||||||
// some system calls share a trampoline, like read and readlen.
|
|
||||||
trampolines[libcFn] = true
|
|
||||||
// Declare assembly trampoline.
|
|
||||||
text += fmt.Sprintf("func libc_%s_trampoline()\n", libcFn)
|
|
||||||
// Assembly trampoline calls the libc_* function, which this magic
|
|
||||||
// redirects to use the function from libSystem.
|
|
||||||
text += fmt.Sprintf("//go:linkname libc_%s libc_%s\n", libcFn, libcFn)
|
|
||||||
text += fmt.Sprintf("//go:cgo_import_dynamic libc_%s %s \"/usr/lib/libSystem.B.dylib\"\n", libcFn, libcFn)
|
|
||||||
text += "\n"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := s.Err(); err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
file.Close()
|
|
||||||
}
|
|
||||||
fmt.Printf(srcTemplate, cmdLine(), buildTags(), text)
|
|
||||||
}
|
|
||||||
|
|
||||||
const srcTemplate = `// %s
|
|
||||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
|
||||||
|
|
||||||
// +build %s
|
|
||||||
|
|
||||||
package unix
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ syscall.Errno
|
|
||||||
|
|
||||||
%s
|
|
||||||
`
|
|
415
vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.go
generated
vendored
415
vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.go
generated
vendored
@ -1,415 +0,0 @@
|
|||||||
// Copyright 2019 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 ignore
|
|
||||||
|
|
||||||
/*
|
|
||||||
This program reads a file containing function prototypes
|
|
||||||
(like syscall_aix.go) and generates system call bodies.
|
|
||||||
The prototypes are marked by lines beginning with "//sys"
|
|
||||||
and read like func declarations if //sys is replaced by func, but:
|
|
||||||
* The parameter lists must give a name for each argument.
|
|
||||||
This includes return parameters.
|
|
||||||
* The parameter lists must give a type for each argument:
|
|
||||||
the (x, y, z int) shorthand is not allowed.
|
|
||||||
* If the return parameter is an error number, it must be named err.
|
|
||||||
* If go func name needs to be different than its libc name,
|
|
||||||
* or the function is not in libc, name could be specified
|
|
||||||
* at the end, after "=" sign, like
|
|
||||||
//sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt
|
|
||||||
*/
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
b32 = flag.Bool("b32", false, "32bit big-endian")
|
|
||||||
l32 = flag.Bool("l32", false, "32bit little-endian")
|
|
||||||
aix = flag.Bool("aix", false, "aix")
|
|
||||||
tags = flag.String("tags", "", "build tags")
|
|
||||||
)
|
|
||||||
|
|
||||||
// cmdLine returns this programs's commandline arguments
|
|
||||||
func cmdLine() string {
|
|
||||||
return "go run mksyscall_aix_ppc.go " + strings.Join(os.Args[1:], " ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// buildTags returns build tags
|
|
||||||
func buildTags() string {
|
|
||||||
return *tags
|
|
||||||
}
|
|
||||||
|
|
||||||
// Param is function parameter
|
|
||||||
type Param struct {
|
|
||||||
Name string
|
|
||||||
Type string
|
|
||||||
}
|
|
||||||
|
|
||||||
// usage prints the program usage
|
|
||||||
func usage() {
|
|
||||||
fmt.Fprintf(os.Stderr, "usage: go run mksyscall_aix_ppc.go [-b32 | -l32] [-tags x,y] [file ...]\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseParamList parses parameter list and returns a slice of parameters
|
|
||||||
func parseParamList(list string) []string {
|
|
||||||
list = strings.TrimSpace(list)
|
|
||||||
if list == "" {
|
|
||||||
return []string{}
|
|
||||||
}
|
|
||||||
return regexp.MustCompile(`\s*,\s*`).Split(list, -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseParam splits a parameter into name and type
|
|
||||||
func parseParam(p string) Param {
|
|
||||||
ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p)
|
|
||||||
if ps == nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
return Param{ps[1], ps[2]}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Usage = usage
|
|
||||||
flag.Parse()
|
|
||||||
if len(flag.Args()) <= 0 {
|
|
||||||
fmt.Fprintf(os.Stderr, "no files to parse provided\n")
|
|
||||||
usage()
|
|
||||||
}
|
|
||||||
|
|
||||||
endianness := ""
|
|
||||||
if *b32 {
|
|
||||||
endianness = "big-endian"
|
|
||||||
} else if *l32 {
|
|
||||||
endianness = "little-endian"
|
|
||||||
}
|
|
||||||
|
|
||||||
pack := ""
|
|
||||||
text := ""
|
|
||||||
cExtern := "/*\n#include <stdint.h>\n#include <stddef.h>\n"
|
|
||||||
for _, path := range flag.Args() {
|
|
||||||
file, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
s := bufio.NewScanner(file)
|
|
||||||
for s.Scan() {
|
|
||||||
t := s.Text()
|
|
||||||
t = strings.TrimSpace(t)
|
|
||||||
t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `)
|
|
||||||
if p := regexp.MustCompile(`^package (\S+)$`).FindStringSubmatch(t); p != nil && pack == "" {
|
|
||||||
pack = p[1]
|
|
||||||
}
|
|
||||||
nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t)
|
|
||||||
if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Line must be of the form
|
|
||||||
// func Open(path string, mode int, perm int) (fd int, err error)
|
|
||||||
// Split into name, in params, out params.
|
|
||||||
f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$`).FindStringSubmatch(t)
|
|
||||||
if f == nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
funct, inps, outps, modname, sysname := f[2], f[3], f[4], f[5], f[6]
|
|
||||||
|
|
||||||
// Split argument lists on comma.
|
|
||||||
in := parseParamList(inps)
|
|
||||||
out := parseParamList(outps)
|
|
||||||
|
|
||||||
inps = strings.Join(in, ", ")
|
|
||||||
outps = strings.Join(out, ", ")
|
|
||||||
|
|
||||||
// Try in vain to keep people from editing this file.
|
|
||||||
// The theory is that they jump into the middle of the file
|
|
||||||
// without reading the header.
|
|
||||||
text += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
|
||||||
|
|
||||||
// Check if value return, err return available
|
|
||||||
errvar := ""
|
|
||||||
retvar := ""
|
|
||||||
rettype := ""
|
|
||||||
for _, param := range out {
|
|
||||||
p := parseParam(param)
|
|
||||||
if p.Type == "error" {
|
|
||||||
errvar = p.Name
|
|
||||||
} else {
|
|
||||||
retvar = p.Name
|
|
||||||
rettype = p.Type
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// System call name.
|
|
||||||
if sysname == "" {
|
|
||||||
sysname = funct
|
|
||||||
}
|
|
||||||
sysname = regexp.MustCompile(`([a-z])([A-Z])`).ReplaceAllString(sysname, `${1}_$2`)
|
|
||||||
sysname = strings.ToLower(sysname) // All libc functions are lowercase.
|
|
||||||
|
|
||||||
cRettype := ""
|
|
||||||
if rettype == "unsafe.Pointer" {
|
|
||||||
cRettype = "uintptr_t"
|
|
||||||
} else if rettype == "uintptr" {
|
|
||||||
cRettype = "uintptr_t"
|
|
||||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(rettype) != nil {
|
|
||||||
cRettype = "uintptr_t"
|
|
||||||
} else if rettype == "int" {
|
|
||||||
cRettype = "int"
|
|
||||||
} else if rettype == "int32" {
|
|
||||||
cRettype = "int"
|
|
||||||
} else if rettype == "int64" {
|
|
||||||
cRettype = "long long"
|
|
||||||
} else if rettype == "uint32" {
|
|
||||||
cRettype = "unsigned int"
|
|
||||||
} else if rettype == "uint64" {
|
|
||||||
cRettype = "unsigned long long"
|
|
||||||
} else {
|
|
||||||
cRettype = "int"
|
|
||||||
}
|
|
||||||
if sysname == "exit" {
|
|
||||||
cRettype = "void"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change p.Types to c
|
|
||||||
var cIn []string
|
|
||||||
for _, param := range in {
|
|
||||||
p := parseParam(param)
|
|
||||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
|
||||||
cIn = append(cIn, "uintptr_t")
|
|
||||||
} else if p.Type == "string" {
|
|
||||||
cIn = append(cIn, "uintptr_t")
|
|
||||||
} else if regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type) != nil {
|
|
||||||
cIn = append(cIn, "uintptr_t", "size_t")
|
|
||||||
} else if p.Type == "unsafe.Pointer" {
|
|
||||||
cIn = append(cIn, "uintptr_t")
|
|
||||||
} else if p.Type == "uintptr" {
|
|
||||||
cIn = append(cIn, "uintptr_t")
|
|
||||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil {
|
|
||||||
cIn = append(cIn, "uintptr_t")
|
|
||||||
} else if p.Type == "int" {
|
|
||||||
cIn = append(cIn, "int")
|
|
||||||
} else if p.Type == "int32" {
|
|
||||||
cIn = append(cIn, "int")
|
|
||||||
} else if p.Type == "int64" {
|
|
||||||
cIn = append(cIn, "long long")
|
|
||||||
} else if p.Type == "uint32" {
|
|
||||||
cIn = append(cIn, "unsigned int")
|
|
||||||
} else if p.Type == "uint64" {
|
|
||||||
cIn = append(cIn, "unsigned long long")
|
|
||||||
} else {
|
|
||||||
cIn = append(cIn, "int")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if funct != "fcntl" && funct != "FcntlInt" && funct != "readlen" && funct != "writelen" {
|
|
||||||
if sysname == "select" {
|
|
||||||
// select is a keyword of Go. Its name is
|
|
||||||
// changed to c_select.
|
|
||||||
cExtern += "#define c_select select\n"
|
|
||||||
}
|
|
||||||
// Imports of system calls from libc
|
|
||||||
cExtern += fmt.Sprintf("%s %s", cRettype, sysname)
|
|
||||||
cIn := strings.Join(cIn, ", ")
|
|
||||||
cExtern += fmt.Sprintf("(%s);\n", cIn)
|
|
||||||
}
|
|
||||||
|
|
||||||
// So file name.
|
|
||||||
if *aix {
|
|
||||||
if modname == "" {
|
|
||||||
modname = "libc.a/shr_64.o"
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(os.Stderr, "%s: only syscall using libc are available\n", funct)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
strconvfunc := "C.CString"
|
|
||||||
|
|
||||||
// Go function header.
|
|
||||||
if outps != "" {
|
|
||||||
outps = fmt.Sprintf(" (%s)", outps)
|
|
||||||
}
|
|
||||||
if text != "" {
|
|
||||||
text += "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
text += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outps)
|
|
||||||
|
|
||||||
// Prepare arguments to Syscall.
|
|
||||||
var args []string
|
|
||||||
n := 0
|
|
||||||
argN := 0
|
|
||||||
for _, param := range in {
|
|
||||||
p := parseParam(param)
|
|
||||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
|
||||||
args = append(args, "C.uintptr_t(uintptr(unsafe.Pointer("+p.Name+")))")
|
|
||||||
} else if p.Type == "string" && errvar != "" {
|
|
||||||
text += fmt.Sprintf("\t_p%d := uintptr(unsafe.Pointer(%s(%s)))\n", n, strconvfunc, p.Name)
|
|
||||||
args = append(args, fmt.Sprintf("C.uintptr_t(_p%d)", n))
|
|
||||||
n++
|
|
||||||
} else if p.Type == "string" {
|
|
||||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n")
|
|
||||||
text += fmt.Sprintf("\t_p%d := uintptr(unsafe.Pointer(%s(%s)))\n", n, strconvfunc, p.Name)
|
|
||||||
args = append(args, fmt.Sprintf("C.uintptr_t(_p%d)", n))
|
|
||||||
n++
|
|
||||||
} else if m := regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type); m != nil {
|
|
||||||
// Convert slice into pointer, length.
|
|
||||||
// Have to be careful not to take address of &a[0] if len == 0:
|
|
||||||
// pass nil in that case.
|
|
||||||
text += fmt.Sprintf("\tvar _p%d *%s\n", n, m[1])
|
|
||||||
text += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = &%s[0]\n\t}\n", p.Name, n, p.Name)
|
|
||||||
args = append(args, fmt.Sprintf("C.uintptr_t(uintptr(unsafe.Pointer(_p%d)))", n))
|
|
||||||
n++
|
|
||||||
text += fmt.Sprintf("\tvar _p%d int\n", n)
|
|
||||||
text += fmt.Sprintf("\t_p%d = len(%s)\n", n, p.Name)
|
|
||||||
args = append(args, fmt.Sprintf("C.size_t(_p%d)", n))
|
|
||||||
n++
|
|
||||||
} else if p.Type == "int64" && endianness != "" {
|
|
||||||
if endianness == "big-endian" {
|
|
||||||
args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
} else {
|
|
||||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name))
|
|
||||||
}
|
|
||||||
n++
|
|
||||||
} else if p.Type == "bool" {
|
|
||||||
text += fmt.Sprintf("\tvar _p%d uint32\n", n)
|
|
||||||
text += fmt.Sprintf("\tif %s {\n\t\t_p%d = 1\n\t} else {\n\t\t_p%d = 0\n\t}\n", p.Name, n, n)
|
|
||||||
args = append(args, fmt.Sprintf("_p%d", n))
|
|
||||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil {
|
|
||||||
args = append(args, fmt.Sprintf("C.uintptr_t(uintptr(%s))", p.Name))
|
|
||||||
} else if p.Type == "unsafe.Pointer" {
|
|
||||||
args = append(args, fmt.Sprintf("C.uintptr_t(uintptr(%s))", p.Name))
|
|
||||||
} else if p.Type == "int" {
|
|
||||||
if (argN == 2) && ((funct == "readlen") || (funct == "writelen")) {
|
|
||||||
args = append(args, fmt.Sprintf("C.size_t(%s)", p.Name))
|
|
||||||
} else if argN == 0 && funct == "fcntl" {
|
|
||||||
args = append(args, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
|
||||||
} else if (argN == 2) && ((funct == "fcntl") || (funct == "FcntlInt")) {
|
|
||||||
args = append(args, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
|
||||||
} else {
|
|
||||||
args = append(args, fmt.Sprintf("C.int(%s)", p.Name))
|
|
||||||
}
|
|
||||||
} else if p.Type == "int32" {
|
|
||||||
args = append(args, fmt.Sprintf("C.int(%s)", p.Name))
|
|
||||||
} else if p.Type == "int64" {
|
|
||||||
args = append(args, fmt.Sprintf("C.longlong(%s)", p.Name))
|
|
||||||
} else if p.Type == "uint32" {
|
|
||||||
args = append(args, fmt.Sprintf("C.uint(%s)", p.Name))
|
|
||||||
} else if p.Type == "uint64" {
|
|
||||||
args = append(args, fmt.Sprintf("C.ulonglong(%s)", p.Name))
|
|
||||||
} else if p.Type == "uintptr" {
|
|
||||||
args = append(args, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
|
||||||
} else {
|
|
||||||
args = append(args, fmt.Sprintf("C.int(%s)", p.Name))
|
|
||||||
}
|
|
||||||
argN++
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actual call.
|
|
||||||
arglist := strings.Join(args, ", ")
|
|
||||||
call := ""
|
|
||||||
if sysname == "exit" {
|
|
||||||
if errvar != "" {
|
|
||||||
call += "er :="
|
|
||||||
} else {
|
|
||||||
call += ""
|
|
||||||
}
|
|
||||||
} else if errvar != "" {
|
|
||||||
call += "r0,er :="
|
|
||||||
} else if retvar != "" {
|
|
||||||
call += "r0,_ :="
|
|
||||||
} else {
|
|
||||||
call += ""
|
|
||||||
}
|
|
||||||
if sysname == "select" {
|
|
||||||
// select is a keyword of Go. Its name is
|
|
||||||
// changed to c_select.
|
|
||||||
call += fmt.Sprintf("C.c_%s(%s)", sysname, arglist)
|
|
||||||
} else {
|
|
||||||
call += fmt.Sprintf("C.%s(%s)", sysname, arglist)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assign return values.
|
|
||||||
body := ""
|
|
||||||
for i := 0; i < len(out); i++ {
|
|
||||||
p := parseParam(out[i])
|
|
||||||
reg := ""
|
|
||||||
if p.Name == "err" {
|
|
||||||
reg = "e1"
|
|
||||||
} else {
|
|
||||||
reg = "r0"
|
|
||||||
}
|
|
||||||
if reg != "e1" {
|
|
||||||
body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// verify return
|
|
||||||
if sysname != "exit" && errvar != "" {
|
|
||||||
if regexp.MustCompile(`^uintptr`).FindStringSubmatch(cRettype) != nil {
|
|
||||||
body += "\tif (uintptr(r0) ==^uintptr(0) && er != nil) {\n"
|
|
||||||
body += fmt.Sprintf("\t\t%s = er\n", errvar)
|
|
||||||
body += "\t}\n"
|
|
||||||
} else {
|
|
||||||
body += "\tif (r0 ==-1 && er != nil) {\n"
|
|
||||||
body += fmt.Sprintf("\t\t%s = er\n", errvar)
|
|
||||||
body += "\t}\n"
|
|
||||||
}
|
|
||||||
} else if errvar != "" {
|
|
||||||
body += "\tif (er != nil) {\n"
|
|
||||||
body += fmt.Sprintf("\t\t%s = er\n", errvar)
|
|
||||||
body += "\t}\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
text += fmt.Sprintf("\t%s\n", call)
|
|
||||||
text += body
|
|
||||||
|
|
||||||
text += "\treturn\n"
|
|
||||||
text += "}\n"
|
|
||||||
}
|
|
||||||
if err := s.Err(); err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
file.Close()
|
|
||||||
}
|
|
||||||
imp := ""
|
|
||||||
if pack != "unix" {
|
|
||||||
imp = "import \"golang.org/x/sys/unix\"\n"
|
|
||||||
|
|
||||||
}
|
|
||||||
fmt.Printf(srcTemplate, cmdLine(), buildTags(), pack, cExtern, imp, text)
|
|
||||||
}
|
|
||||||
|
|
||||||
const srcTemplate = `// %s
|
|
||||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
|
||||||
|
|
||||||
// +build %s
|
|
||||||
|
|
||||||
package %s
|
|
||||||
|
|
||||||
|
|
||||||
%s
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import (
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
%s
|
|
||||||
|
|
||||||
%s
|
|
||||||
`
|
|
614
vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.go
generated
vendored
614
vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.go
generated
vendored
@ -1,614 +0,0 @@
|
|||||||
// Copyright 2019 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 ignore
|
|
||||||
|
|
||||||
/*
|
|
||||||
This program reads a file containing function prototypes
|
|
||||||
(like syscall_aix.go) and generates system call bodies.
|
|
||||||
The prototypes are marked by lines beginning with "//sys"
|
|
||||||
and read like func declarations if //sys is replaced by func, but:
|
|
||||||
* The parameter lists must give a name for each argument.
|
|
||||||
This includes return parameters.
|
|
||||||
* The parameter lists must give a type for each argument:
|
|
||||||
the (x, y, z int) shorthand is not allowed.
|
|
||||||
* If the return parameter is an error number, it must be named err.
|
|
||||||
* If go func name needs to be different than its libc name,
|
|
||||||
* or the function is not in libc, name could be specified
|
|
||||||
* at the end, after "=" sign, like
|
|
||||||
//sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt
|
|
||||||
|
|
||||||
|
|
||||||
This program will generate three files and handle both gc and gccgo implementation:
|
|
||||||
- zsyscall_aix_ppc64.go: the common part of each implementation (error handler, pointer creation)
|
|
||||||
- zsyscall_aix_ppc64_gc.go: gc part with //go_cgo_import_dynamic and a call to syscall6
|
|
||||||
- zsyscall_aix_ppc64_gccgo.go: gccgo part with C function and conversion to C type.
|
|
||||||
|
|
||||||
The generated code looks like this
|
|
||||||
|
|
||||||
zsyscall_aix_ppc64.go
|
|
||||||
func asyscall(...) (n int, err error) {
|
|
||||||
// Pointer Creation
|
|
||||||
r1, e1 := callasyscall(...)
|
|
||||||
// Type Conversion
|
|
||||||
// Error Handler
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
zsyscall_aix_ppc64_gc.go
|
|
||||||
//go:cgo_import_dynamic libc_asyscall asyscall "libc.a/shr_64.o"
|
|
||||||
//go:linkname libc_asyscall libc_asyscall
|
|
||||||
var asyscall syscallFunc
|
|
||||||
|
|
||||||
func callasyscall(...) (r1 uintptr, e1 Errno) {
|
|
||||||
r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_asyscall)), "nb_args", ... )
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
zsyscall_aix_ppc64_ggcgo.go
|
|
||||||
|
|
||||||
// int asyscall(...)
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
func callasyscall(...) (r1 uintptr, e1 Errno) {
|
|
||||||
r1 = uintptr(C.asyscall(...))
|
|
||||||
e1 = syscall.GetErrno()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
b32 = flag.Bool("b32", false, "32bit big-endian")
|
|
||||||
l32 = flag.Bool("l32", false, "32bit little-endian")
|
|
||||||
aix = flag.Bool("aix", false, "aix")
|
|
||||||
tags = flag.String("tags", "", "build tags")
|
|
||||||
)
|
|
||||||
|
|
||||||
// cmdLine returns this programs's commandline arguments
|
|
||||||
func cmdLine() string {
|
|
||||||
return "go run mksyscall_aix_ppc64.go " + strings.Join(os.Args[1:], " ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// buildTags returns build tags
|
|
||||||
func buildTags() string {
|
|
||||||
return *tags
|
|
||||||
}
|
|
||||||
|
|
||||||
// Param is function parameter
|
|
||||||
type Param struct {
|
|
||||||
Name string
|
|
||||||
Type string
|
|
||||||
}
|
|
||||||
|
|
||||||
// usage prints the program usage
|
|
||||||
func usage() {
|
|
||||||
fmt.Fprintf(os.Stderr, "usage: go run mksyscall_aix_ppc64.go [-b32 | -l32] [-tags x,y] [file ...]\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseParamList parses parameter list and returns a slice of parameters
|
|
||||||
func parseParamList(list string) []string {
|
|
||||||
list = strings.TrimSpace(list)
|
|
||||||
if list == "" {
|
|
||||||
return []string{}
|
|
||||||
}
|
|
||||||
return regexp.MustCompile(`\s*,\s*`).Split(list, -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseParam splits a parameter into name and type
|
|
||||||
func parseParam(p string) Param {
|
|
||||||
ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p)
|
|
||||||
if ps == nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
return Param{ps[1], ps[2]}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Usage = usage
|
|
||||||
flag.Parse()
|
|
||||||
if len(flag.Args()) <= 0 {
|
|
||||||
fmt.Fprintf(os.Stderr, "no files to parse provided\n")
|
|
||||||
usage()
|
|
||||||
}
|
|
||||||
|
|
||||||
endianness := ""
|
|
||||||
if *b32 {
|
|
||||||
endianness = "big-endian"
|
|
||||||
} else if *l32 {
|
|
||||||
endianness = "little-endian"
|
|
||||||
}
|
|
||||||
|
|
||||||
pack := ""
|
|
||||||
// GCCGO
|
|
||||||
textgccgo := ""
|
|
||||||
cExtern := "/*\n#include <stdint.h>\n"
|
|
||||||
// GC
|
|
||||||
textgc := ""
|
|
||||||
dynimports := ""
|
|
||||||
linknames := ""
|
|
||||||
var vars []string
|
|
||||||
// COMMON
|
|
||||||
textcommon := ""
|
|
||||||
for _, path := range flag.Args() {
|
|
||||||
file, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
s := bufio.NewScanner(file)
|
|
||||||
for s.Scan() {
|
|
||||||
t := s.Text()
|
|
||||||
t = strings.TrimSpace(t)
|
|
||||||
t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `)
|
|
||||||
if p := regexp.MustCompile(`^package (\S+)$`).FindStringSubmatch(t); p != nil && pack == "" {
|
|
||||||
pack = p[1]
|
|
||||||
}
|
|
||||||
nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t)
|
|
||||||
if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Line must be of the form
|
|
||||||
// func Open(path string, mode int, perm int) (fd int, err error)
|
|
||||||
// Split into name, in params, out params.
|
|
||||||
f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$`).FindStringSubmatch(t)
|
|
||||||
if f == nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
funct, inps, outps, modname, sysname := f[2], f[3], f[4], f[5], f[6]
|
|
||||||
|
|
||||||
// Split argument lists on comma.
|
|
||||||
in := parseParamList(inps)
|
|
||||||
out := parseParamList(outps)
|
|
||||||
|
|
||||||
inps = strings.Join(in, ", ")
|
|
||||||
outps = strings.Join(out, ", ")
|
|
||||||
|
|
||||||
if sysname == "" {
|
|
||||||
sysname = funct
|
|
||||||
}
|
|
||||||
|
|
||||||
onlyCommon := false
|
|
||||||
if funct == "readlen" || funct == "writelen" || funct == "FcntlInt" || funct == "FcntlFlock" {
|
|
||||||
// This function call another syscall which is already implemented.
|
|
||||||
// Therefore, the gc and gccgo part must not be generated.
|
|
||||||
onlyCommon = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try in vain to keep people from editing this file.
|
|
||||||
// The theory is that they jump into the middle of the file
|
|
||||||
// without reading the header.
|
|
||||||
|
|
||||||
textcommon += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
|
||||||
if !onlyCommon {
|
|
||||||
textgccgo += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
|
||||||
textgc += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if value return, err return available
|
|
||||||
errvar := ""
|
|
||||||
rettype := ""
|
|
||||||
for _, param := range out {
|
|
||||||
p := parseParam(param)
|
|
||||||
if p.Type == "error" {
|
|
||||||
errvar = p.Name
|
|
||||||
} else {
|
|
||||||
rettype = p.Type
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sysname = regexp.MustCompile(`([a-z])([A-Z])`).ReplaceAllString(sysname, `${1}_$2`)
|
|
||||||
sysname = strings.ToLower(sysname) // All libc functions are lowercase.
|
|
||||||
|
|
||||||
// GCCGO Prototype return type
|
|
||||||
cRettype := ""
|
|
||||||
if rettype == "unsafe.Pointer" {
|
|
||||||
cRettype = "uintptr_t"
|
|
||||||
} else if rettype == "uintptr" {
|
|
||||||
cRettype = "uintptr_t"
|
|
||||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(rettype) != nil {
|
|
||||||
cRettype = "uintptr_t"
|
|
||||||
} else if rettype == "int" {
|
|
||||||
cRettype = "int"
|
|
||||||
} else if rettype == "int32" {
|
|
||||||
cRettype = "int"
|
|
||||||
} else if rettype == "int64" {
|
|
||||||
cRettype = "long long"
|
|
||||||
} else if rettype == "uint32" {
|
|
||||||
cRettype = "unsigned int"
|
|
||||||
} else if rettype == "uint64" {
|
|
||||||
cRettype = "unsigned long long"
|
|
||||||
} else {
|
|
||||||
cRettype = "int"
|
|
||||||
}
|
|
||||||
if sysname == "exit" {
|
|
||||||
cRettype = "void"
|
|
||||||
}
|
|
||||||
|
|
||||||
// GCCGO Prototype arguments type
|
|
||||||
var cIn []string
|
|
||||||
for i, param := range in {
|
|
||||||
p := parseParam(param)
|
|
||||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
|
||||||
cIn = append(cIn, "uintptr_t")
|
|
||||||
} else if p.Type == "string" {
|
|
||||||
cIn = append(cIn, "uintptr_t")
|
|
||||||
} else if regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type) != nil {
|
|
||||||
cIn = append(cIn, "uintptr_t", "size_t")
|
|
||||||
} else if p.Type == "unsafe.Pointer" {
|
|
||||||
cIn = append(cIn, "uintptr_t")
|
|
||||||
} else if p.Type == "uintptr" {
|
|
||||||
cIn = append(cIn, "uintptr_t")
|
|
||||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil {
|
|
||||||
cIn = append(cIn, "uintptr_t")
|
|
||||||
} else if p.Type == "int" {
|
|
||||||
if (i == 0 || i == 2) && funct == "fcntl" {
|
|
||||||
// These fcntl arguments needs to be uintptr to be able to call FcntlInt and FcntlFlock
|
|
||||||
cIn = append(cIn, "uintptr_t")
|
|
||||||
} else {
|
|
||||||
cIn = append(cIn, "int")
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if p.Type == "int32" {
|
|
||||||
cIn = append(cIn, "int")
|
|
||||||
} else if p.Type == "int64" {
|
|
||||||
cIn = append(cIn, "long long")
|
|
||||||
} else if p.Type == "uint32" {
|
|
||||||
cIn = append(cIn, "unsigned int")
|
|
||||||
} else if p.Type == "uint64" {
|
|
||||||
cIn = append(cIn, "unsigned long long")
|
|
||||||
} else {
|
|
||||||
cIn = append(cIn, "int")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !onlyCommon {
|
|
||||||
// GCCGO Prototype Generation
|
|
||||||
// Imports of system calls from libc
|
|
||||||
if sysname == "select" {
|
|
||||||
// select is a keyword of Go. Its name is
|
|
||||||
// changed to c_select.
|
|
||||||
cExtern += "#define c_select select\n"
|
|
||||||
}
|
|
||||||
cExtern += fmt.Sprintf("%s %s", cRettype, sysname)
|
|
||||||
cIn := strings.Join(cIn, ", ")
|
|
||||||
cExtern += fmt.Sprintf("(%s);\n", cIn)
|
|
||||||
}
|
|
||||||
// GC Library name
|
|
||||||
if modname == "" {
|
|
||||||
modname = "libc.a/shr_64.o"
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(os.Stderr, "%s: only syscall using libc are available\n", funct)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
sysvarname := fmt.Sprintf("libc_%s", sysname)
|
|
||||||
|
|
||||||
if !onlyCommon {
|
|
||||||
// GC Runtime import of function to allow cross-platform builds.
|
|
||||||
dynimports += fmt.Sprintf("//go:cgo_import_dynamic %s %s \"%s\"\n", sysvarname, sysname, modname)
|
|
||||||
// GC Link symbol to proc address variable.
|
|
||||||
linknames += fmt.Sprintf("//go:linkname %s %s\n", sysvarname, sysvarname)
|
|
||||||
// GC Library proc address variable.
|
|
||||||
vars = append(vars, sysvarname)
|
|
||||||
}
|
|
||||||
|
|
||||||
strconvfunc := "BytePtrFromString"
|
|
||||||
strconvtype := "*byte"
|
|
||||||
|
|
||||||
// Go function header.
|
|
||||||
if outps != "" {
|
|
||||||
outps = fmt.Sprintf(" (%s)", outps)
|
|
||||||
}
|
|
||||||
if textcommon != "" {
|
|
||||||
textcommon += "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
textcommon += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outps)
|
|
||||||
|
|
||||||
// Prepare arguments tocall.
|
|
||||||
var argscommon []string // Arguments in the common part
|
|
||||||
var argscall []string // Arguments for call prototype
|
|
||||||
var argsgc []string // Arguments for gc call (with syscall6)
|
|
||||||
var argsgccgo []string // Arguments for gccgo call (with C.name_of_syscall)
|
|
||||||
n := 0
|
|
||||||
argN := 0
|
|
||||||
for _, param := range in {
|
|
||||||
p := parseParam(param)
|
|
||||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
|
||||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(%s))", p.Name))
|
|
||||||
argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
|
|
||||||
argsgc = append(argsgc, p.Name)
|
|
||||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
|
||||||
} else if p.Type == "string" && errvar != "" {
|
|
||||||
textcommon += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype)
|
|
||||||
textcommon += fmt.Sprintf("\t_p%d, %s = %s(%s)\n", n, errvar, strconvfunc, p.Name)
|
|
||||||
textcommon += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar)
|
|
||||||
|
|
||||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
|
||||||
argscall = append(argscall, fmt.Sprintf("_p%d uintptr ", n))
|
|
||||||
argsgc = append(argsgc, fmt.Sprintf("_p%d", n))
|
|
||||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n))
|
|
||||||
n++
|
|
||||||
} else if p.Type == "string" {
|
|
||||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n")
|
|
||||||
textcommon += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype)
|
|
||||||
textcommon += fmt.Sprintf("\t_p%d, %s = %s(%s)\n", n, errvar, strconvfunc, p.Name)
|
|
||||||
textcommon += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar)
|
|
||||||
|
|
||||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
|
||||||
argscall = append(argscall, fmt.Sprintf("_p%d uintptr", n))
|
|
||||||
argsgc = append(argsgc, fmt.Sprintf("_p%d", n))
|
|
||||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n))
|
|
||||||
n++
|
|
||||||
} else if m := regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type); m != nil {
|
|
||||||
// Convert slice into pointer, length.
|
|
||||||
// Have to be careful not to take address of &a[0] if len == 0:
|
|
||||||
// pass nil in that case.
|
|
||||||
textcommon += fmt.Sprintf("\tvar _p%d *%s\n", n, m[1])
|
|
||||||
textcommon += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = &%s[0]\n\t}\n", p.Name, n, p.Name)
|
|
||||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n), fmt.Sprintf("len(%s)", p.Name))
|
|
||||||
argscall = append(argscall, fmt.Sprintf("_p%d uintptr", n), fmt.Sprintf("_lenp%d int", n))
|
|
||||||
argsgc = append(argsgc, fmt.Sprintf("_p%d", n), fmt.Sprintf("uintptr(_lenp%d)", n))
|
|
||||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n), fmt.Sprintf("C.size_t(_lenp%d)", n))
|
|
||||||
n++
|
|
||||||
} else if p.Type == "int64" && endianness != "" {
|
|
||||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses int64 with 32 bits mode. Case not yet implemented\n")
|
|
||||||
} else if p.Type == "bool" {
|
|
||||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses bool. Case not yet implemented\n")
|
|
||||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil || p.Type == "unsafe.Pointer" {
|
|
||||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
|
|
||||||
argsgc = append(argsgc, p.Name)
|
|
||||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
|
||||||
} else if p.Type == "int" {
|
|
||||||
if (argN == 0 || argN == 2) && ((funct == "fcntl") || (funct == "FcntlInt") || (funct == "FcntlFlock")) {
|
|
||||||
// These fcntl arguments need to be uintptr to be able to call FcntlInt and FcntlFlock
|
|
||||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
|
|
||||||
argsgc = append(argsgc, p.Name)
|
|
||||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
|
||||||
|
|
||||||
} else {
|
|
||||||
argscommon = append(argscommon, p.Name)
|
|
||||||
argscall = append(argscall, fmt.Sprintf("%s int", p.Name))
|
|
||||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name))
|
|
||||||
}
|
|
||||||
} else if p.Type == "int32" {
|
|
||||||
argscommon = append(argscommon, p.Name)
|
|
||||||
argscall = append(argscall, fmt.Sprintf("%s int32", p.Name))
|
|
||||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name))
|
|
||||||
} else if p.Type == "int64" {
|
|
||||||
argscommon = append(argscommon, p.Name)
|
|
||||||
argscall = append(argscall, fmt.Sprintf("%s int64", p.Name))
|
|
||||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.longlong(%s)", p.Name))
|
|
||||||
} else if p.Type == "uint32" {
|
|
||||||
argscommon = append(argscommon, p.Name)
|
|
||||||
argscall = append(argscall, fmt.Sprintf("%s uint32", p.Name))
|
|
||||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uint(%s)", p.Name))
|
|
||||||
} else if p.Type == "uint64" {
|
|
||||||
argscommon = append(argscommon, p.Name)
|
|
||||||
argscall = append(argscall, fmt.Sprintf("%s uint64", p.Name))
|
|
||||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.ulonglong(%s)", p.Name))
|
|
||||||
} else if p.Type == "uintptr" {
|
|
||||||
argscommon = append(argscommon, p.Name)
|
|
||||||
argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
|
|
||||||
argsgc = append(argsgc, p.Name)
|
|
||||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
|
||||||
} else {
|
|
||||||
argscommon = append(argscommon, fmt.Sprintf("int(%s)", p.Name))
|
|
||||||
argscall = append(argscall, fmt.Sprintf("%s int", p.Name))
|
|
||||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
|
||||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name))
|
|
||||||
}
|
|
||||||
argN++
|
|
||||||
}
|
|
||||||
nargs := len(argsgc)
|
|
||||||
|
|
||||||
// COMMON function generation
|
|
||||||
argscommonlist := strings.Join(argscommon, ", ")
|
|
||||||
callcommon := fmt.Sprintf("call%s(%s)", sysname, argscommonlist)
|
|
||||||
ret := []string{"_", "_"}
|
|
||||||
body := ""
|
|
||||||
doErrno := false
|
|
||||||
for i := 0; i < len(out); i++ {
|
|
||||||
p := parseParam(out[i])
|
|
||||||
reg := ""
|
|
||||||
if p.Name == "err" {
|
|
||||||
reg = "e1"
|
|
||||||
ret[1] = reg
|
|
||||||
doErrno = true
|
|
||||||
} else {
|
|
||||||
reg = "r0"
|
|
||||||
ret[0] = reg
|
|
||||||
}
|
|
||||||
if p.Type == "bool" {
|
|
||||||
reg = fmt.Sprintf("%s != 0", reg)
|
|
||||||
}
|
|
||||||
if reg != "e1" {
|
|
||||||
body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ret[0] == "_" && ret[1] == "_" {
|
|
||||||
textcommon += fmt.Sprintf("\t%s\n", callcommon)
|
|
||||||
} else {
|
|
||||||
textcommon += fmt.Sprintf("\t%s, %s := %s\n", ret[0], ret[1], callcommon)
|
|
||||||
}
|
|
||||||
textcommon += body
|
|
||||||
|
|
||||||
if doErrno {
|
|
||||||
textcommon += "\tif e1 != 0 {\n"
|
|
||||||
textcommon += "\t\terr = errnoErr(e1)\n"
|
|
||||||
textcommon += "\t}\n"
|
|
||||||
}
|
|
||||||
textcommon += "\treturn\n"
|
|
||||||
textcommon += "}\n"
|
|
||||||
|
|
||||||
if onlyCommon {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// CALL Prototype
|
|
||||||
callProto := fmt.Sprintf("func call%s(%s) (r1 uintptr, e1 Errno) {\n", sysname, strings.Join(argscall, ", "))
|
|
||||||
|
|
||||||
// GC function generation
|
|
||||||
asm := "syscall6"
|
|
||||||
if nonblock != nil {
|
|
||||||
asm = "rawSyscall6"
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(argsgc) <= 6 {
|
|
||||||
for len(argsgc) < 6 {
|
|
||||||
argsgc = append(argsgc, "0")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(os.Stderr, "%s: too many arguments to system call", funct)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
argsgclist := strings.Join(argsgc, ", ")
|
|
||||||
callgc := fmt.Sprintf("%s(uintptr(unsafe.Pointer(&%s)), %d, %s)", asm, sysvarname, nargs, argsgclist)
|
|
||||||
|
|
||||||
textgc += callProto
|
|
||||||
textgc += fmt.Sprintf("\tr1, _, e1 = %s\n", callgc)
|
|
||||||
textgc += "\treturn\n}\n"
|
|
||||||
|
|
||||||
// GCCGO function generation
|
|
||||||
argsgccgolist := strings.Join(argsgccgo, ", ")
|
|
||||||
var callgccgo string
|
|
||||||
if sysname == "select" {
|
|
||||||
// select is a keyword of Go. Its name is
|
|
||||||
// changed to c_select.
|
|
||||||
callgccgo = fmt.Sprintf("C.c_%s(%s)", sysname, argsgccgolist)
|
|
||||||
} else {
|
|
||||||
callgccgo = fmt.Sprintf("C.%s(%s)", sysname, argsgccgolist)
|
|
||||||
}
|
|
||||||
textgccgo += callProto
|
|
||||||
textgccgo += fmt.Sprintf("\tr1 = uintptr(%s)\n", callgccgo)
|
|
||||||
textgccgo += "\te1 = syscall.GetErrno()\n"
|
|
||||||
textgccgo += "\treturn\n}\n"
|
|
||||||
}
|
|
||||||
if err := s.Err(); err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
file.Close()
|
|
||||||
}
|
|
||||||
imp := ""
|
|
||||||
if pack != "unix" {
|
|
||||||
imp = "import \"golang.org/x/sys/unix\"\n"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print zsyscall_aix_ppc64.go
|
|
||||||
err := ioutil.WriteFile("zsyscall_aix_ppc64.go",
|
|
||||||
[]byte(fmt.Sprintf(srcTemplate1, cmdLine(), buildTags(), pack, imp, textcommon)),
|
|
||||||
0644)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print zsyscall_aix_ppc64_gc.go
|
|
||||||
vardecls := "\t" + strings.Join(vars, ",\n\t")
|
|
||||||
vardecls += " syscallFunc"
|
|
||||||
err = ioutil.WriteFile("zsyscall_aix_ppc64_gc.go",
|
|
||||||
[]byte(fmt.Sprintf(srcTemplate2, cmdLine(), buildTags(), pack, imp, dynimports, linknames, vardecls, textgc)),
|
|
||||||
0644)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print zsyscall_aix_ppc64_gccgo.go
|
|
||||||
err = ioutil.WriteFile("zsyscall_aix_ppc64_gccgo.go",
|
|
||||||
[]byte(fmt.Sprintf(srcTemplate3, cmdLine(), buildTags(), pack, cExtern, imp, textgccgo)),
|
|
||||||
0644)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const srcTemplate1 = `// %s
|
|
||||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
|
||||||
|
|
||||||
// +build %s
|
|
||||||
|
|
||||||
package %s
|
|
||||||
|
|
||||||
import (
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
%s
|
|
||||||
|
|
||||||
%s
|
|
||||||
`
|
|
||||||
const srcTemplate2 = `// %s
|
|
||||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
|
||||||
|
|
||||||
// +build %s
|
|
||||||
// +build !gccgo
|
|
||||||
|
|
||||||
package %s
|
|
||||||
|
|
||||||
import (
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
%s
|
|
||||||
%s
|
|
||||||
%s
|
|
||||||
type syscallFunc uintptr
|
|
||||||
|
|
||||||
var (
|
|
||||||
%s
|
|
||||||
)
|
|
||||||
|
|
||||||
// Implemented in runtime/syscall_aix.go.
|
|
||||||
func rawSyscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
|
|
||||||
func syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
|
|
||||||
|
|
||||||
%s
|
|
||||||
`
|
|
||||||
const srcTemplate3 = `// %s
|
|
||||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
|
||||||
|
|
||||||
// +build %s
|
|
||||||
// +build gccgo
|
|
||||||
|
|
||||||
package %s
|
|
||||||
|
|
||||||
%s
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
%s
|
|
||||||
|
|
||||||
%s
|
|
||||||
`
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user