├── vendor ├── github.com │ ├── spf13 │ │ ├── pflag │ │ │ ├── .gitignore │ │ │ ├── .travis.yml │ │ │ ├── LICENSE │ │ │ ├── int.go │ │ │ ├── string.go │ │ │ ├── int64.go │ │ │ ├── int8.go │ │ │ ├── uint.go │ │ │ ├── count.go │ │ │ ├── golangflag.go │ │ │ ├── uint8.go │ │ │ ├── int16.go │ │ │ ├── int32.go │ │ │ ├── ip.go │ │ │ ├── uint16.go │ │ │ └── float64.go │ │ └── cobra │ │ │ ├── command_notwin.go │ │ │ ├── .mailmap │ │ │ ├── command_win.go │ │ │ ├── .travis.yml │ │ │ ├── .gitignore │ │ │ ├── args.go │ │ │ ├── cobra │ │ │ └── cmd │ │ │ │ └── license_mit.go │ │ │ └── zsh_completions.go │ ├── PuerkitoBio │ │ └── goquery │ │ │ ├── .gitattributes │ │ │ ├── .travis.yml │ │ │ ├── .gitignore │ │ │ ├── LICENSE │ │ │ ├── iteration.go │ │ │ ├── query.go │ │ │ └── expand.go │ ├── mholt │ │ └── archiver │ │ │ ├── .gitignore │ │ │ ├── .travis.yml │ │ │ ├── appveyor.yml │ │ │ ├── build.bash │ │ │ ├── LICENSE │ │ │ ├── targz.go │ │ │ ├── tarxz.go │ │ │ ├── tarbz2.go │ │ │ ├── rar.go │ │ │ ├── archiver.go │ │ │ └── README.md │ ├── ulikunitz │ │ └── xz │ │ │ ├── fox.xz │ │ │ ├── lzma │ │ │ ├── fox.lzma │ │ │ ├── breader.go │ │ │ ├── bytewriter.go │ │ │ ├── bitops.go │ │ │ ├── matchalgorithm.go │ │ │ ├── directcodec.go │ │ │ ├── prob.go │ │ │ ├── properties.go │ │ │ ├── operation.go │ │ │ └── reader.go │ │ │ ├── make-docs │ │ │ ├── .gitignore │ │ │ ├── internal │ │ │ └── hash │ │ │ │ ├── doc.go │ │ │ │ ├── roller.go │ │ │ │ └── rabin_karp.go │ │ │ ├── example.go │ │ │ ├── LICENSE │ │ │ ├── crc.go │ │ │ ├── bits.go │ │ │ ├── README.md │ │ │ ├── cmd │ │ │ └── gxz │ │ │ │ └── licenses.go │ │ │ └── lzmafilter.go │ ├── andybalholm │ │ └── cascadia │ │ │ ├── go.mod │ │ │ ├── .travis.yml │ │ │ ├── README.md │ │ │ └── LICENSE │ ├── nwaples │ │ └── rardecode │ │ │ ├── README.md │ │ │ ├── LICENSE │ │ │ ├── decode29_ppm.go │ │ │ └── bit_reader.go │ ├── pkg │ │ └── errors │ │ │ ├── .travis.yml │ │ │ ├── .gitignore │ │ │ ├── appveyor.yml │ │ │ ├── LICENSE │ │ │ └── README.md │ ├── dsnet │ │ └── compress │ │ │ ├── internal │ │ │ ├── gofuzz.go │ │ │ ├── debug.go │ │ │ ├── release.go │ │ │ └── prefix │ │ │ │ ├── encoder.go │ │ │ │ └── range.go │ │ │ ├── zfuzz.sh │ │ │ ├── bzip2 │ │ │ ├── fuzz_off.go │ │ │ ├── internal │ │ │ │ └── sais │ │ │ │ │ └── common.go │ │ │ ├── fuzz_on.go │ │ │ └── rle1.go │ │ │ ├── zbench.sh │ │ │ ├── .travis.yml │ │ │ ├── LICENSE.md │ │ │ ├── ztest.sh │ │ │ ├── zprof.sh │ │ │ └── api.go │ ├── dustin │ │ └── go-humanize │ │ │ ├── humanize.go │ │ │ ├── ordinals.go │ │ │ ├── ftoa.go │ │ │ ├── .travis.yml │ │ │ ├── big.go │ │ │ ├── commaf.go │ │ │ ├── LICENSE │ │ │ ├── comma.go │ │ │ ├── si.go │ │ │ └── bytes.go │ └── inconshreveable │ │ └── mousetrap │ │ ├── trap_others.go │ │ ├── LICENSE │ │ ├── README.md │ │ ├── trap_windows_1.4.go │ │ └── trap_windows.go └── golang.org │ └── x │ └── net │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── PATENTS │ ├── LICENSE │ └── html │ ├── atom │ └── atom.go │ └── const.go ├── main.go ├── utils ├── file.go └── env.go ├── .gitignore ├── engine ├── path.go ├── uninstall.go ├── localList.go ├── exec.go ├── remoteList.go ├── install.go └── configure.go ├── cmd ├── configure.go ├── ls.go ├── use.go ├── path.go ├── uninstall.go ├── exec.go ├── root.go ├── ls-remote.go └── install.go ├── domain ├── version.go └── config.go ├── CONTRIBUTING.md ├── LICENCE.md ├── README.md ├── Gopkg.toml └── Gopkg.lock /vendor/github.com/spf13/pflag/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | 3 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/.gitattributes: -------------------------------------------------------------------------------- 1 | testdata/* linguist-vendored 2 | -------------------------------------------------------------------------------- /vendor/github.com/mholt/archiver/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | _gitignore 3 | builds/ 4 | *.test 5 | cmd/archiver/archiver 6 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/shivakishore14/govm/cmd" 4 | 5 | func main() { 6 | cmd.Execute() 7 | } 8 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/fox.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivakishore14/govm/HEAD/vendor/github.com/ulikunitz/xz/fox.xz -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/command_notwin.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package cobra 4 | 5 | var preExecHookFn func(*Command) 6 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/lzma/fox.lzma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shivakishore14/govm/HEAD/vendor/github.com/ulikunitz/xz/lzma/fox.lzma -------------------------------------------------------------------------------- /vendor/github.com/andybalholm/cascadia/go.mod: -------------------------------------------------------------------------------- 1 | module "github.com/andybalholm/cascadia" 2 | 3 | require "golang.org/x/net" v0.0.0-20180218175443-cbe0f9307d01 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.mailmap: -------------------------------------------------------------------------------- 1 | Steve Francia 2 | Bjørn Erik Pedersen 3 | Fabiano Franz 4 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/make-docs: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -x 4 | pandoc -t html5 -f markdown -s --css=doc/md.css -o README.html README.md 5 | pandoc -t html5 -f markdown -s --css=doc/md.css -o TODO.html TODO.md 6 | -------------------------------------------------------------------------------- /vendor/github.com/nwaples/rardecode/README.md: -------------------------------------------------------------------------------- 1 | # rardecode 2 | [![GoDoc](https://godoc.org/github.com/nwaples/rardecode?status.svg)](https://godoc.org/github.com/nwaples/rardecode) 3 | 4 | A go package for reading RAR archives. 5 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go_import_path: github.com/pkg/errors 3 | go: 4 | - 1.4.3 5 | - 1.5.4 6 | - 1.6.2 7 | - 1.7.1 8 | - tip 9 | 10 | script: 11 | - go test -v ./... 12 | -------------------------------------------------------------------------------- /vendor/github.com/andybalholm/cascadia/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.3 5 | - 1.4 6 | 7 | install: 8 | - go get github.com/andybalholm/cascadia 9 | 10 | script: 11 | - go test -v 12 | 13 | notifications: 14 | email: false 15 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.1 5 | - 1.2.x 6 | - 1.3.x 7 | - 1.4.x 8 | - 1.5.x 9 | - 1.6.x 10 | - 1.7.x 11 | - 1.8.x 12 | - 1.9.x 13 | - "1.10.x" 14 | - tip 15 | 16 | -------------------------------------------------------------------------------- /utils/file.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import "os" 4 | 5 | func CreateDirIfNotPresent(dirName string) error{ 6 | if _, err := os.Stat(dirName); os.IsNotExist(err) { 7 | // Path does not exists 8 | return os.MkdirAll(dirName, os.ModePerm) 9 | } 10 | return nil 11 | } -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/.gitignore: -------------------------------------------------------------------------------- 1 | # editor temporary files 2 | *.sublime-* 3 | .DS_Store 4 | *.swp 5 | #*.*# 6 | tags 7 | 8 | # direnv config 9 | .env* 10 | 11 | # test binaries 12 | *.test 13 | 14 | # coverage and profilte outputs 15 | *.out 16 | 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.dll 4 | *.so 5 | *.dylib 6 | 7 | # Test binary, build with `go test -c` 8 | *.test 9 | 10 | # Output of the go coverage tool, specifically when used with LiteIDE 11 | *.out 12 | 13 | # temp dirs 14 | temp/ 15 | .idea/ 16 | .DS_Store -------------------------------------------------------------------------------- /vendor/github.com/dsnet/compress/internal/gofuzz.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016, Joe Tsai. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE.md file. 4 | 5 | // +build gofuzz 6 | 7 | package internal 8 | 9 | const ( 10 | Debug = true 11 | GoFuzz = true 12 | ) 13 | -------------------------------------------------------------------------------- /vendor/github.com/dsnet/compress/internal/debug.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Joe Tsai. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE.md file. 4 | 5 | // +build debug,!gofuzz 6 | 7 | package internal 8 | 9 | const ( 10 | Debug = true 11 | GoFuzz = false 12 | ) 13 | -------------------------------------------------------------------------------- /vendor/github.com/dustin/go-humanize/humanize.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package humanize converts boring ugly numbers to human-friendly strings and back. 3 | 4 | Durations can be turned into strings such as "3 days ago", numbers 5 | representing sizes like 82854982 into useful strings like, "83 MB" or 6 | "79 MiB" (whichever you prefer). 7 | */ 8 | package humanize 9 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.7.3 7 | - 1.8.1 8 | - tip 9 | 10 | matrix: 11 | allow_failures: 12 | - go: tip 13 | 14 | install: 15 | - go get github.com/golang/lint/golint 16 | - export PATH=$GOPATH/bin:$PATH 17 | - go install ./... 18 | 19 | script: 20 | - verify/all.sh -v 21 | - go test ./... 22 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/.gitignore: -------------------------------------------------------------------------------- 1 | # .gitignore 2 | 3 | TODO.html 4 | README.html 5 | 6 | lzma/writer.txt 7 | lzma/reader.txt 8 | 9 | cmd/gxz/gxz 10 | cmd/xb/xb 11 | 12 | # test executables 13 | *.test 14 | 15 | # profile files 16 | *.out 17 | 18 | # vim swap file 19 | .*.swp 20 | 21 | # executables on windows 22 | *.exe 23 | 24 | # default compression test file 25 | enwik8* 26 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /vendor/github.com/dsnet/compress/zfuzz.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2017, Joe Tsai. All rights reserved. 4 | # Use of this source code is governed by a BSD-style 5 | # license that can be found in the LICENSE.md file. 6 | 7 | # zfuzz wraps internal/tool/fuzz and is useful for fuzz testing each of 8 | # the implementations in this repository. 9 | cd $(dirname "${BASH_SOURCE[0]}")/internal/tool/fuzz 10 | ./fuzz.sh "$@" 11 | -------------------------------------------------------------------------------- /vendor/github.com/mholt/archiver/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.7.1 5 | 6 | env: 7 | - CGO_ENABLED=0 8 | 9 | install: 10 | - go get -t ./... 11 | - go get github.com/golang/lint/golint 12 | - go get github.com/gordonklaus/ineffassign 13 | 14 | script: 15 | - diff <(echo -n) <(gofmt -s -d .) 16 | - ineffassign . 17 | - go vet ./... 18 | - go test ./... 19 | 20 | after_script: 21 | - golint ./... 22 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/command_win.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package cobra 4 | 5 | import ( 6 | "os" 7 | "time" 8 | 9 | "github.com/inconshreveable/mousetrap" 10 | ) 11 | 12 | var preExecHookFn = preExecHook 13 | 14 | func preExecHook(c *Command) { 15 | if MousetrapHelpText != "" && mousetrap.StartedByExplorer() { 16 | c.Print(MousetrapHelpText) 17 | time.Sleep(5 * time.Second) 18 | os.Exit(1) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /vendor/github.com/andybalholm/cascadia/README.md: -------------------------------------------------------------------------------- 1 | # cascadia 2 | 3 | [![](https://travis-ci.org/andybalholm/cascadia.svg)](https://travis-ci.org/andybalholm/cascadia) 4 | 5 | The Cascadia package implements CSS selectors for use with the parse trees produced by the html package. 6 | 7 | To test CSS selectors without writing Go code, check out [cascadia](https://github.com/suntong/cascadia) the command line tool, a thin wrapper around this package. 8 | -------------------------------------------------------------------------------- /vendor/github.com/dsnet/compress/bzip2/fuzz_off.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016, Joe Tsai. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE.md file. 4 | 5 | // +build !gofuzz 6 | 7 | // This file exists to suppress fuzzing details from release builds. 8 | 9 | package bzip2 10 | 11 | type fuzzReader struct{} 12 | 13 | func (*fuzzReader) updateChecksum(int64, uint32) {} 14 | -------------------------------------------------------------------------------- /engine/path.go: -------------------------------------------------------------------------------- 1 | package engine 2 | 3 | import ( 4 | "github.com/shivakishore14/govm/domain" 5 | "os" 6 | "path/filepath" 7 | ) 8 | 9 | func Path(name string) (string, error) { 10 | config := domain.Config{} 11 | config.LoadConf() 12 | versionPath := filepath.Join(config.InstallationDir, name, "go") 13 | 14 | if _, err := os.Stat(versionPath); os.IsNotExist(err) { 15 | return "", domain.ErrVersionNotFound 16 | } 17 | 18 | return versionPath, nil 19 | } 20 | -------------------------------------------------------------------------------- /engine/uninstall.go: -------------------------------------------------------------------------------- 1 | package engine 2 | 3 | import ( 4 | "github.com/shivakishore14/govm/domain" 5 | "os" 6 | "path/filepath" 7 | ) 8 | 9 | func Uninstall(versionName string) error { 10 | config := domain.Config{} 11 | config.LoadConf() 12 | installedPath := filepath.Join(config.InstallationDir, versionName) 13 | if _, err := os.Stat(installedPath); err != nil { 14 | return domain.ErrVersionNotFound 15 | } 16 | return os.RemoveAll(installedPath) 17 | } 18 | -------------------------------------------------------------------------------- /cmd/configure.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/shivakishore14/govm/engine" 5 | "github.com/spf13/cobra" 6 | "log" 7 | ) 8 | 9 | var configureCmd = &cobra.Command{ 10 | Use: "configure", 11 | Short: "configure Govm", 12 | Long: `configure Govm with initial data and this is to be run as a part of installation`, 13 | Run: func(cmd *cobra.Command, args []string) { 14 | if err := engine.Configure(); err != nil { 15 | log.Println(err) 16 | } 17 | }, 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/dustin/go-humanize/ordinals.go: -------------------------------------------------------------------------------- 1 | package humanize 2 | 3 | import "strconv" 4 | 5 | // Ordinal gives you the input number in a rank/ordinal format. 6 | // 7 | // Ordinal(3) -> 3rd 8 | func Ordinal(x int) string { 9 | suffix := "th" 10 | switch x % 10 { 11 | case 1: 12 | if x%100 != 11 { 13 | suffix = "st" 14 | } 15 | case 2: 16 | if x%100 != 12 { 17 | suffix = "nd" 18 | } 19 | case 3: 20 | if x%100 != 13 { 21 | suffix = "rd" 22 | } 23 | } 24 | return strconv.Itoa(x) + suffix 25 | } 26 | -------------------------------------------------------------------------------- /cmd/ls.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "github.com/shivakishore14/govm/engine" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | var lsCmd = &cobra.Command{ 10 | Use: "ls", 11 | Short: "Display the versions installed", 12 | Long: `Display all the versions of Go installed`, 13 | Run: func(cmd *cobra.Command, args []string) { 14 | remoteVersions := engine.LocalList() 15 | //fmt.Println(remoteVersions) 16 | for _, x := range remoteVersions { 17 | fmt.Println(x.Name, x.DownloadLink) 18 | } 19 | }, 20 | } 21 | -------------------------------------------------------------------------------- /cmd/use.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "github.com/spf13/cobra" 6 | ) 7 | 8 | // Use command is to be called from script, 9 | // this serves as a warning for users and to display command info. 10 | var useCmd = &cobra.Command{ 11 | Use: "use", 12 | Short: "Lets you switch to another go version", 13 | Long: `Use command lets you switch between multiple go versions.`, 14 | Run: func(cmd *cobra.Command, args []string) { 15 | fmt.Println("please check configuration \n run `govm configure`") 16 | }, 17 | } 18 | -------------------------------------------------------------------------------- /vendor/github.com/dustin/go-humanize/ftoa.go: -------------------------------------------------------------------------------- 1 | package humanize 2 | 3 | import "strconv" 4 | 5 | func stripTrailingZeros(s string) string { 6 | offset := len(s) - 1 7 | for offset > 0 { 8 | if s[offset] == '.' { 9 | offset-- 10 | break 11 | } 12 | if s[offset] != '0' { 13 | break 14 | } 15 | offset-- 16 | } 17 | return s[:offset+1] 18 | } 19 | 20 | // Ftoa converts a float to a string with no trailing zeros. 21 | func Ftoa(num float64) string { 22 | return stripTrailingZeros(strconv.FormatFloat(num, 'f', 6, 64)) 23 | } 24 | -------------------------------------------------------------------------------- /domain/version.go: -------------------------------------------------------------------------------- 1 | package domain 2 | 3 | import "errors" 4 | 5 | type Version struct { 6 | Name string 7 | FileName string 8 | Kind string 9 | Os string 10 | Arch string 11 | Size string 12 | SHA1 string 13 | DownloadLink string 14 | } 15 | type Versions []Version 16 | func (v Version) IsEmpty() bool { 17 | if v.Name != "" && v.Size != "" && v.DownloadLink != "" { 18 | return false 19 | } 20 | return true 21 | } 22 | 23 | var ErrVersionNotFound = errors.New("version not found") 24 | -------------------------------------------------------------------------------- /vendor/github.com/dsnet/compress/zbench.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2017, Joe Tsai. All rights reserved. 4 | # Use of this source code is governed by a BSD-style 5 | # license that can be found in the LICENSE.md file. 6 | 7 | # zbench wraps internal/tool/bench and is useful for comparing benchmarks from 8 | # the implementations in this repository relative to other implementations. 9 | # 10 | # See internal/tool/bench/main.go for more details. 11 | cd $(dirname "${BASH_SOURCE[0]}")/internal/tool/bench 12 | go run $(go list -f '{{ join .GoFiles "\n" }}') "$@" 13 | -------------------------------------------------------------------------------- /vendor/github.com/dustin/go-humanize/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: go 3 | go: 4 | - 1.3.x 5 | - 1.5.x 6 | - 1.6.x 7 | - 1.7.x 8 | - 1.8.x 9 | - 1.9.x 10 | - master 11 | matrix: 12 | allow_failures: 13 | - go: master 14 | fast_finish: true 15 | install: 16 | - # Do nothing. This is needed to prevent default install action "go get -t -v ./..." from happening here (we want it to happen inside script step). 17 | script: 18 | - go get -t -v ./... 19 | - diff -u <(echo -n) <(gofmt -d -s .) 20 | - go tool vet . 21 | - go test -v -race ./... 22 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/internal/hash/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package hash provides rolling hashes. 7 | 8 | Rolling hashes have to be used for maintaining the positions of n-byte 9 | sequences in the dictionary buffer. 10 | 11 | The package provides currently the Rabin-Karp rolling hash and a Cyclic 12 | Polynomial hash. Both support the Hashes method to be used with an interface. 13 | */ 14 | package hash 15 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_others.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package mousetrap 4 | 5 | // StartedByExplorer returns true if the program was invoked by the user 6 | // double-clicking on the executable from explorer.exe 7 | // 8 | // It is conservative and returns false if any of the internal calls fail. 9 | // It does not guarantee that the program was run from a terminal. It only can tell you 10 | // whether it was launched from explorer.exe 11 | // 12 | // On non-Windows platforms, it always returns false. 13 | func StartedByExplorer() bool { 14 | return false 15 | } 16 | -------------------------------------------------------------------------------- /utils/env.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "github.com/pkg/errors" 5 | "os" 6 | ) 7 | 8 | var ErrorEnvNotSet = errors.New("env variable not found") 9 | 10 | func GetEnv(key string) (string, error) { 11 | value := os.Getenv(key) 12 | if value == "" { 13 | return "", ErrorEnvNotSet 14 | } 15 | return value, nil 16 | } 17 | 18 | func GetEnvWithDefault(key string, defaultValue string) string { 19 | value := os.Getenv(key) 20 | if value == "" { 21 | value = defaultValue 22 | } 23 | return value 24 | } 25 | func AddToPath(data string) { 26 | pathValue := os.Getenv("PATH") 27 | os.Setenv("PATH", data+":"+pathValue) 28 | } 29 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Alan Shreve 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | matrix: 4 | include: 5 | - go: 1.9.4 6 | - go: 1.10.0 7 | - go: tip 8 | allow_failures: 9 | - go: tip 10 | 11 | before_install: 12 | - mkdir -p bin 13 | - curl -Lso bin/shellcheck https://github.com/caarlos0/shellcheck-docker/releases/download/v0.4.3/shellcheck 14 | - chmod +x bin/shellcheck 15 | script: 16 | - PATH=$PATH:$PWD/bin go test -v ./... 17 | - go build 18 | - diff -u <(echo -n) <(gofmt -d -s .) 19 | - if [ -z $NOVET ]; then 20 | diff -u <(echo -n) <(go tool vet . 2>&1 | grep -vE 'ExampleCommand|bash_completions.*Fprint'); 21 | fi 22 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | # Vim files https://github.com/github/gitignore/blob/master/Global/Vim.gitignore 23 | # swap 24 | [._]*.s[a-w][a-z] 25 | [._]s[a-w][a-z] 26 | # session 27 | Session.vim 28 | # temporary 29 | .netrwhist 30 | *~ 31 | # auto-generated tag files 32 | tags 33 | 34 | *.exe 35 | 36 | cobra.test 37 | -------------------------------------------------------------------------------- /cmd/path.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "github.com/shivakishore14/govm/engine" 6 | "github.com/spf13/cobra" 7 | "log" 8 | "strings" 9 | ) 10 | 11 | var pathCmd = &cobra.Command{ 12 | Use: "path", 13 | Short: "finds the path of the go version", 14 | Long: `path command finds the path of the go verion given as argument`, 15 | Run: func(cmd *cobra.Command, args []string) { 16 | if len(args) == 0 { 17 | fmt.Println("Provide version") 18 | return 19 | } 20 | version := args[0] 21 | if !strings.HasPrefix(version, "go") { 22 | version = "go" + version 23 | } 24 | path, err := engine.Path(version) 25 | if err != nil { 26 | log.Println(err) 27 | return 28 | } 29 | fmt.Println("PATH:" +path) 30 | }, 31 | } 32 | -------------------------------------------------------------------------------- /cmd/uninstall.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "github.com/shivakishore14/govm/engine" 6 | "github.com/spf13/cobra" 7 | "strings" 8 | ) 9 | 10 | var uninstallCmd = &cobra.Command{ 11 | Use: "uninstall", 12 | Short: "Uninstall a golang version", 13 | Long: `Uninstalls Go given the version given`, 14 | Run: func(cmd *cobra.Command, args []string) { 15 | if len(args) == 0 { 16 | fmt.Println("please pecify a version to uninstall") 17 | return 18 | } 19 | version := args[0] 20 | if !strings.HasPrefix(version, "go") { 21 | version = "go" + version 22 | } 23 | if err := engine.Uninstall(version); err != nil { 24 | fmt.Println(err) 25 | return 26 | } 27 | 28 | fmt.Println("Successfuly removed ", args[0]) 29 | 30 | }, 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/dustin/go-humanize/big.go: -------------------------------------------------------------------------------- 1 | package humanize 2 | 3 | import ( 4 | "math/big" 5 | ) 6 | 7 | // order of magnitude (to a max order) 8 | func oomm(n, b *big.Int, maxmag int) (float64, int) { 9 | mag := 0 10 | m := &big.Int{} 11 | for n.Cmp(b) >= 0 { 12 | n.DivMod(n, b, m) 13 | mag++ 14 | if mag == maxmag && maxmag >= 0 { 15 | break 16 | } 17 | } 18 | return float64(n.Int64()) + (float64(m.Int64()) / float64(b.Int64())), mag 19 | } 20 | 21 | // total order of magnitude 22 | // (same as above, but with no upper limit) 23 | func oom(n, b *big.Int) (float64, int) { 24 | mag := 0 25 | m := &big.Int{} 26 | for n.Cmp(b) >= 0 { 27 | n.DivMod(n, b, m) 28 | mag++ 29 | } 30 | return float64(n.Int64()) + (float64(m.Int64()) / float64(b.Int64())), mag 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/mholt/archiver/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: "{build}" 2 | 3 | os: Windows Server 2012 R2 4 | 5 | clone_folder: c:\gopath\src\github.com\mholt\archiver 6 | 7 | environment: 8 | GOPATH: c:\gopath 9 | CGO_ENABLED: 0 10 | 11 | install: 12 | - rmdir c:\go /s /q 13 | - appveyor DownloadFile https://storage.googleapis.com/golang/go1.7.1.windows-amd64.zip 14 | - 7z x go1.7.1.windows-amd64.zip -y -oC:\ > NUL 15 | - go version 16 | - go env 17 | - go get -t ./... 18 | - go get github.com/golang/lint/golint 19 | - go get github.com/gordonklaus/ineffassign 20 | - set PATH=%GOPATH%\bin;%PATH% 21 | 22 | build: off 23 | 24 | test_script: 25 | - go vet ./... 26 | - go test ./... 27 | - ineffassign . 28 | 29 | after_test: 30 | - golint ./... 31 | 32 | deploy: off 33 | -------------------------------------------------------------------------------- /cmd/exec.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/shivakishore14/govm/engine" 5 | "github.com/spf13/cobra" 6 | "log" 7 | "strings" 8 | ) 9 | 10 | var execCmd = &cobra.Command{ 11 | Use: "exec", 12 | Short: "execute with version", 13 | Long: `execute the command with the version specified 14 | $ govm exec 1.10 go ... 15 | `, 16 | Run: func(cmd *cobra.Command, args []string) { 17 | // it should have version number and an extra arg 18 | if len(args) < 2 { 19 | log.Println("Not valid format \nUsage: `govm exec 1.10 go `") 20 | return 21 | } 22 | versionName := args[0] 23 | if !strings.HasPrefix(versionName, "go") { 24 | versionName = "go" + versionName 25 | } 26 | if err := engine.Exec(versionName, args[1:]); err != nil { 27 | log.Println(err) 28 | } 29 | }, 30 | } 31 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: build-{build}.{branch} 2 | 3 | clone_folder: C:\gopath\src\github.com\pkg\errors 4 | shallow_clone: true # for startup speed 5 | 6 | environment: 7 | GOPATH: C:\gopath 8 | 9 | platform: 10 | - x64 11 | 12 | # http://www.appveyor.com/docs/installed-software 13 | install: 14 | # some helpful output for debugging builds 15 | - go version 16 | - go env 17 | # pre-installed MinGW at C:\MinGW is 32bit only 18 | # but MSYS2 at C:\msys64 has mingw64 19 | - set PATH=C:\msys64\mingw64\bin;%PATH% 20 | - gcc --version 21 | - g++ --version 22 | 23 | build_script: 24 | - go install -v ./... 25 | 26 | test_script: 27 | - set PATH=C:\gopath\bin;%PATH% 28 | - go test -v ./... 29 | 30 | #artifacts: 31 | # - path: '%GOPATH%\bin\*.exe' 32 | deploy: off 33 | -------------------------------------------------------------------------------- /cmd/root.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "github.com/spf13/cobra" 6 | "os" 7 | ) 8 | 9 | var rootCmd = &cobra.Command{ 10 | Use: "govm", 11 | Short: "Govm is a version manager for golang", 12 | Long: `Govm is a Fast and Flexible Go Version Manager built with go`, 13 | Run: func(cmd *cobra.Command, args []string) { 14 | fmt.Println(args) 15 | }, 16 | } 17 | 18 | func Execute() { 19 | if err := rootCmd.Execute(); err != nil { 20 | fmt.Println(err) 21 | os.Exit(1) 22 | } 23 | } 24 | 25 | func init() { 26 | rootCmd.AddCommand(lsCmd) 27 | rootCmd.AddCommand(useCmd) 28 | rootCmd.AddCommand(pathCmd) 29 | rootCmd.AddCommand(execCmd) 30 | rootCmd.AddCommand(installCmd) 31 | rootCmd.AddCommand(lsRemoteCmd) 32 | rootCmd.AddCommand(uninstallCmd) 33 | rootCmd.AddCommand(configureCmd) 34 | } 35 | -------------------------------------------------------------------------------- /cmd/ls-remote.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "github.com/shivakishore14/govm/engine" 6 | "github.com/spf13/cobra" 7 | "os" 8 | ) 9 | 10 | var lsRemoteCmd = &cobra.Command{ 11 | Use: "ls-remote", 12 | Short: "Display all the versions available", 13 | Long: `Display all the versions of Go available for download`, 14 | Run: func(cmd *cobra.Command, args []string) { 15 | hostOs := os.Getenv("GOVMOS") 16 | hostArch := os.Getenv("GOVMARCH") 17 | fmt.Println(hostOs, hostArch) 18 | 19 | if hostOs == "" || hostArch == "" { 20 | fmt.Println("please check configuration \n run `govm configure`") 21 | return 22 | } 23 | 24 | remoteVersions := engine.RemoteList(hostOs, hostArch) 25 | //fmt.Println(remoteVersions) 26 | for _, x := range remoteVersions { 27 | fmt.Println(x.Name) 28 | } 29 | }, 30 | } 31 | -------------------------------------------------------------------------------- /vendor/github.com/dsnet/compress/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: go 3 | before_install: 4 | - curl -L https://github.com/google/brotli/archive/v1.0.2.tar.gz | tar -zxv 5 | - (cd brotli-1.0.2 && mkdir out && cd out && ../configure-cmake && make && sudo make install) 6 | - rm -rf brotli-1.0.2 7 | - curl -L https://github.com/facebook/zstd/archive/v1.3.2.tar.gz | tar -zxv 8 | - (cd zstd-1.3.2 && sudo make install) 9 | - rm -rf zstd-1.3.2 10 | - sudo ldconfig 11 | before_script: 12 | - go get github.com/golang/lint/golint 13 | - go get honnef.co/go/tools/cmd/staticcheck 14 | matrix: 15 | include: 16 | - go: 1.7.x 17 | script: go test -v -race ./... 18 | - go: 1.x 19 | script: ./ztest.sh 20 | - go: master 21 | script: go test -v -race ./... 22 | allow_failures: 23 | - go: master 24 | fast_finish: true 25 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/internal/hash/roller.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package hash 6 | 7 | // Roller provides an interface for rolling hashes. The hash value will become 8 | // valid after hash has been called Len times. 9 | type Roller interface { 10 | Len() int 11 | RollByte(x byte) uint64 12 | } 13 | 14 | // Hashes computes all hash values for the array p. Note that the state of the 15 | // roller is changed. 16 | func Hashes(r Roller, p []byte) []uint64 { 17 | n := r.Len() 18 | if len(p) < n { 19 | return nil 20 | } 21 | h := make([]uint64, len(p)-n+1) 22 | for i := 0; i < n-1; i++ { 23 | r.RollByte(p[i]) 24 | } 25 | for i := range h { 26 | h[i] = r.RollByte(p[i+n-1]) 27 | } 28 | return h 29 | } 30 | -------------------------------------------------------------------------------- /vendor/github.com/dsnet/compress/internal/release.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Joe Tsai. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE.md file. 4 | 5 | // +build !debug,!gofuzz 6 | 7 | package internal 8 | 9 | // Debug indicates whether the debug build tag was set. 10 | // 11 | // If set, programs may choose to print with more human-readable 12 | // debug information and also perform sanity checks that would otherwise be too 13 | // expensive to run in a release build. 14 | const Debug = false 15 | 16 | // GoFuzz indicates whether the gofuzz build tag was set. 17 | // 18 | // If set, programs may choose to disable certain checks (like checksums) that 19 | // would be nearly impossible for gofuzz to properly get right. 20 | // If GoFuzz is set, it implies that Debug is set as well. 21 | const GoFuzz = false 22 | -------------------------------------------------------------------------------- /engine/localList.go: -------------------------------------------------------------------------------- 1 | package engine 2 | 3 | import ( 4 | "github.com/shivakishore14/govm/domain" 5 | "github.com/shivakishore14/govm/utils" 6 | "io/ioutil" 7 | "log" 8 | "os" 9 | "strings" 10 | ) 11 | 12 | func LocalList() domain.Versions { 13 | config := domain.Config{} 14 | config.LoadConf() 15 | 16 | files, err := ioutil.ReadDir(config.InstallationDir) 17 | if err != nil { 18 | if os.IsNotExist(err) { 19 | if err := utils.CreateDirIfNotPresent(config.InstallationDir); err != nil { 20 | log.Fatal(err) 21 | } 22 | } else { 23 | log.Fatal(err) 24 | } 25 | } 26 | versions := domain.Versions{} 27 | for _, f := range files { 28 | if f.IsDir() { 29 | name := f.Name() 30 | if strings.HasPrefix(name, "go") { 31 | version := domain.Version{} 32 | version.Name = name 33 | versions = append(versions, version) 34 | } 35 | } 36 | } 37 | return versions 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/dustin/go-humanize/commaf.go: -------------------------------------------------------------------------------- 1 | // +build go1.6 2 | 3 | package humanize 4 | 5 | import ( 6 | "bytes" 7 | "math/big" 8 | "strings" 9 | ) 10 | 11 | // BigCommaf produces a string form of the given big.Float in base 10 12 | // with commas after every three orders of magnitude. 13 | func BigCommaf(v *big.Float) string { 14 | buf := &bytes.Buffer{} 15 | if v.Sign() < 0 { 16 | buf.Write([]byte{'-'}) 17 | v.Abs(v) 18 | } 19 | 20 | comma := []byte{','} 21 | 22 | parts := strings.Split(v.Text('f', -1), ".") 23 | pos := 0 24 | if len(parts[0])%3 != 0 { 25 | pos += len(parts[0]) % 3 26 | buf.WriteString(parts[0][:pos]) 27 | buf.Write(comma) 28 | } 29 | for ; pos < len(parts[0]); pos += 3 { 30 | buf.WriteString(parts[0][pos : pos+3]) 31 | buf.Write(comma) 32 | } 33 | buf.Truncate(buf.Len() - 1) 34 | 35 | if len(parts) > 1 { 36 | buf.Write([]byte{'.'}) 37 | buf.WriteString(parts[1]) 38 | } 39 | return buf.String() 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/README.md: -------------------------------------------------------------------------------- 1 | # mousetrap 2 | 3 | mousetrap is a tiny library that answers a single question. 4 | 5 | On a Windows machine, was the process invoked by someone double clicking on 6 | the executable file while browsing in explorer? 7 | 8 | ### Motivation 9 | 10 | Windows developers unfamiliar with command line tools will often "double-click" 11 | the executable for a tool. Because most CLI tools print the help and then exit 12 | when invoked without arguments, this is often very frustrating for those users. 13 | 14 | mousetrap provides a way to detect these invocations so that you can provide 15 | more helpful behavior and instructions on how to run the CLI tool. To see what 16 | this looks like, both from an organizational and a technical perspective, see 17 | https://inconshreveable.com/09-09-2014/sweat-the-small-stuff/ 18 | 19 | ### The interface 20 | 21 | The library exposes a single interface: 22 | 23 | func StartedByExplorer() (bool) 24 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to GoVM 2 | 3 | First, thank you so much for wanting to contribute! It means so much that you care enough to want to contribute. We appreciate every PR from the smallest of typos to the be biggest of features. 4 | We encourage new contributors. 5 | 6 | ## First time committing to a Go Repo? 7 | 8 | Contributing to a Go project for the first time can be confusing due to import statements requiring a very specific path on disk. 9 | 10 | Please take moment and read this fantastic post on how to easily work with Go repos. 11 | 12 | [https://splice.com/blog/contributing-open-source-git-repositories-go/](https://splice.com/blog/contributing-open-source-git-repositories-go/) 13 | 14 | ## Contributing to GoVM 15 | 16 | 1. Check [https://github.com/shivakishore14/govm/issues](https://github.com/shivakishore14/govm/issues) to make sure you're not working on a duplicate issue or PR. 17 | 2. if you have a feature or a fix in mind, Please open a issue then give a PR referencing that issue. 18 | -------------------------------------------------------------------------------- /domain/config.go: -------------------------------------------------------------------------------- 1 | package domain 2 | 3 | import ( 4 | "os/user" 5 | "path/filepath" 6 | "runtime" 7 | ) 8 | 9 | type Config struct { 10 | TempDir string 11 | InstallationDir string 12 | GovmHome string 13 | BashrcPath string 14 | ScriptPath string 15 | } 16 | 17 | func (c *Config) LoadConf() error { 18 | usr, err := user.Current() 19 | if err != nil { 20 | return err 21 | } 22 | bashFilename := ".bash_profile" 23 | if runtime.GOOS == "linux" { 24 | bashFilename = ".bashrc" 25 | } 26 | userHome := usr.HomeDir 27 | govmHome := filepath.Join(userHome, ".govm/") 28 | tempDir := filepath.Join(govmHome, "tmp/") 29 | installationDir := filepath.Join(govmHome, "installed/") 30 | bashrcPath := filepath.Join(userHome, bashFilename) 31 | scriptPath := filepath.Join(govmHome, "wrapper.sh") 32 | 33 | c.GovmHome = govmHome 34 | c.TempDir = tempDir 35 | c.InstallationDir = installationDir 36 | c.BashrcPath = bashrcPath 37 | c.ScriptPath = scriptPath 38 | return nil 39 | } 40 | -------------------------------------------------------------------------------- /LICENCE.md: -------------------------------------------------------------------------------- 1 | Copyright 2017 SHIVA S 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/lzma/breader.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package lzma 6 | 7 | import ( 8 | "errors" 9 | "io" 10 | ) 11 | 12 | // breader provides the ReadByte function for a Reader. It doesn't read 13 | // more data from the reader than absolutely necessary. 14 | type breader struct { 15 | io.Reader 16 | // helper slice to save allocations 17 | p []byte 18 | } 19 | 20 | // ByteReader converts an io.Reader into an io.ByteReader. 21 | func ByteReader(r io.Reader) io.ByteReader { 22 | br, ok := r.(io.ByteReader) 23 | if !ok { 24 | return &breader{r, make([]byte, 1)} 25 | } 26 | return br 27 | } 28 | 29 | // ReadByte read byte function. 30 | func (r *breader) ReadByte() (c byte, err error) { 31 | n, err := r.Reader.Read(r.p) 32 | if n < 1 { 33 | if err == nil { 34 | err = errors.New("breader.ReadByte: no data") 35 | } 36 | return 0, err 37 | } 38 | return r.p[0], nil 39 | } 40 | -------------------------------------------------------------------------------- /cmd/install.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "github.com/shivakishore14/govm/domain" 6 | "github.com/shivakishore14/govm/engine" 7 | "github.com/spf13/cobra" 8 | "os" 9 | "strings" 10 | ) 11 | 12 | var installCmd = &cobra.Command{ 13 | Use: "install", 14 | Short: "Install a golang version", 15 | Long: `Installs Go given the version to be installed`, 16 | Run: func(cmd *cobra.Command, args []string) { 17 | hostOs := os.Getenv("GOVMOS") 18 | hostArch := os.Getenv("GOVMARCH") 19 | if hostOs == "" || hostArch == "" { 20 | fmt.Println("please check configuration \n run `govm configure`") 21 | return 22 | } 23 | remoteVersions := engine.RemoteList(hostOs, hostArch) 24 | version := domain.Version{} 25 | 26 | versionName := args[0] 27 | if !strings.HasPrefix(versionName, "go") { 28 | versionName = "go" + versionName 29 | } 30 | for _, x := range remoteVersions { 31 | if versionName == x.Name { 32 | version = x 33 | } 34 | } 35 | if e := engine.Download(version); e != nil { 36 | fmt.Println(e) 37 | } 38 | }, 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/example.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ignore 6 | 7 | package main 8 | 9 | import ( 10 | "bytes" 11 | "io" 12 | "log" 13 | "os" 14 | 15 | "github.com/ulikunitz/xz" 16 | ) 17 | 18 | func main() { 19 | const text = "The quick brown fox jumps over the lazy dog.\n" 20 | var buf bytes.Buffer 21 | // compress text 22 | w, err := xz.NewWriter(&buf) 23 | if err != nil { 24 | log.Fatalf("xz.NewWriter error %s", err) 25 | } 26 | if _, err := io.WriteString(w, text); err != nil { 27 | log.Fatalf("WriteString error %s", err) 28 | } 29 | if err := w.Close(); err != nil { 30 | log.Fatalf("w.Close error %s", err) 31 | } 32 | // decompress buffer and write output to stdout 33 | r, err := xz.NewReader(&buf) 34 | if err != nil { 35 | log.Fatalf("NewReader error %s", err) 36 | } 37 | if _, err = io.Copy(os.Stdout, r); err != nil { 38 | log.Fatalf("io.Copy error %s", err) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/mholt/archiver/build.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -ex 3 | 4 | # This script builds archiver for most common platforms. 5 | 6 | export CGO_ENABLED=0 7 | 8 | cd cmd/archiver 9 | GOOS=linux GOARCH=386 go build -o ../../builds/archiver_linux_386 10 | GOOS=linux GOARCH=amd64 go build -o ../../builds/archiver_linux_amd64 11 | GOOS=linux GOARCH=arm go build -o ../../builds/archiver_linux_arm7 12 | GOOS=linux GOARCH=arm64 go build -o ../../builds/archiver_linux_arm64 13 | GOOS=darwin GOARCH=amd64 go build -o ../../builds/archiver_mac_amd64 14 | GOOS=windows GOARCH=386 go build -o ../../builds/archiver_windows_386.exe 15 | GOOS=windows GOARCH=amd64 go build -o ../../builds/archiver_windows_amd64.exe 16 | GOOS=freebsd GOARCH=386 go build -o ../../builds/archiver_freebsd_386 17 | GOOS=freebsd GOARCH=amd64 go build -o ../../builds/archiver_freebsd_amd64 18 | GOOS=freebsd GOARCH=arm go build -o ../../builds/archiver_freebsd_arm7 19 | GOOS=openbsd GOARCH=386 go build -o ../../builds/archiver_openbsd_386 20 | GOOS=openbsd GOARCH=amd64 go build -o ../../builds/archiver_openbsd_amd64 21 | cd ../.. -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/lzma/bytewriter.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package lzma 6 | 7 | import ( 8 | "errors" 9 | "io" 10 | ) 11 | 12 | // ErrLimit indicates that the limit of the LimitedByteWriter has been 13 | // reached. 14 | var ErrLimit = errors.New("limit reached") 15 | 16 | // LimitedByteWriter provides a byte writer that can be written until a 17 | // limit is reached. The field N provides the number of remaining 18 | // bytes. 19 | type LimitedByteWriter struct { 20 | BW io.ByteWriter 21 | N int64 22 | } 23 | 24 | // WriteByte writes a single byte to the limited byte writer. It returns 25 | // ErrLimit if the limit has been reached. If the byte is successfully 26 | // written the field N of the LimitedByteWriter will be decremented by 27 | // one. 28 | func (l *LimitedByteWriter) WriteByte(c byte) error { 29 | if l.N <= 0 { 30 | return ErrLimit 31 | } 32 | if err := l.BW.WriteByte(c); err != nil { 33 | return err 34 | } 35 | l.N-- 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /engine/exec.go: -------------------------------------------------------------------------------- 1 | package engine 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "github.com/shivakishore14/govm/utils" 7 | "os" 8 | "os/exec" 9 | "path/filepath" 10 | "runtime" 11 | ) 12 | 13 | func Exec(version string, args []string) error { 14 | path, err := Path(version) 15 | if err != nil { 16 | return err 17 | } 18 | binPath := filepath.Join(path, "bin/") 19 | goToolDir := filepath.Join(path, "/pkg/tools/",runtime.GOOS+"_"+runtime.GOARCH) 20 | os.Setenv("GOTOOLDIR", goToolDir) 21 | os.Setenv("GOROOT", path) 22 | 23 | if err = os.Setenv("GOROOT", path); err != nil { 24 | fmt.Println(err) 25 | } 26 | utils.AddToPath(binPath) 27 | 28 | cmd := exec.Command(args[0], args[1:]...) 29 | // Stdout buffer 30 | cmdOutput := &bytes.Buffer{} 31 | // Attach buffer to command 32 | cmd.Stdout = cmdOutput 33 | 34 | err = cmd.Run() // will wait for command to return 35 | if err != nil { 36 | return err 37 | } 38 | // Only output the commands stdout 39 | printOutput(cmdOutput.Bytes()) 40 | 41 | return nil 42 | } 43 | 44 | func printOutput(outs []byte) { 45 | if len(outs) > 0 { 46 | fmt.Printf(string(outs)) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/mholt/archiver/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Matthew Holt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /vendor/github.com/dustin/go-humanize/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2005-2008 Dustin Sallings 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Govm [ WIP ] 2 | Govm is a fast and flexible version manager for Go built with Go. 3 | 4 | Govm lets you work with multiple versions of Go, actively. 5 | 6 | 7 | # installation 8 | 9 | ## Step 1 10 | #### from binary 11 | download binary from [here](https://github.com/shivakishore14/govm/releases) 12 | and copy the binary to a place under `$PATH`. 13 | 14 | [or] 15 | #### with Go 16 | ``` 17 | go get github.com/shivakishore14/govm 18 | ``` 19 | 20 | ## step 2 21 | #### configure govm 22 | ``` 23 | govm configure 24 | ``` 25 | 26 | # List versions 27 | List all versions available for download 28 | ``` 29 | govm ls-remote 30 | ``` 31 | 32 | List versions installed locally. 33 | ``` 34 | govm ls 35 | ``` 36 | 37 | # Download / Install a Go version 38 | ``` 39 | govm install 1.10 40 | ``` 41 | 42 | # Use a version 43 | ``` 44 | govm use 1.10 45 | ``` 46 | 47 | # uninstall a version 48 | ``` 49 | govm uninstall 1.10 50 | ``` 51 | 52 | # Execute a command with specific version 53 | ``` 54 | govm exec 1.10 go env 55 | ``` 56 | 57 | # Contributing 58 | 59 | Contributions to GoVM are welcome and encouraged. please read CONTRIBUTING.md 60 | 61 | # Bugs ? 62 | Please report them under [issues](https://github.com/shivakishore14/govm/issues) 63 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Gopkg.toml example 2 | # 3 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md 4 | # for detailed Gopkg.toml documentation. 5 | # 6 | # required = ["github.com/user/thing/cmd/thing"] 7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 8 | # 9 | # [[constraint]] 10 | # name = "github.com/user/project" 11 | # version = "1.0.0" 12 | # 13 | # [[constraint]] 14 | # name = "github.com/user/project2" 15 | # branch = "dev" 16 | # source = "github.com/myfork/project2" 17 | # 18 | # [[override]] 19 | # name = "github.com/x/y" 20 | # version = "2.4.0" 21 | # 22 | # [prune] 23 | # non-go = false 24 | # go-tests = true 25 | # unused-packages = true 26 | 27 | 28 | [[constraint]] 29 | name = "github.com/PuerkitoBio/goquery" 30 | version = "1.4.0" 31 | 32 | [[constraint]] 33 | branch = "master" 34 | name = "github.com/dustin/go-humanize" 35 | 36 | [[constraint]] 37 | name = "github.com/mholt/archiver" 38 | version = "2.0.0" 39 | 40 | [[constraint]] 41 | name = "github.com/pkg/errors" 42 | version = "0.8.0" 43 | 44 | [[constraint]] 45 | name = "github.com/spf13/cobra" 46 | version = "0.0.2" 47 | 48 | [prune] 49 | go-tests = true 50 | unused-packages = true 51 | -------------------------------------------------------------------------------- /vendor/github.com/dsnet/compress/bzip2/internal/sais/common.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Joe Tsai. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE.md file. 4 | 5 | // Package sais implements a linear time suffix array algorithm. 6 | package sais 7 | 8 | //go:generate go run sais_gen.go byte sais_byte.go 9 | //go:generate go run sais_gen.go int sais_int.go 10 | 11 | // This package ports the C sais implementation by Yuta Mori. The ports are 12 | // located in sais_byte.go and sais_int.go, which are identical to each other 13 | // except for the types. Since Go does not support generics, we use generators to 14 | // create the two files. 15 | // 16 | // References: 17 | // https://sites.google.com/site/yuta256/sais 18 | // https://www.researchgate.net/publication/221313676_Linear_Time_Suffix_Array_Construction_Using_D-Critical_Substrings 19 | // https://www.researchgate.net/publication/224176324_Two_Efficient_Algorithms_for_Linear_Time_Suffix_Array_Construction 20 | 21 | // ComputeSA computes the suffix array of t and places the result in sa. 22 | // Both t and sa must be the same length. 23 | func ComputeSA(t []byte, sa []int) { 24 | if len(sa) != len(t) { 25 | panic("mismatching sizes") 26 | } 27 | computeSA_byte(t, sa, 0, len(t), 256) 28 | } 29 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/lzma/bitops.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package lzma 6 | 7 | /* Naming conventions follows the CodeReviewComments in the Go Wiki. */ 8 | 9 | // ntz32Const is used by the functions NTZ and NLZ. 10 | const ntz32Const = 0x04d7651f 11 | 12 | // ntz32Table is a helper table for de Bruijn algorithm by Danny Dubé. 13 | // See Henry S. Warren, Jr. "Hacker's Delight" section 5-1 figure 5-26. 14 | var ntz32Table = [32]int8{ 15 | 0, 1, 2, 24, 3, 19, 6, 25, 16 | 22, 4, 20, 10, 16, 7, 12, 26, 17 | 31, 23, 18, 5, 21, 9, 15, 11, 18 | 30, 17, 8, 14, 29, 13, 28, 27, 19 | } 20 | 21 | // ntz32 computes the number of trailing zeros for an unsigned 32-bit integer. 22 | func ntz32(x uint32) int { 23 | if x == 0 { 24 | return 32 25 | } 26 | x = (x & -x) * ntz32Const 27 | return int(ntz32Table[x>>27]) 28 | } 29 | 30 | // nlz32 computes the number of leading zeros for an unsigned 32-bit integer. 31 | func nlz32(x uint32) int { 32 | // Smear left most bit to the right 33 | x |= x >> 1 34 | x |= x >> 2 35 | x |= x >> 4 36 | x |= x >> 8 37 | x |= x >> 16 38 | // Use ntz mechanism to calculate nlz. 39 | x++ 40 | if x == 0 { 41 | return 0 42 | } 43 | x *= ntz32Const 44 | return 32 - int(ntz32Table[x>>27]) 45 | } 46 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/github.com/nwaples/rardecode/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Nicholas Waples 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /vendor/github.com/andybalholm/cascadia/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Andy Balholm. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Dave Cheney 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_windows_1.4.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | // +build go1.4 3 | 4 | package mousetrap 5 | 6 | import ( 7 | "os" 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func getProcessEntry(pid int) (*syscall.ProcessEntry32, error) { 13 | snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0) 14 | if err != nil { 15 | return nil, err 16 | } 17 | defer syscall.CloseHandle(snapshot) 18 | var procEntry syscall.ProcessEntry32 19 | procEntry.Size = uint32(unsafe.Sizeof(procEntry)) 20 | if err = syscall.Process32First(snapshot, &procEntry); err != nil { 21 | return nil, err 22 | } 23 | for { 24 | if procEntry.ProcessID == uint32(pid) { 25 | return &procEntry, nil 26 | } 27 | err = syscall.Process32Next(snapshot, &procEntry) 28 | if err != nil { 29 | return nil, err 30 | } 31 | } 32 | } 33 | 34 | // StartedByExplorer returns true if the program was invoked by the user double-clicking 35 | // on the executable from explorer.exe 36 | // 37 | // It is conservative and returns false if any of the internal calls fail. 38 | // It does not guarantee that the program was run from a terminal. It only can tell you 39 | // whether it was launched from explorer.exe 40 | func StartedByExplorer() bool { 41 | pe, err := getProcessEntry(os.Getppid()) 42 | if err != nil { 43 | return false 44 | } 45 | return "explorer.exe" == syscall.UTF16ToString(pe.ExeFile[:]) 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/lzma/matchalgorithm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package lzma 6 | 7 | import "errors" 8 | 9 | // MatchAlgorithm identifies an algorithm to find matches in the 10 | // dictionary. 11 | type MatchAlgorithm byte 12 | 13 | // Supported matcher algorithms. 14 | const ( 15 | HashTable4 MatchAlgorithm = iota 16 | BinaryTree 17 | ) 18 | 19 | // maStrings are used by the String method. 20 | var maStrings = map[MatchAlgorithm]string{ 21 | HashTable4: "HashTable4", 22 | BinaryTree: "BinaryTree", 23 | } 24 | 25 | // String returns a string representation of the Matcher. 26 | func (a MatchAlgorithm) String() string { 27 | if s, ok := maStrings[a]; ok { 28 | return s 29 | } 30 | return "unknown" 31 | } 32 | 33 | var errUnsupportedMatchAlgorithm = errors.New( 34 | "lzma: unsupported match algorithm value") 35 | 36 | // verify checks whether the matcher value is supported. 37 | func (a MatchAlgorithm) verify() error { 38 | if _, ok := maStrings[a]; !ok { 39 | return errUnsupportedMatchAlgorithm 40 | } 41 | return nil 42 | } 43 | 44 | func (a MatchAlgorithm) new(dictCap int) (m matcher, err error) { 45 | switch a { 46 | case HashTable4: 47 | return newHashTable(dictCap, 4) 48 | case BinaryTree: 49 | return newBinTree(dictCap) 50 | } 51 | return nil, errUnsupportedMatchAlgorithm 52 | } 53 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2016, Martin Angers & Contributors 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2016 Ulrich Kunitz 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * My name, Ulrich Kunitz, may not be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /vendor/github.com/dsnet/compress/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright © 2015, Joe Tsai and The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright notice, 9 | this list of conditions and the following disclaimer in the documentation and/or 10 | other materials provided with the distribution. 11 | * Neither the copyright holder nor the names of its contributors may be used to 12 | endorse or promote products derived from this software without specific prior 13 | written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/iteration.go: -------------------------------------------------------------------------------- 1 | package goquery 2 | 3 | // Each iterates over a Selection object, executing a function for each 4 | // matched element. It returns the current Selection object. The function 5 | // f is called for each element in the selection with the index of the 6 | // element in that selection starting at 0, and a *Selection that contains 7 | // only that element. 8 | func (s *Selection) Each(f func(int, *Selection)) *Selection { 9 | for i, n := range s.Nodes { 10 | f(i, newSingleSelection(n, s.document)) 11 | } 12 | return s 13 | } 14 | 15 | // EachWithBreak iterates over a Selection object, executing a function for each 16 | // matched element. It is identical to Each except that it is possible to break 17 | // out of the loop by returning false in the callback function. It returns the 18 | // current Selection object. 19 | func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection { 20 | for i, n := range s.Nodes { 21 | if !f(i, newSingleSelection(n, s.document)) { 22 | return s 23 | } 24 | } 25 | return s 26 | } 27 | 28 | // Map passes each element in the current matched set through a function, 29 | // producing a slice of string holding the returned values. The function 30 | // f is called for each element in the selection with the index of the 31 | // element in that selection starting at 0, and a *Selection that contains 32 | // only that element. 33 | func (s *Selection) Map(f func(int, *Selection) string) (result []string) { 34 | for i, n := range s.Nodes { 35 | result = append(result, f(i, newSingleSelection(n, s.document))) 36 | } 37 | 38 | return result 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/crc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package xz 6 | 7 | import ( 8 | "hash" 9 | "hash/crc32" 10 | "hash/crc64" 11 | ) 12 | 13 | // crc32Hash implements the hash.Hash32 interface with Sum returning the 14 | // crc32 value in little-endian encoding. 15 | type crc32Hash struct { 16 | hash.Hash32 17 | } 18 | 19 | // Sum returns the crc32 value as little endian. 20 | func (h crc32Hash) Sum(b []byte) []byte { 21 | p := make([]byte, 4) 22 | putUint32LE(p, h.Hash32.Sum32()) 23 | b = append(b, p...) 24 | return b 25 | } 26 | 27 | // newCRC32 returns a CRC-32 hash that returns the 64-bit value in 28 | // little-endian encoding using the IEEE polynomial. 29 | func newCRC32() hash.Hash { 30 | return crc32Hash{Hash32: crc32.NewIEEE()} 31 | } 32 | 33 | // crc64Hash implements the Hash64 interface with Sum returning the 34 | // CRC-64 value in little-endian encoding. 35 | type crc64Hash struct { 36 | hash.Hash64 37 | } 38 | 39 | // Sum returns the CRC-64 value in little-endian encoding. 40 | func (h crc64Hash) Sum(b []byte) []byte { 41 | p := make([]byte, 8) 42 | putUint64LE(p, h.Hash64.Sum64()) 43 | b = append(b, p...) 44 | return b 45 | } 46 | 47 | // crc64Table is used to create a CRC-64 hash. 48 | var crc64Table = crc64.MakeTable(crc64.ECMA) 49 | 50 | // newCRC64 returns a CRC-64 hash that returns the 64-bit value in 51 | // little-endian encoding using the ECMA polynomial. 52 | func newCRC64() hash.Hash { 53 | return crc64Hash{Hash64: crc64.New(crc64Table)} 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Alex Ogier. All rights reserved. 2 | Copyright (c) 2012 The Go Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/lzma/directcodec.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package lzma 6 | 7 | import "fmt" 8 | 9 | // directCodec allows the encoding and decoding of values with a fixed number 10 | // of bits. The number of bits must be in the range [1,32]. 11 | type directCodec byte 12 | 13 | // makeDirectCodec creates a directCodec. The function panics if the number of 14 | // bits is not in the range [1,32]. 15 | func makeDirectCodec(bits int) directCodec { 16 | if !(1 <= bits && bits <= 32) { 17 | panic(fmt.Errorf("bits=%d out of range", bits)) 18 | } 19 | return directCodec(bits) 20 | } 21 | 22 | // Bits returns the number of bits supported by this codec. 23 | func (dc directCodec) Bits() int { 24 | return int(dc) 25 | } 26 | 27 | // Encode uses the range encoder to encode a value with the fixed number of 28 | // bits. The most-significant bit is encoded first. 29 | func (dc directCodec) Encode(e *rangeEncoder, v uint32) error { 30 | for i := int(dc) - 1; i >= 0; i-- { 31 | if err := e.DirectEncodeBit(v >> uint(i)); err != nil { 32 | return err 33 | } 34 | } 35 | return nil 36 | } 37 | 38 | // Decode uses the range decoder to decode a value with the given number of 39 | // given bits. The most-significant bit is decoded first. 40 | func (dc directCodec) Decode(d *rangeDecoder) (v uint32, err error) { 41 | for i := int(dc) - 1; i >= 0; i-- { 42 | x, err := d.DirectDecodeBit() 43 | if err != nil { 44 | return 0, err 45 | } 46 | v = (v << 1) | x 47 | } 48 | return v, nil 49 | } 50 | -------------------------------------------------------------------------------- /vendor/github.com/mholt/archiver/targz.go: -------------------------------------------------------------------------------- 1 | package archiver 2 | 3 | import ( 4 | "archive/tar" 5 | "compress/gzip" 6 | "fmt" 7 | "os" 8 | "strings" 9 | ) 10 | 11 | // TarGz is for TarGz format 12 | var TarGz tarGzFormat 13 | 14 | func init() { 15 | RegisterFormat("TarGz", TarGz) 16 | } 17 | 18 | type tarGzFormat struct{} 19 | 20 | func (tarGzFormat) Match(filename string) bool { 21 | // TODO: read file header to identify the format 22 | return strings.HasSuffix(strings.ToLower(filename), ".tar.gz") || 23 | strings.HasSuffix(strings.ToLower(filename), ".tgz") 24 | } 25 | 26 | // Make creates a .tar.gz file at targzPath containing 27 | // the contents of files listed in filePaths. It works 28 | // the same way Tar does, but with gzip compression. 29 | func (tarGzFormat) Make(targzPath string, filePaths []string) error { 30 | out, err := os.Create(targzPath) 31 | if err != nil { 32 | return fmt.Errorf("error creating %s: %v", targzPath, err) 33 | } 34 | defer out.Close() 35 | 36 | gzWriter := gzip.NewWriter(out) 37 | defer gzWriter.Close() 38 | 39 | tarWriter := tar.NewWriter(gzWriter) 40 | defer tarWriter.Close() 41 | 42 | return tarball(filePaths, tarWriter, targzPath) 43 | } 44 | 45 | // Open untars source and decompresses the contents into destination. 46 | func (tarGzFormat) Open(source, destination string) error { 47 | f, err := os.Open(source) 48 | if err != nil { 49 | return fmt.Errorf("%s: failed to open archive: %v", source, err) 50 | } 51 | defer f.Close() 52 | 53 | gzr, err := gzip.NewReader(f) 54 | if err != nil { 55 | return fmt.Errorf("%s: create new gzip reader: %v", source, err) 56 | } 57 | defer gzr.Close() 58 | 59 | return untar(tar.NewReader(gzr), destination) 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/lzma/prob.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package lzma 6 | 7 | // movebits defines the number of bits used for the updates of probability 8 | // values. 9 | const movebits = 5 10 | 11 | // probbits defines the number of bits of a probability value. 12 | const probbits = 11 13 | 14 | // probInit defines 0.5 as initial value for prob values. 15 | const probInit prob = 1 << (probbits - 1) 16 | 17 | // Type prob represents probabilities. The type can also be used to encode and 18 | // decode single bits. 19 | type prob uint16 20 | 21 | // Dec decreases the probability. The decrease is proportional to the 22 | // probability value. 23 | func (p *prob) dec() { 24 | *p -= *p >> movebits 25 | } 26 | 27 | // Inc increases the probability. The Increase is proportional to the 28 | // difference of 1 and the probability value. 29 | func (p *prob) inc() { 30 | *p += ((1 << probbits) - *p) >> movebits 31 | } 32 | 33 | // Computes the new bound for a given range using the probability value. 34 | func (p prob) bound(r uint32) uint32 { 35 | return (r >> probbits) * uint32(p) 36 | } 37 | 38 | // Bits returns 1. One is the number of bits that can be encoded or decoded 39 | // with a single prob value. 40 | func (p prob) Bits() int { 41 | return 1 42 | } 43 | 44 | // Encode encodes the least-significant bit of v. Note that the p value will be 45 | // changed. 46 | func (p *prob) Encode(e *rangeEncoder, v uint32) error { 47 | return e.EncodeBit(v, p) 48 | } 49 | 50 | // Decode decodes a single bit. Note that the p value will change. 51 | func (p *prob) Decode(d *rangeDecoder) (v uint32, err error) { 52 | return d.DecodeBit(p) 53 | } 54 | -------------------------------------------------------------------------------- /engine/remoteList.go: -------------------------------------------------------------------------------- 1 | package engine 2 | 3 | import ( 4 | "github.com/PuerkitoBio/goquery" 5 | "github.com/shivakishore14/govm/domain" 6 | "log" 7 | ) 8 | 9 | var URL = "https://golang.org/dl/" 10 | 11 | func RemoteList(os string, arch string) domain.Versions { 12 | doc, err := goquery.NewDocument(URL) 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | remoteVersions := []domain.Version{} 17 | doc.Find(".toggle, .toggleVisible").Each(func(i int, s *goquery.Selection) { 18 | s.Find(".codetable").Each(func(i int, s *goquery.Selection) { 19 | v := getFileByConf(s, os, arch) 20 | if !v.IsEmpty() { 21 | remoteVersions = append(remoteVersions, v) 22 | } 23 | }) 24 | }) 25 | return remoteVersions 26 | } 27 | 28 | func getFileByConf(tableSelection *goquery.Selection, os string, arch string) domain.Version { 29 | version := domain.Version{} 30 | name, _ := tableSelection.Parent().Parent().Attr("id") 31 | tableSelection.Find("tr").Each(func(i int, s *goquery.Selection) { 32 | data := s.Find("td") 33 | link, _ := data.Eq(0).Find("a").Attr("href") 34 | 35 | v := domain.Version{ 36 | Name: name, 37 | DownloadLink: link, 38 | FileName: data.Eq(0).Text(), 39 | Kind: data.Eq(1).Text(), 40 | Os: data.Eq(2).Text(), 41 | Arch: data.Eq(3).Text(), 42 | Size: data.Eq(4).Text(), 43 | SHA1: data.Eq(5).Text(), 44 | } 45 | if v.Kind == "Archive" && v.Os == getRemoteOs(os) && v.Arch == getRemoteArch(arch) { 46 | version = v 47 | } 48 | }) 49 | return version 50 | } 51 | 52 | func getRemoteOs(hostOs string) string { 53 | switch hostOs { 54 | case "darwin": 55 | return "macOS" 56 | case "linux": 57 | return "Linux" 58 | case "windows": 59 | return "Windows" 60 | } 61 | return "" 62 | } 63 | 64 | func getRemoteArch(hostArch string) string { 65 | switch hostArch { 66 | case "amd64": 67 | return "x86-64" 68 | } 69 | return "x86" 70 | } 71 | -------------------------------------------------------------------------------- /vendor/github.com/mholt/archiver/tarxz.go: -------------------------------------------------------------------------------- 1 | package archiver 2 | 3 | import ( 4 | "archive/tar" 5 | "fmt" 6 | "os" 7 | "strings" 8 | 9 | "github.com/ulikunitz/xz" 10 | ) 11 | 12 | // TarXZ is for TarXZ format 13 | var TarXZ xzFormat 14 | 15 | func init() { 16 | RegisterFormat("TarXZ", TarXZ) 17 | } 18 | 19 | type xzFormat struct{} 20 | 21 | // Match returns whether filename matches this format. 22 | func (xzFormat) Match(filename string) bool { 23 | // TODO: read file header to identify the format 24 | return strings.HasSuffix(strings.ToLower(filename), ".tar.xz") || 25 | strings.HasSuffix(strings.ToLower(filename), ".txz") 26 | } 27 | 28 | // Make creates a .tar.xz file at xzPath containing 29 | // the contents of files listed in filePaths. File 30 | // paths can be those of regular files or directories. 31 | // Regular files are stored at the 'root' of the 32 | // archive, and directories are recursively added. 33 | func (xzFormat) Make(xzPath string, filePaths []string) error { 34 | out, err := os.Create(xzPath) 35 | if err != nil { 36 | return fmt.Errorf("error creating %s: %v", xzPath, err) 37 | } 38 | defer out.Close() 39 | 40 | xzWriter, err := xz.NewWriter(out) 41 | if err != nil { 42 | return fmt.Errorf("error compressing %s: %v", xzPath, err) 43 | } 44 | defer xzWriter.Close() 45 | 46 | tarWriter := tar.NewWriter(xzWriter) 47 | defer tarWriter.Close() 48 | 49 | return tarball(filePaths, tarWriter, xzPath) 50 | } 51 | 52 | // Open untars source and decompresses the contents into destination. 53 | func (xzFormat) Open(source, destination string) error { 54 | f, err := os.Open(source) 55 | if err != nil { 56 | return fmt.Errorf("%s: failed to open archive: %v", source, err) 57 | } 58 | defer f.Close() 59 | 60 | xzReader, err := xz.NewReader(f) 61 | if err != nil { 62 | return fmt.Errorf("error decompressing %s: %v", source, err) 63 | } 64 | 65 | return untar(tar.NewReader(xzReader), destination) 66 | } 67 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/query.go: -------------------------------------------------------------------------------- 1 | package goquery 2 | 3 | import "golang.org/x/net/html" 4 | 5 | // Is checks the current matched set of elements against a selector and 6 | // returns true if at least one of these elements matches. 7 | func (s *Selection) Is(selector string) bool { 8 | return s.IsMatcher(compileMatcher(selector)) 9 | } 10 | 11 | // IsMatcher checks the current matched set of elements against a matcher and 12 | // returns true if at least one of these elements matches. 13 | func (s *Selection) IsMatcher(m Matcher) bool { 14 | if len(s.Nodes) > 0 { 15 | if len(s.Nodes) == 1 { 16 | return m.Match(s.Nodes[0]) 17 | } 18 | return len(m.Filter(s.Nodes)) > 0 19 | } 20 | 21 | return false 22 | } 23 | 24 | // IsFunction checks the current matched set of elements against a predicate and 25 | // returns true if at least one of these elements matches. 26 | func (s *Selection) IsFunction(f func(int, *Selection) bool) bool { 27 | return s.FilterFunction(f).Length() > 0 28 | } 29 | 30 | // IsSelection checks the current matched set of elements against a Selection object 31 | // and returns true if at least one of these elements matches. 32 | func (s *Selection) IsSelection(sel *Selection) bool { 33 | return s.FilterSelection(sel).Length() > 0 34 | } 35 | 36 | // IsNodes checks the current matched set of elements against the specified nodes 37 | // and returns true if at least one of these elements matches. 38 | func (s *Selection) IsNodes(nodes ...*html.Node) bool { 39 | return s.FilterNodes(nodes...).Length() > 0 40 | } 41 | 42 | // Contains returns true if the specified Node is within, 43 | // at any depth, one of the nodes in the Selection object. 44 | // It is NOT inclusive, to behave like jQuery's implementation, and 45 | // unlike Javascript's .contains, so if the contained 46 | // node is itself in the selection, it returns false. 47 | func (s *Selection) Contains(n *html.Node) bool { 48 | return sliceContains(s.Nodes, n) 49 | } 50 | -------------------------------------------------------------------------------- /vendor/github.com/mholt/archiver/tarbz2.go: -------------------------------------------------------------------------------- 1 | package archiver 2 | 3 | import ( 4 | "archive/tar" 5 | "fmt" 6 | "os" 7 | "strings" 8 | 9 | "github.com/dsnet/compress/bzip2" 10 | ) 11 | 12 | // TarBz2 is for TarBz2 format 13 | var TarBz2 tarBz2Format 14 | 15 | func init() { 16 | RegisterFormat("TarBz2", TarBz2) 17 | } 18 | 19 | type tarBz2Format struct{} 20 | 21 | func (tarBz2Format) Match(filename string) bool { 22 | // TODO: read file header to identify the format 23 | return strings.HasSuffix(strings.ToLower(filename), ".tar.bz2") || 24 | strings.HasSuffix(strings.ToLower(filename), ".tbz2") 25 | } 26 | 27 | // Make creates a .tar.bz2 file at tarbz2Path containing 28 | // the contents of files listed in filePaths. File paths 29 | // can be those of regular files or directories. Regular 30 | // files are stored at the 'root' of the archive, and 31 | // directories are recursively added. 32 | func (tarBz2Format) Make(tarbz2Path string, filePaths []string) error { 33 | out, err := os.Create(tarbz2Path) 34 | if err != nil { 35 | return fmt.Errorf("error creating %s: %v", tarbz2Path, err) 36 | } 37 | defer out.Close() 38 | 39 | bz2Writer, err := bzip2.NewWriter(out, nil) 40 | if err != nil { 41 | return fmt.Errorf("error compressing %s: %v", tarbz2Path, err) 42 | } 43 | defer bz2Writer.Close() 44 | 45 | tarWriter := tar.NewWriter(bz2Writer) 46 | defer tarWriter.Close() 47 | 48 | return tarball(filePaths, tarWriter, tarbz2Path) 49 | } 50 | 51 | // Open untars source and decompresses the contents into destination. 52 | func (tarBz2Format) Open(source, destination string) error { 53 | f, err := os.Open(source) 54 | if err != nil { 55 | return fmt.Errorf("%s: failed to open archive: %v", source, err) 56 | } 57 | defer f.Close() 58 | 59 | bz2r, err := bzip2.NewReader(f, nil) 60 | if err != nil { 61 | return fmt.Errorf("error decompressing %s: %v", source, err) 62 | } 63 | defer bz2r.Close() 64 | 65 | return untar(tar.NewReader(bz2r), destination) 66 | } 67 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/internal/hash/rabin_karp.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package hash 6 | 7 | // A is the default constant for Robin-Karp rolling hash. This is a random 8 | // prime. 9 | const A = 0x97b548add41d5da1 10 | 11 | // RabinKarp supports the computation of a rolling hash. 12 | type RabinKarp struct { 13 | A uint64 14 | // a^n 15 | aOldest uint64 16 | h uint64 17 | p []byte 18 | i int 19 | } 20 | 21 | // NewRabinKarp creates a new RabinKarp value. The argument n defines the 22 | // length of the byte sequence to be hashed. The default constant will will be 23 | // used. 24 | func NewRabinKarp(n int) *RabinKarp { 25 | return NewRabinKarpConst(n, A) 26 | } 27 | 28 | // NewRabinKarpConst creates a new RabinKarp value. The argument n defines the 29 | // length of the byte sequence to be hashed. The argument a provides the 30 | // constant used to compute the hash. 31 | func NewRabinKarpConst(n int, a uint64) *RabinKarp { 32 | if n <= 0 { 33 | panic("number of bytes n must be positive") 34 | } 35 | aOldest := uint64(1) 36 | // There are faster methods. For the small n required by the LZMA 37 | // compressor O(n) is sufficient. 38 | for i := 0; i < n; i++ { 39 | aOldest *= a 40 | } 41 | return &RabinKarp{ 42 | A: a, aOldest: aOldest, 43 | p: make([]byte, 0, n), 44 | } 45 | } 46 | 47 | // Len returns the length of the byte sequence. 48 | func (r *RabinKarp) Len() int { 49 | return cap(r.p) 50 | } 51 | 52 | // RollByte computes the hash after x has been added. 53 | func (r *RabinKarp) RollByte(x byte) uint64 { 54 | if len(r.p) < cap(r.p) { 55 | r.h += uint64(x) 56 | r.h *= r.A 57 | r.p = append(r.p, x) 58 | } else { 59 | r.h -= uint64(r.p[r.i]) * r.aOldest 60 | r.h += uint64(x) 61 | r.h *= r.A 62 | r.p[r.i] = x 63 | r.i = (r.i + 1) % cap(r.p) 64 | } 65 | return r.h 66 | } 67 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/bits.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package xz 6 | 7 | import ( 8 | "errors" 9 | "io" 10 | ) 11 | 12 | // putUint32LE puts the little-endian representation of x into the first 13 | // four bytes of p. 14 | func putUint32LE(p []byte, x uint32) { 15 | p[0] = byte(x) 16 | p[1] = byte(x >> 8) 17 | p[2] = byte(x >> 16) 18 | p[3] = byte(x >> 24) 19 | } 20 | 21 | // putUint64LE puts the little-endian representation of x into the first 22 | // eight bytes of p. 23 | func putUint64LE(p []byte, x uint64) { 24 | p[0] = byte(x) 25 | p[1] = byte(x >> 8) 26 | p[2] = byte(x >> 16) 27 | p[3] = byte(x >> 24) 28 | p[4] = byte(x >> 32) 29 | p[5] = byte(x >> 40) 30 | p[6] = byte(x >> 48) 31 | p[7] = byte(x >> 56) 32 | } 33 | 34 | // uint32LE converts a little endian representation to an uint32 value. 35 | func uint32LE(p []byte) uint32 { 36 | return uint32(p[0]) | uint32(p[1])<<8 | uint32(p[2])<<16 | 37 | uint32(p[3])<<24 38 | } 39 | 40 | // putUvarint puts a uvarint representation of x into the byte slice. 41 | func putUvarint(p []byte, x uint64) int { 42 | i := 0 43 | for x >= 0x80 { 44 | p[i] = byte(x) | 0x80 45 | x >>= 7 46 | i++ 47 | } 48 | p[i] = byte(x) 49 | return i + 1 50 | } 51 | 52 | // errOverflow indicates an overflow of the 64-bit unsigned integer. 53 | var errOverflowU64 = errors.New("xz: uvarint overflows 64-bit unsigned integer") 54 | 55 | // readUvarint reads a uvarint from the given byte reader. 56 | func readUvarint(r io.ByteReader) (x uint64, n int, err error) { 57 | var s uint 58 | i := 0 59 | for { 60 | b, err := r.ReadByte() 61 | if err != nil { 62 | return x, i, err 63 | } 64 | i++ 65 | if b < 0x80 { 66 | if i > 10 || i == 10 && b > 1 { 67 | return x, i, errOverflowU64 68 | } 69 | return x | uint64(b)<&1) 28 | if [[ ! -z "$RET_SCHK" ]]; then echo "$RET_SCHK"; echo; fi 29 | 30 | echo -e "${BOLD}vet${RESET}" 31 | RET_VET=$(go vet ./... 2>&1 | 32 | egrep -v "^flate/dict_decoder.go:(.*)WriteByte" | 33 | egrep -v "^exit status") 34 | if [[ ! -z "$RET_VET" ]]; then echo "$RET_VET"; echo; fi 35 | 36 | echo -e "${BOLD}lint${RESET}" 37 | RET_LINT=$(golint ./... 2>&1 | 38 | egrep -v "should have comment(.*)or be unexported" | 39 | egrep -v "^(.*)type name will be used as(.*)by other packages" | 40 | egrep -v "^brotli/transform.go:(.*)replace i [+]= 1 with i[+]{2}" | 41 | egrep -v "^internal/prefix/prefix.go:(.*)replace symBits(.*) [-]= 1 with symBits(.*)[-]{2}" | 42 | egrep -v "^xflate/common.go:(.*)NoCompression should be of the form" | 43 | egrep -v "^exit status") 44 | if [[ ! -z "$RET_LINT" ]]; then echo "$RET_LINT"; echo; fi 45 | 46 | if [[ ! -z "$RET_FMT" ]] || [ ! -z "$RET_TEST" ] || [[ ! -z "$RET_VET" ]] || [[ ! -z "$RET_SCHK" ]] || [[ ! -z "$RET_LINT" ]] || [[ ! -z "$RET_SPELL" ]]; then 47 | echo -e "${FAIL}${RESET}"; exit 1 48 | else 49 | echo -e "${PASS}${RESET}"; exit 0 50 | fi 51 | -------------------------------------------------------------------------------- /vendor/github.com/mholt/archiver/rar.go: -------------------------------------------------------------------------------- 1 | package archiver 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "os" 7 | "path/filepath" 8 | "strings" 9 | 10 | "github.com/nwaples/rardecode" 11 | ) 12 | 13 | // Rar is for RAR archive format 14 | var Rar rarFormat 15 | 16 | func init() { 17 | RegisterFormat("Rar", Rar) 18 | } 19 | 20 | type rarFormat struct{} 21 | 22 | func (rarFormat) Match(filename string) bool { 23 | // TODO: read file header to identify the format 24 | return strings.HasSuffix(strings.ToLower(filename), ".rar") 25 | } 26 | 27 | // Make makes a .rar archive, but this is not implemented because 28 | // RAR is a proprietary format. It is here only for symmetry with 29 | // the other archive formats in this package. 30 | func (rarFormat) Make(rarPath string, filePaths []string) error { 31 | return fmt.Errorf("make %s: RAR not implemented (proprietary format)", rarPath) 32 | } 33 | 34 | // Open extracts the RAR file at source and puts the contents 35 | // into destination. 36 | func (rarFormat) Open(source, destination string) error { 37 | f, err := os.Open(source) 38 | if err != nil { 39 | return fmt.Errorf("%s: failed to open archive: %v", source, err) 40 | } 41 | defer f.Close() 42 | 43 | rr, err := rardecode.NewReader(f, "") 44 | if err != nil { 45 | return fmt.Errorf("%s: failed to create reader: %v", source, err) 46 | } 47 | 48 | for { 49 | header, err := rr.Next() 50 | if err == io.EOF { 51 | break 52 | } else if err != nil { 53 | return err 54 | } 55 | 56 | if header.IsDir { 57 | err = mkdir(filepath.Join(destination, header.Name)) 58 | if err != nil { 59 | return err 60 | } 61 | continue 62 | } 63 | 64 | // if files come before their containing folders, then we must 65 | // create their folders before writing the file 66 | err = mkdir(filepath.Dir(filepath.Join(destination, header.Name))) 67 | if err != nil { 68 | return err 69 | } 70 | 71 | err = writeNewFile(filepath.Join(destination, header.Name), rr, header.Mode()) 72 | if err != nil { 73 | return err 74 | } 75 | } 76 | 77 | return nil 78 | } 79 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/lzma/properties.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package lzma 6 | 7 | import ( 8 | "errors" 9 | "fmt" 10 | ) 11 | 12 | // maximum and minimum values for the LZMA properties. 13 | const ( 14 | minPB = 0 15 | maxPB = 4 16 | ) 17 | 18 | // maxPropertyCode is the possible maximum of a properties code byte. 19 | const maxPropertyCode = (maxPB+1)*(maxLP+1)*(maxLC+1) - 1 20 | 21 | // Properties contains the parameters LC, LP and PB. The parameter LC 22 | // defines the number of literal context bits; parameter LP the number 23 | // of literal position bits and PB the number of position bits. 24 | type Properties struct { 25 | LC int 26 | LP int 27 | PB int 28 | } 29 | 30 | // String returns the properties in a string representation. 31 | func (p *Properties) String() string { 32 | return fmt.Sprintf("LC %d LP %d PB %d", p.LC, p.LP, p.PB) 33 | } 34 | 35 | // PropertiesForCode converts a properties code byte into a Properties value. 36 | func PropertiesForCode(code byte) (p Properties, err error) { 37 | if code > maxPropertyCode { 38 | return p, errors.New("lzma: invalid properties code") 39 | } 40 | p.LC = int(code % 9) 41 | code /= 9 42 | p.LP = int(code % 5) 43 | code /= 5 44 | p.PB = int(code % 5) 45 | return p, err 46 | } 47 | 48 | // verify checks the properties for correctness. 49 | func (p *Properties) verify() error { 50 | if p == nil { 51 | return errors.New("lzma: properties are nil") 52 | } 53 | if !(minLC <= p.LC && p.LC <= maxLC) { 54 | return errors.New("lzma: lc out of range") 55 | } 56 | if !(minLP <= p.LP && p.LP <= maxLP) { 57 | return errors.New("lzma: lp out of range") 58 | } 59 | if !(minPB <= p.PB && p.PB <= maxPB) { 60 | return errors.New("lzma: pb out of range") 61 | } 62 | return nil 63 | } 64 | 65 | // Code converts the properties to a byte. The function assumes that 66 | // the properties components are all in range. 67 | func (p Properties) Code() byte { 68 | return byte((p.PB*5+p.LP)*9 + p.LC) 69 | } 70 | -------------------------------------------------------------------------------- /vendor/github.com/mholt/archiver/archiver.go: -------------------------------------------------------------------------------- 1 | package archiver 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "log" 7 | "os" 8 | "path/filepath" 9 | "runtime" 10 | ) 11 | 12 | // Archiver represent a archive format 13 | type Archiver interface { 14 | // Match checks supported files 15 | Match(filename string) bool 16 | // Make makes an archive. 17 | Make(destination string, sources []string) error 18 | // Open extracts an archive. 19 | Open(source, destination string) error 20 | } 21 | 22 | // SupportedFormats contains all supported archive formats 23 | var SupportedFormats = map[string]Archiver{} 24 | 25 | // RegisterFormat adds a supported archive format 26 | func RegisterFormat(name string, format Archiver) { 27 | if _, ok := SupportedFormats[name]; ok { 28 | log.Printf("Format %s already exists, skip!\n", name) 29 | return 30 | } 31 | SupportedFormats[name] = format 32 | } 33 | 34 | func writeNewFile(fpath string, in io.Reader, fm os.FileMode) error { 35 | err := os.MkdirAll(filepath.Dir(fpath), 0755) 36 | if err != nil { 37 | return fmt.Errorf("%s: making directory for file: %v", fpath, err) 38 | } 39 | 40 | out, err := os.Create(fpath) 41 | if err != nil { 42 | return fmt.Errorf("%s: creating new file: %v", fpath, err) 43 | } 44 | defer out.Close() 45 | 46 | err = out.Chmod(fm) 47 | if err != nil && runtime.GOOS != "windows" { 48 | return fmt.Errorf("%s: changing file mode: %v", fpath, err) 49 | } 50 | 51 | _, err = io.Copy(out, in) 52 | if err != nil { 53 | return fmt.Errorf("%s: writing file: %v", fpath, err) 54 | } 55 | return nil 56 | } 57 | 58 | func writeNewSymbolicLink(fpath string, target string) error { 59 | err := os.MkdirAll(filepath.Dir(fpath), 0755) 60 | if err != nil { 61 | return fmt.Errorf("%s: making directory for file: %v", fpath, err) 62 | } 63 | 64 | err = os.Symlink(target, fpath) 65 | if err != nil { 66 | return fmt.Errorf("%s: making symbolic link for: %v", fpath, err) 67 | } 68 | 69 | return nil 70 | } 71 | 72 | func mkdir(dirPath string) error { 73 | err := os.MkdirAll(dirPath, 0755) 74 | if err != nil { 75 | return fmt.Errorf("%s: making directory: %v", dirPath, err) 76 | } 77 | return nil 78 | } 79 | -------------------------------------------------------------------------------- /vendor/github.com/dsnet/compress/internal/prefix/encoder.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Joe Tsai. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE.md file. 4 | 5 | package prefix 6 | 7 | import ( 8 | "sort" 9 | 10 | "github.com/dsnet/compress/internal" 11 | ) 12 | 13 | type Encoder struct { 14 | chunks []uint32 // First-level lookup map 15 | chunkMask uint32 // Mask the length of the chunks table 16 | 17 | NumSyms uint32 // Number of symbols 18 | } 19 | 20 | // Init initializes Encoder according to the codes provided. 21 | func (pe *Encoder) Init(codes PrefixCodes) { 22 | // Handle special case trees. 23 | if len(codes) <= 1 { 24 | switch { 25 | case len(codes) == 0: // Empty tree (should error if used later) 26 | *pe = Encoder{chunks: pe.chunks[:0], NumSyms: 0} 27 | case len(codes) == 1 && codes[0].Len == 0: // Single code tree (bit-length of zero) 28 | pe.chunks = append(pe.chunks[:0], codes[0].Val< 0; n >>= 1 { 45 | numChunks <<= 1 46 | } 47 | pe.NumSyms = uint32(len(codes)) 48 | 49 | retry: 50 | // Allocate and reset chunks. 51 | pe.chunks = allocUint32s(pe.chunks, numChunks) 52 | pe.chunkMask = uint32(numChunks - 1) 53 | for i := range pe.chunks { 54 | pe.chunks[i] = 0 // Logic below relies on zero value as uninitialized 55 | } 56 | 57 | // Insert each symbol, checking that there are no conflicts. 58 | for _, c := range codes { 59 | if pe.chunks[c.Sym&pe.chunkMask] > 0 { 60 | // Collision found our "hash" table, so grow and try again. 61 | numChunks <<= 1 62 | goto retry 63 | } 64 | pe.chunks[c.Sym&pe.chunkMask] = c.Val< /dev/null 44 | $PPROF -output=cpu.html -weblist=. $PKG_NAME.test $TMPDIR/cpu.profile 2> /dev/null 45 | $PPROF -output=mem_objects.svg -alloc_objects -web $PKG_NAME.test $TMPDIR/mem.profile 2> /dev/null 46 | $PPROF -output=mem_objects.html -alloc_objects -weblist=. $PKG_NAME.test $TMPDIR/mem.profile 2> /dev/null 47 | $PPROF -output=mem_space.svg -alloc_space -web $PKG_NAME.test $TMPDIR/mem.profile 2> /dev/null 48 | $PPROF -output=mem_space.html -alloc_space -weblist=. $PKG_NAME.test $TMPDIR/mem.profile 2> /dev/null 49 | fi 50 | 51 | rm -rf $DIR/_zprof_/$PKG_NAME 52 | mkdir -p $DIR/_zprof_/$PKG_NAME 53 | mv *.html *.svg $DIR/_zprof_/$PKG_NAME 2> /dev/null 54 | ) 55 | -------------------------------------------------------------------------------- /vendor/github.com/dsnet/compress/bzip2/fuzz_on.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016, Joe Tsai. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE.md file. 4 | 5 | // +build gofuzz 6 | 7 | // This file exists to export internal implementation details for fuzz testing. 8 | 9 | package bzip2 10 | 11 | func ForwardBWT(buf []byte) (ptr int) { 12 | var bwt burrowsWheelerTransform 13 | return bwt.Encode(buf) 14 | } 15 | 16 | func ReverseBWT(buf []byte, ptr int) { 17 | var bwt burrowsWheelerTransform 18 | bwt.Decode(buf, ptr) 19 | } 20 | 21 | type fuzzReader struct { 22 | Checksums Checksums 23 | } 24 | 25 | // updateChecksum updates Checksums. 26 | // 27 | // If a valid pos is provided, it appends the (pos, val) pair to the slice. 28 | // Otherwise, it will update the last record with the new value. 29 | func (fr *fuzzReader) updateChecksum(pos int64, val uint32) { 30 | if pos >= 0 { 31 | fr.Checksums = append(fr.Checksums, Checksum{pos, val}) 32 | } else { 33 | fr.Checksums[len(fr.Checksums)-1].Value = val 34 | } 35 | } 36 | 37 | type Checksum struct { 38 | Offset int64 // Bit offset of the checksum 39 | Value uint32 // Checksum value 40 | } 41 | 42 | type Checksums []Checksum 43 | 44 | // Apply overwrites all checksum fields in d with the ones in cs. 45 | func (cs Checksums) Apply(d []byte) []byte { 46 | d = append([]byte(nil), d...) 47 | for _, c := range cs { 48 | setU32(d, c.Offset, c.Value) 49 | } 50 | return d 51 | } 52 | 53 | func setU32(d []byte, pos int64, val uint32) { 54 | for i := uint(0); i < 32; i++ { 55 | bpos := uint64(pos) + uint64(i) 56 | d[bpos/8] &= ^byte(1 << (7 - bpos%8)) 57 | d[bpos/8] |= byte(val>>(31-i)) << (7 - bpos%8) 58 | } 59 | } 60 | 61 | // Verify checks that all checksum fields in d matches those in cs. 62 | func (cs Checksums) Verify(d []byte) bool { 63 | for _, c := range cs { 64 | if getU32(d, c.Offset) != c.Value { 65 | return false 66 | } 67 | } 68 | return true 69 | } 70 | 71 | func getU32(d []byte, pos int64) (val uint32) { 72 | for i := uint(0); i < 32; i++ { 73 | bpos := uint64(pos) + uint64(i) 74 | val |= (uint32(d[bpos/8] >> (7 - bpos%8))) << (31 - i) 75 | } 76 | return val 77 | } 78 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/README.md: -------------------------------------------------------------------------------- 1 | # Package xz 2 | 3 | This Go language package supports the reading and writing of xz 4 | compressed streams. It includes also a gxz command for compressing and 5 | decompressing data. The package is completely written in Go and doesn't 6 | have any dependency on any C code. 7 | 8 | The package is currently under development. There might be bugs and APIs 9 | are not considered stable. At this time the package cannot compete with 10 | the xz tool regarding compression speed and size. The algorithms there 11 | have been developed over a long time and are highly optimized. However 12 | there are a number of improvements planned and I'm very optimistic about 13 | parallel compression and decompression. Stay tuned! 14 | 15 | # Using the API 16 | 17 | The following example program shows how to use the API. 18 | 19 | package main 20 | 21 | import ( 22 | "bytes" 23 | "io" 24 | "log" 25 | "os" 26 | 27 | "github.com/ulikunitz/xz" 28 | ) 29 | 30 | func main() { 31 | const text = "The quick brown fox jumps over the lazy dog.\n" 32 | var buf bytes.Buffer 33 | // compress text 34 | w, err := xz.NewWriter(&buf) 35 | if err != nil { 36 | log.Fatalf("xz.NewWriter error %s", err) 37 | } 38 | if _, err := io.WriteString(w, text); err != nil { 39 | log.Fatalf("WriteString error %s", err) 40 | } 41 | if err := w.Close(); err != nil { 42 | log.Fatalf("w.Close error %s", err) 43 | } 44 | // decompress buffer and write output to stdout 45 | r, err := xz.NewReader(&buf) 46 | if err != nil { 47 | log.Fatalf("NewReader error %s", err) 48 | } 49 | if _, err = io.Copy(os.Stdout, r); err != nil { 50 | log.Fatalf("io.Copy error %s", err) 51 | } 52 | } 53 | 54 | # Using the gxz compression tool 55 | 56 | The package includes a gxz command line utility for compression and 57 | decompression. 58 | 59 | Use following command for installation: 60 | 61 | $ go get github.com/ulikunitz/xz/cmd/gxz 62 | 63 | To test it call the following command. 64 | 65 | $ gxz bigfile 66 | 67 | After some time a much smaller file bigfile.xz will replace bigfile. 68 | To decompress it use the following command. 69 | 70 | $ gxz -d bigfile.xz 71 | 72 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/README.md: -------------------------------------------------------------------------------- 1 | # errors [![Travis-CI](https://travis-ci.org/pkg/errors.svg)](https://travis-ci.org/pkg/errors) [![AppVeyor](https://ci.appveyor.com/api/projects/status/b98mptawhudj53ep/branch/master?svg=true)](https://ci.appveyor.com/project/davecheney/errors/branch/master) [![GoDoc](https://godoc.org/github.com/pkg/errors?status.svg)](http://godoc.org/github.com/pkg/errors) [![Report card](https://goreportcard.com/badge/github.com/pkg/errors)](https://goreportcard.com/report/github.com/pkg/errors) 2 | 3 | Package errors provides simple error handling primitives. 4 | 5 | `go get github.com/pkg/errors` 6 | 7 | The traditional error handling idiom in Go is roughly akin to 8 | ```go 9 | if err != nil { 10 | return err 11 | } 12 | ``` 13 | which applied recursively up the call stack results in error reports without context or debugging information. The errors package allows programmers to add context to the failure path in their code in a way that does not destroy the original value of the error. 14 | 15 | ## Adding context to an error 16 | 17 | The errors.Wrap function returns a new error that adds context to the original error. For example 18 | ```go 19 | _, err := ioutil.ReadAll(r) 20 | if err != nil { 21 | return errors.Wrap(err, "read failed") 22 | } 23 | ``` 24 | ## Retrieving the cause of an error 25 | 26 | Using `errors.Wrap` constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to reverse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by `errors.Cause`. 27 | ```go 28 | type causer interface { 29 | Cause() error 30 | } 31 | ``` 32 | `errors.Cause` will recursively retrieve the topmost error which does not implement `causer`, which is assumed to be the original cause. For example: 33 | ```go 34 | switch err := errors.Cause(err).(type) { 35 | case *MyError: 36 | // handle specifically 37 | default: 38 | // unknown error 39 | } 40 | ``` 41 | 42 | [Read the package documentation for more information](https://godoc.org/github.com/pkg/errors). 43 | 44 | ## Contributing 45 | 46 | We welcome pull requests, bug fixes and issue reports. With that said, the bar for adding new symbols to this package is intentionally set high. 47 | 48 | Before proposing a change, please discuss your change by raising an issue. 49 | 50 | ## Licence 51 | 52 | BSD-2-Clause 53 | -------------------------------------------------------------------------------- /Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/PuerkitoBio/goquery" 6 | packages = ["."] 7 | revision = "a86ea073017a6beddef78c8659e7224e8ca634b0" 8 | version = "v1.4.0" 9 | 10 | [[projects]] 11 | name = "github.com/andybalholm/cascadia" 12 | packages = ["."] 13 | revision = "901648c87902174f774fac311d7f176f8647bdaa" 14 | version = "v1.0.0" 15 | 16 | [[projects]] 17 | branch = "master" 18 | name = "github.com/dsnet/compress" 19 | packages = [ 20 | ".", 21 | "bzip2", 22 | "bzip2/internal/sais", 23 | "internal", 24 | "internal/errors", 25 | "internal/prefix" 26 | ] 27 | revision = "cc9eb1d7ad760af14e8f918698f745e80377af4f" 28 | 29 | [[projects]] 30 | branch = "master" 31 | name = "github.com/dustin/go-humanize" 32 | packages = ["."] 33 | revision = "bb3d318650d48840a39aa21a027c6630e198e626" 34 | 35 | [[projects]] 36 | name = "github.com/inconshreveable/mousetrap" 37 | packages = ["."] 38 | revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" 39 | version = "v1.0" 40 | 41 | [[projects]] 42 | name = "github.com/mholt/archiver" 43 | packages = ["."] 44 | revision = "cdc68dd1f170b8dfc1a0d2231b5bb0967ed67006" 45 | version = "v2.0" 46 | 47 | [[projects]] 48 | branch = "master" 49 | name = "github.com/nwaples/rardecode" 50 | packages = ["."] 51 | revision = "e06696f847aeda6f39a8f0b7cdff193b7690aef6" 52 | 53 | [[projects]] 54 | name = "github.com/pkg/errors" 55 | packages = ["."] 56 | revision = "645ef00459ed84a119197bfb8d8205042c6df63d" 57 | version = "v0.8.0" 58 | 59 | [[projects]] 60 | name = "github.com/spf13/cobra" 61 | packages = ["."] 62 | revision = "a1f051bc3eba734da4772d60e2d677f47cf93ef4" 63 | version = "v0.0.2" 64 | 65 | [[projects]] 66 | name = "github.com/spf13/pflag" 67 | packages = ["."] 68 | revision = "583c0c0531f06d5278b7d917446061adc344b5cd" 69 | version = "v1.0.1" 70 | 71 | [[projects]] 72 | name = "github.com/ulikunitz/xz" 73 | packages = [ 74 | ".", 75 | "internal/hash", 76 | "internal/xlog", 77 | "lzma" 78 | ] 79 | revision = "0c6b41e72360850ca4f98dc341fd999726ea007f" 80 | version = "v0.5.4" 81 | 82 | [[projects]] 83 | branch = "master" 84 | name = "golang.org/x/net" 85 | packages = [ 86 | "html", 87 | "html/atom" 88 | ] 89 | revision = "d41e8174641f662c5a2d1c7a5f9e828788eb8706" 90 | 91 | [solve-meta] 92 | analyzer-name = "dep" 93 | analyzer-version = 1 94 | inputs-digest = "f8d943d4bf091ca9bed67b165b5ad9c89095f3385174c26a461b0afeec8ce017" 95 | solver-name = "gps-cdcl" 96 | solver-version = 1 97 | -------------------------------------------------------------------------------- /engine/install.go: -------------------------------------------------------------------------------- 1 | package engine 2 | 3 | import ( 4 | "fmt" 5 | "github.com/dustin/go-humanize" 6 | "github.com/mholt/archiver" 7 | "github.com/shivakishore14/govm/domain" 8 | "io" 9 | "net/http" 10 | "os" 11 | "path/filepath" 12 | "strings" 13 | ) 14 | 15 | func Install(v domain.Version) error { 16 | return Download(v) 17 | } 18 | 19 | func Download(v domain.Version) error { 20 | conf := domain.Config{} 21 | conf.LoadConf() 22 | return DownloadFile(v, conf) 23 | } 24 | 25 | func DownloadFile(v domain.Version, config domain.Config) error { 26 | // Create the file, but give it a tmp file extension, this means we won't overwrite a 27 | // file until it's downloaded, but we'll remove the tmp extension once downloaded. 28 | if err := os.MkdirAll(config.TempDir, os.ModePerm); err != nil { 29 | return err 30 | } 31 | filePath := filepath.Join(config.TempDir, v.FileName) 32 | out, err := os.Create(filePath + ".tmp") 33 | if err != nil { 34 | return err 35 | } 36 | defer out.Close() 37 | 38 | // Get the data 39 | resp, err := http.Get(v.DownloadLink) 40 | if err != nil { 41 | return err 42 | } 43 | defer resp.Body.Close() 44 | fmt.Printf("Downloading : %s \n", v.Size) 45 | // Create our progress reporter and pass it to be used alongside our writer 46 | counter := &WriteCounter{} 47 | _, err = io.Copy(out, io.TeeReader(resp.Body, counter)) 48 | if err != nil { 49 | return err 50 | } 51 | 52 | // The progress use the same line so print a new line once it's finished downloading 53 | fmt.Printf("\r%s", strings.Repeat(" ", 35)) 54 | fmt.Print("\rDownload complete") 55 | 56 | err = os.Rename(filePath+".tmp", filePath) 57 | if err != nil { 58 | return err 59 | } 60 | installPath := filepath.Join(config.InstallationDir, v.Name) 61 | if err := os.MkdirAll(installPath, os.ModePerm); err != nil { 62 | return err 63 | } 64 | fmt.Println("\rExtracting \n") 65 | err = archiver.TarGz.Open(filePath, installPath) 66 | 67 | return err 68 | } 69 | 70 | type WriteCounter struct { 71 | Total uint64 72 | } 73 | 74 | func (wc *WriteCounter) Write(p []byte) (int, error) { 75 | n := len(p) 76 | wc.Total += uint64(n) 77 | wc.PrintProgress() 78 | return n, nil 79 | } 80 | 81 | func (wc WriteCounter) PrintProgress() { 82 | // Clear the line by using a character return to go back to the start and remove 83 | // the remaining characters by filling it with spaces 84 | fmt.Printf("\r%s", strings.Repeat(" ", 35)) 85 | 86 | // Return again and print current status of download 87 | // We use the humanize package to print the bytes in a meaningful way (e.g. 10 MB) 88 | fmt.Printf("\rDownloading... %s complete", humanize.Bytes(wc.Total)) 89 | } 90 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/html/atom/atom.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package atom provides integer codes (also known as atoms) for a fixed set of 6 | // frequently occurring HTML strings: tag names and attribute keys such as "p" 7 | // and "id". 8 | // 9 | // Sharing an atom's name between all elements with the same tag can result in 10 | // fewer string allocations when tokenizing and parsing HTML. Integer 11 | // comparisons are also generally faster than string comparisons. 12 | // 13 | // The value of an atom's particular code is not guaranteed to stay the same 14 | // between versions of this package. Neither is any ordering guaranteed: 15 | // whether atom.H1 < atom.H2 may also change. The codes are not guaranteed to 16 | // be dense. The only guarantees are that e.g. looking up "div" will yield 17 | // atom.Div, calling atom.Div.String will return "div", and atom.Div != 0. 18 | package atom // import "golang.org/x/net/html/atom" 19 | 20 | // Atom is an integer code for a string. The zero value maps to "". 21 | type Atom uint32 22 | 23 | // String returns the atom's name. 24 | func (a Atom) String() string { 25 | start := uint32(a >> 8) 26 | n := uint32(a & 0xff) 27 | if start+n > uint32(len(atomText)) { 28 | return "" 29 | } 30 | return atomText[start : start+n] 31 | } 32 | 33 | func (a Atom) string() string { 34 | return atomText[a>>8 : a>>8+a&0xff] 35 | } 36 | 37 | // fnv computes the FNV hash with an arbitrary starting value h. 38 | func fnv(h uint32, s []byte) uint32 { 39 | for i := range s { 40 | h ^= uint32(s[i]) 41 | h *= 16777619 42 | } 43 | return h 44 | } 45 | 46 | func match(s string, t []byte) bool { 47 | for i, c := range t { 48 | if s[i] != c { 49 | return false 50 | } 51 | } 52 | return true 53 | } 54 | 55 | // Lookup returns the atom whose name is s. It returns zero if there is no 56 | // such atom. The lookup is case sensitive. 57 | func Lookup(s []byte) Atom { 58 | if len(s) == 0 || len(s) > maxAtomLen { 59 | return 0 60 | } 61 | h := fnv(hash0, s) 62 | if a := table[h&uint32(len(table)-1)]; int(a&0xff) == len(s) && match(a.string(), s) { 63 | return a 64 | } 65 | if a := table[(h>>16)&uint32(len(table)-1)]; int(a&0xff) == len(s) && match(a.string(), s) { 66 | return a 67 | } 68 | return 0 69 | } 70 | 71 | // String returns a string whose contents are equal to s. In that sense, it is 72 | // equivalent to string(s) but may be more efficient. 73 | func String(s []byte) string { 74 | if a := Lookup(s); a != 0 { 75 | return a.String() 76 | } 77 | return string(s) 78 | } 79 | -------------------------------------------------------------------------------- /vendor/github.com/dsnet/compress/api.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Joe Tsai. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE.md file. 4 | 5 | // Package compress is a collection of compression libraries. 6 | package compress 7 | 8 | import ( 9 | "bufio" 10 | "io" 11 | 12 | "github.com/dsnet/compress/internal/errors" 13 | ) 14 | 15 | // The Error interface identifies all compression related errors. 16 | type Error interface { 17 | error 18 | CompressError() 19 | 20 | // IsDeprecated reports the use of a deprecated and unsupported feature. 21 | IsDeprecated() bool 22 | 23 | // IsCorrupted reports whether the input stream was corrupted. 24 | IsCorrupted() bool 25 | } 26 | 27 | var _ Error = errors.Error{} 28 | 29 | // ByteReader is an interface accepted by all decompression Readers. 30 | // It guarantees that the decompressor never reads more data than is necessary 31 | // from the underlying io.Reader. 32 | type ByteReader interface { 33 | io.Reader 34 | io.ByteReader 35 | } 36 | 37 | var _ ByteReader = (*bufio.Reader)(nil) 38 | 39 | // BufferedReader is an interface accepted by all decompression Readers. 40 | // It guarantees that the decompressor never reads more data than is necessary 41 | // from the underlying io.Reader. Since BufferedReader allows a decompressor 42 | // to peek at bytes further along in the stream without advancing the read 43 | // pointer, decompression can experience a significant performance gain when 44 | // provided a reader that satisfies this interface. Thus, a decompressor will 45 | // prefer this interface over ByteReader for performance reasons. 46 | // 47 | // The bufio.Reader satisfies this interface. 48 | type BufferedReader interface { 49 | io.Reader 50 | 51 | // Buffered returns the number of bytes currently buffered. 52 | // 53 | // This value becomes invalid following the next Read/Discard operation. 54 | Buffered() int 55 | 56 | // Peek returns the next n bytes without advancing the reader. 57 | // 58 | // If Peek returns fewer than n bytes, it also returns an error explaining 59 | // why the peek is short. Peek must support peeking of at least 8 bytes. 60 | // If 0 <= n <= Buffered(), Peek is guaranteed to succeed without reading 61 | // from the underlying io.Reader. 62 | // 63 | // This result becomes invalid following the next Read/Discard operation. 64 | Peek(n int) ([]byte, error) 65 | 66 | // Discard skips the next n bytes, returning the number of bytes discarded. 67 | // 68 | // If Discard skips fewer than n bytes, it also returns an error. 69 | // If 0 <= n <= Buffered(), Discard is guaranteed to succeed without reading 70 | // from the underlying io.Reader. 71 | Discard(n int) (int, error) 72 | } 73 | 74 | var _ BufferedReader = (*bufio.Reader)(nil) 75 | -------------------------------------------------------------------------------- /vendor/github.com/dustin/go-humanize/comma.go: -------------------------------------------------------------------------------- 1 | package humanize 2 | 3 | import ( 4 | "bytes" 5 | "math" 6 | "math/big" 7 | "strconv" 8 | "strings" 9 | ) 10 | 11 | // Comma produces a string form of the given number in base 10 with 12 | // commas after every three orders of magnitude. 13 | // 14 | // e.g. Comma(834142) -> 834,142 15 | func Comma(v int64) string { 16 | sign := "" 17 | 18 | // Min int64 can't be negated to a usable value, so it has to be special cased. 19 | if v == math.MinInt64 { 20 | return "-9,223,372,036,854,775,808" 21 | } 22 | 23 | if v < 0 { 24 | sign = "-" 25 | v = 0 - v 26 | } 27 | 28 | parts := []string{"", "", "", "", "", "", ""} 29 | j := len(parts) - 1 30 | 31 | for v > 999 { 32 | parts[j] = strconv.FormatInt(v%1000, 10) 33 | switch len(parts[j]) { 34 | case 2: 35 | parts[j] = "0" + parts[j] 36 | case 1: 37 | parts[j] = "00" + parts[j] 38 | } 39 | v = v / 1000 40 | j-- 41 | } 42 | parts[j] = strconv.Itoa(int(v)) 43 | return sign + strings.Join(parts[j:], ",") 44 | } 45 | 46 | // Commaf produces a string form of the given number in base 10 with 47 | // commas after every three orders of magnitude. 48 | // 49 | // e.g. Commaf(834142.32) -> 834,142.32 50 | func Commaf(v float64) string { 51 | buf := &bytes.Buffer{} 52 | if v < 0 { 53 | buf.Write([]byte{'-'}) 54 | v = 0 - v 55 | } 56 | 57 | comma := []byte{','} 58 | 59 | parts := strings.Split(strconv.FormatFloat(v, 'f', -1, 64), ".") 60 | pos := 0 61 | if len(parts[0])%3 != 0 { 62 | pos += len(parts[0]) % 3 63 | buf.WriteString(parts[0][:pos]) 64 | buf.Write(comma) 65 | } 66 | for ; pos < len(parts[0]); pos += 3 { 67 | buf.WriteString(parts[0][pos : pos+3]) 68 | buf.Write(comma) 69 | } 70 | buf.Truncate(buf.Len() - 1) 71 | 72 | if len(parts) > 1 { 73 | buf.Write([]byte{'.'}) 74 | buf.WriteString(parts[1]) 75 | } 76 | return buf.String() 77 | } 78 | 79 | // BigComma produces a string form of the given big.Int in base 10 80 | // with commas after every three orders of magnitude. 81 | func BigComma(b *big.Int) string { 82 | sign := "" 83 | if b.Sign() < 0 { 84 | sign = "-" 85 | b.Abs(b) 86 | } 87 | 88 | athousand := big.NewInt(1000) 89 | c := (&big.Int{}).Set(b) 90 | _, m := oom(c, athousand) 91 | parts := make([]string, m+1) 92 | j := len(parts) - 1 93 | 94 | mod := &big.Int{} 95 | for b.Cmp(athousand) >= 0 { 96 | b.DivMod(b, athousand, mod) 97 | parts[j] = strconv.FormatInt(mod.Int64(), 10) 98 | switch len(parts[j]) { 99 | case 2: 100 | parts[j] = "0" + parts[j] 101 | case 1: 102 | parts[j] = "00" + parts[j] 103 | } 104 | j-- 105 | } 106 | parts[j] = strconv.Itoa(int(b.Int64())) 107 | return sign + strings.Join(parts[j:], ",") 108 | } 109 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | // +build !go1.4 3 | 4 | package mousetrap 5 | 6 | import ( 7 | "fmt" 8 | "os" 9 | "syscall" 10 | "unsafe" 11 | ) 12 | 13 | const ( 14 | // defined by the Win32 API 15 | th32cs_snapprocess uintptr = 0x2 16 | ) 17 | 18 | var ( 19 | kernel = syscall.MustLoadDLL("kernel32.dll") 20 | CreateToolhelp32Snapshot = kernel.MustFindProc("CreateToolhelp32Snapshot") 21 | Process32First = kernel.MustFindProc("Process32FirstW") 22 | Process32Next = kernel.MustFindProc("Process32NextW") 23 | ) 24 | 25 | // ProcessEntry32 structure defined by the Win32 API 26 | type processEntry32 struct { 27 | dwSize uint32 28 | cntUsage uint32 29 | th32ProcessID uint32 30 | th32DefaultHeapID int 31 | th32ModuleID uint32 32 | cntThreads uint32 33 | th32ParentProcessID uint32 34 | pcPriClassBase int32 35 | dwFlags uint32 36 | szExeFile [syscall.MAX_PATH]uint16 37 | } 38 | 39 | func getProcessEntry(pid int) (pe *processEntry32, err error) { 40 | snapshot, _, e1 := CreateToolhelp32Snapshot.Call(th32cs_snapprocess, uintptr(0)) 41 | if snapshot == uintptr(syscall.InvalidHandle) { 42 | err = fmt.Errorf("CreateToolhelp32Snapshot: %v", e1) 43 | return 44 | } 45 | defer syscall.CloseHandle(syscall.Handle(snapshot)) 46 | 47 | var processEntry processEntry32 48 | processEntry.dwSize = uint32(unsafe.Sizeof(processEntry)) 49 | ok, _, e1 := Process32First.Call(snapshot, uintptr(unsafe.Pointer(&processEntry))) 50 | if ok == 0 { 51 | err = fmt.Errorf("Process32First: %v", e1) 52 | return 53 | } 54 | 55 | for { 56 | if processEntry.th32ProcessID == uint32(pid) { 57 | pe = &processEntry 58 | return 59 | } 60 | 61 | ok, _, e1 = Process32Next.Call(snapshot, uintptr(unsafe.Pointer(&processEntry))) 62 | if ok == 0 { 63 | err = fmt.Errorf("Process32Next: %v", e1) 64 | return 65 | } 66 | } 67 | } 68 | 69 | func getppid() (pid int, err error) { 70 | pe, err := getProcessEntry(os.Getpid()) 71 | if err != nil { 72 | return 73 | } 74 | 75 | pid = int(pe.th32ParentProcessID) 76 | return 77 | } 78 | 79 | // StartedByExplorer returns true if the program was invoked by the user double-clicking 80 | // on the executable from explorer.exe 81 | // 82 | // It is conservative and returns false if any of the internal calls fail. 83 | // It does not guarantee that the program was run from a terminal. It only can tell you 84 | // whether it was launched from explorer.exe 85 | func StartedByExplorer() bool { 86 | ppid, err := getppid() 87 | if err != nil { 88 | return false 89 | } 90 | 91 | pe, err := getProcessEntry(ppid) 92 | if err != nil { 93 | return false 94 | } 95 | 96 | name := syscall.UTF16ToString(pe.szExeFile[:]) 97 | return name == "explorer.exe" 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/mholt/archiver/README.md: -------------------------------------------------------------------------------- 1 | archiver [![archiver GoDoc](https://img.shields.io/badge/reference-godoc-blue.svg?style=flat-square)](https://godoc.org/github.com/mholt/archiver) [![Linux Build Status](https://img.shields.io/travis/mholt/archiver.svg?style=flat-square&label=linux+build)](https://travis-ci.org/mholt/archiver) [![Windows Build Status](https://img.shields.io/appveyor/ci/mholt/archiver.svg?style=flat-square&label=windows+build)](https://ci.appveyor.com/project/mholt/archiver) 2 | ======== 3 | 4 | Package archiver makes it trivially easy to make and extract common archive formats such as .zip, and .tar.gz. Simply name the input and output file(s). 5 | 6 | Files are put into the root of the archive; directories are recursively added, preserving structure. 7 | 8 | The `archiver` command runs the same cross-platform and has no external dependencies (not even libc); powered by the Go standard library, [dsnet/compress](https://github.com/dsnet/compress), [nwaples/rardecode](https://github.com/nwaples/rardecode), and [ulikunitz/xz](https://github.com/ulikunitz/xz). Enjoy! 9 | 10 | Supported formats/extensions: 11 | 12 | - .zip 13 | - .tar 14 | - .tar.gz & .tgz 15 | - .tar.bz2 & .tbz2 16 | - .tar.xz & .txz 17 | - .rar (open only) 18 | 19 | 20 | ## Install 21 | 22 | ```bash 23 | go get github.com/mholt/archiver/cmd/archiver 24 | ``` 25 | 26 | Or download binaries from the [releases](https://github.com/mholt/archiver/releases) page. 27 | 28 | 29 | ## Command Use 30 | 31 | Make a new archive: 32 | 33 | ```bash 34 | $ archiver make [archive name] [input files...] 35 | ``` 36 | 37 | (At least one input file is required.) 38 | 39 | To extract an archive: 40 | 41 | ```bash 42 | $ archiver open [archive name] [destination] 43 | ``` 44 | 45 | (The destination path is optional; default is current directory.) 46 | 47 | The archive name must end with a supported file extension—this is how it knows what kind of archive to make. Run `archiver -h` for more help. 48 | 49 | 50 | ## Library Use 51 | 52 | ```go 53 | import "github.com/mholt/archiver" 54 | ``` 55 | 56 | Create a .zip file: 57 | 58 | ```go 59 | err := archiver.Zip.Make("output.zip", []string{"file.txt", "folder"}) 60 | ``` 61 | 62 | Extract a .zip file: 63 | 64 | ```go 65 | err := archiver.Zip.Open("input.zip", "output_folder") 66 | ``` 67 | 68 | Working with other file formats is exactly the same, but with [their own Archiver implementations](https://godoc.org/github.com/mholt/archiver#Archiver). 69 | 70 | 71 | 72 | ## FAQ 73 | 74 | #### Can I list a file in one folder to go into a different folder in the archive? 75 | 76 | No. This works just like your OS would make an archive in the file explorer: organize your input files to mirror the structure you want in the archive. 77 | 78 | 79 | #### Can it add files to an existing archive? 80 | 81 | Nope. This is a simple tool; it just makes new archives or extracts existing ones. 82 | -------------------------------------------------------------------------------- /vendor/github.com/nwaples/rardecode/decode29_ppm.go: -------------------------------------------------------------------------------- 1 | package rardecode 2 | 3 | import "io" 4 | 5 | type ppm29Decoder struct { 6 | m model // ppm model 7 | esc byte // escape character 8 | br io.ByteReader 9 | } 10 | 11 | func (d *ppm29Decoder) init(br *rarBitReader) error { 12 | maxOrder, err := br.readBits(7) 13 | if err != nil { 14 | return err 15 | } 16 | reset := maxOrder&0x20 > 0 17 | 18 | // Should have flushed all unread bits from bitReader by now, 19 | // use underlying ByteReader 20 | d.br = br.r 21 | 22 | var maxMB int 23 | if reset { 24 | c, err := d.br.ReadByte() 25 | if err != nil { 26 | return err 27 | } 28 | maxMB = int(c) + 1 29 | } 30 | 31 | if maxOrder&0x40 > 0 { 32 | d.esc, err = d.br.ReadByte() 33 | if err != nil { 34 | return err 35 | } 36 | } 37 | 38 | maxOrder = (maxOrder & 0x1f) + 1 39 | if maxOrder > 16 { 40 | maxOrder = 16 + (maxOrder-16)*3 41 | } 42 | 43 | return d.m.init(d.br, reset, maxOrder, maxMB) 44 | } 45 | 46 | func (d *ppm29Decoder) reset() { 47 | d.esc = 2 48 | } 49 | 50 | func (d *ppm29Decoder) readFilterData() ([]byte, error) { 51 | c, err := d.m.ReadByte() 52 | if err != nil { 53 | return nil, err 54 | } 55 | n := int(c&7) + 1 56 | if n == 7 { 57 | b, err := d.m.ReadByte() 58 | if err != nil { 59 | return nil, err 60 | } 61 | n += int(b) 62 | } else if n == 8 { 63 | b, err := d.m.ReadByte() 64 | if err != nil { 65 | return nil, err 66 | } 67 | n = int(b) << 8 68 | b, err = d.m.ReadByte() 69 | if err != nil { 70 | return nil, err 71 | } 72 | n |= int(b) 73 | } 74 | 75 | n++ 76 | buf := make([]byte, n) 77 | buf[0] = byte(c) 78 | for i := 1; i < n; i++ { 79 | buf[i], err = d.m.ReadByte() 80 | if err != nil { 81 | return nil, err 82 | } 83 | } 84 | return buf, nil 85 | } 86 | 87 | func (d *ppm29Decoder) decode(w *window) ([]byte, error) { 88 | c, err := d.m.ReadByte() 89 | if err != nil { 90 | return nil, err 91 | } 92 | if c != d.esc { 93 | w.writeByte(c) 94 | return nil, nil 95 | } 96 | c, err = d.m.ReadByte() 97 | if err != nil { 98 | return nil, err 99 | } 100 | 101 | switch c { 102 | case 0: 103 | return nil, endOfBlock 104 | case 2: 105 | return nil, endOfBlockAndFile 106 | case 3: 107 | return d.readFilterData() 108 | case 4: 109 | offset := 0 110 | for i := 0; i < 3; i++ { 111 | c, err = d.m.ReadByte() 112 | if err != nil { 113 | return nil, err 114 | } 115 | offset = offset<<8 | int(c) 116 | } 117 | len, err := d.m.ReadByte() 118 | if err != nil { 119 | return nil, err 120 | } 121 | w.copyBytes(int(len)+32, offset+2) 122 | case 5: 123 | len, err := d.m.ReadByte() 124 | if err != nil { 125 | return nil, err 126 | } 127 | w.copyBytes(int(len)+4, 1) 128 | default: 129 | w.writeByte(d.esc) 130 | } 131 | return nil, nil 132 | } 133 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/args.go: -------------------------------------------------------------------------------- 1 | package cobra 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type PositionalArgs func(cmd *Command, args []string) error 8 | 9 | // Legacy arg validation has the following behaviour: 10 | // - root commands with no subcommands can take arbitrary arguments 11 | // - root commands with subcommands will do subcommand validity checking 12 | // - subcommands will always accept arbitrary arguments 13 | func legacyArgs(cmd *Command, args []string) error { 14 | // no subcommand, always take args 15 | if !cmd.HasSubCommands() { 16 | return nil 17 | } 18 | 19 | // root command with subcommands, do subcommand checking. 20 | if !cmd.HasParent() && len(args) > 0 { 21 | return fmt.Errorf("unknown command %q for %q%s", args[0], cmd.CommandPath(), cmd.findSuggestions(args[0])) 22 | } 23 | return nil 24 | } 25 | 26 | // NoArgs returns an error if any args are included. 27 | func NoArgs(cmd *Command, args []string) error { 28 | if len(args) > 0 { 29 | return fmt.Errorf("unknown command %q for %q", args[0], cmd.CommandPath()) 30 | } 31 | return nil 32 | } 33 | 34 | // OnlyValidArgs returns an error if any args are not in the list of ValidArgs. 35 | func OnlyValidArgs(cmd *Command, args []string) error { 36 | if len(cmd.ValidArgs) > 0 { 37 | for _, v := range args { 38 | if !stringInSlice(v, cmd.ValidArgs) { 39 | return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.findSuggestions(args[0])) 40 | } 41 | } 42 | } 43 | return nil 44 | } 45 | 46 | // ArbitraryArgs never returns an error. 47 | func ArbitraryArgs(cmd *Command, args []string) error { 48 | return nil 49 | } 50 | 51 | // MinimumNArgs returns an error if there is not at least N args. 52 | func MinimumNArgs(n int) PositionalArgs { 53 | return func(cmd *Command, args []string) error { 54 | if len(args) < n { 55 | return fmt.Errorf("requires at least %d arg(s), only received %d", n, len(args)) 56 | } 57 | return nil 58 | } 59 | } 60 | 61 | // MaximumNArgs returns an error if there are more than N args. 62 | func MaximumNArgs(n int) PositionalArgs { 63 | return func(cmd *Command, args []string) error { 64 | if len(args) > n { 65 | return fmt.Errorf("accepts at most %d arg(s), received %d", n, len(args)) 66 | } 67 | return nil 68 | } 69 | } 70 | 71 | // ExactArgs returns an error if there are not exactly n args. 72 | func ExactArgs(n int) PositionalArgs { 73 | return func(cmd *Command, args []string) error { 74 | if len(args) != n { 75 | return fmt.Errorf("accepts %d arg(s), received %d", n, len(args)) 76 | } 77 | return nil 78 | } 79 | } 80 | 81 | // RangeArgs returns an error if the number of args is not within the expected range. 82 | func RangeArgs(min int, max int) PositionalArgs { 83 | return func(cmd *Command, args []string) error { 84 | if len(args) < min || len(args) > max { 85 | return fmt.Errorf("accepts between %d and %d arg(s), received %d", min, max, len(args)) 86 | } 87 | return nil 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/dsnet/compress/internal/prefix/range.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Joe Tsai. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE.md file. 4 | 5 | package prefix 6 | 7 | type RangeCode struct { 8 | Base uint32 // Starting base offset of the range 9 | Len uint32 // Bit-length of a subsequent integer to add to base offset 10 | } 11 | type RangeCodes []RangeCode 12 | 13 | type RangeEncoder struct { 14 | rcs RangeCodes 15 | lut [1024]uint32 16 | minBase uint 17 | } 18 | 19 | // End reports the non-inclusive ending range. 20 | func (rc RangeCode) End() uint32 { return rc.Base + (1 << rc.Len) } 21 | 22 | // MakeRangeCodes creates a RangeCodes, where each region is assumed to be 23 | // contiguously stacked, without any gaps, with bit-lengths taken from bits. 24 | func MakeRangeCodes(minBase uint, bits []uint) (rc RangeCodes) { 25 | for _, nb := range bits { 26 | rc = append(rc, RangeCode{Base: uint32(minBase), Len: uint32(nb)}) 27 | minBase += 1 << nb 28 | } 29 | return rc 30 | } 31 | 32 | // Base reports the inclusive starting range for all ranges. 33 | func (rcs RangeCodes) Base() uint32 { return rcs[0].Base } 34 | 35 | // End reports the non-inclusive ending range for all ranges. 36 | func (rcs RangeCodes) End() uint32 { return rcs[len(rcs)-1].End() } 37 | 38 | // checkValid reports whether the RangeCodes is valid. In order to be valid, 39 | // the following must hold true: 40 | // rcs[i-1].Base <= rcs[i].Base 41 | // rcs[i-1].End <= rcs[i].End 42 | // rcs[i-1].End >= rcs[i].Base 43 | // 44 | // Practically speaking, each range must be increasing and must not have any 45 | // gaps in between. It is okay for ranges to overlap. 46 | func (rcs RangeCodes) checkValid() bool { 47 | if len(rcs) == 0 { 48 | return false 49 | } 50 | pre := rcs[0] 51 | for _, cur := range rcs[1:] { 52 | preBase, preEnd := pre.Base, pre.End() 53 | curBase, curEnd := cur.Base, cur.End() 54 | if preBase > curBase || preEnd > curEnd || preEnd < curBase { 55 | return false 56 | } 57 | pre = cur 58 | } 59 | return true 60 | } 61 | 62 | func (re *RangeEncoder) Init(rcs RangeCodes) { 63 | if !rcs.checkValid() { 64 | panic("invalid range codes") 65 | } 66 | *re = RangeEncoder{rcs: rcs, minBase: uint(rcs.Base())} 67 | for sym, rc := range rcs { 68 | base := int(rc.Base) - int(re.minBase) 69 | end := int(rc.End()) - int(re.minBase) 70 | if base >= len(re.lut) { 71 | break 72 | } 73 | if end > len(re.lut) { 74 | end = len(re.lut) 75 | } 76 | for i := base; i < end; i++ { 77 | re.lut[i] = uint32(sym) 78 | } 79 | } 80 | } 81 | 82 | func (re *RangeEncoder) Encode(offset uint) (sym uint) { 83 | if idx := int(offset - re.minBase); idx < len(re.lut) { 84 | return uint(re.lut[idx]) 85 | } 86 | sym = uint(re.lut[len(re.lut)-1]) 87 | retry: 88 | if int(sym) >= len(re.rcs) || re.rcs[sym].Base > uint32(offset) { 89 | return sym - 1 90 | } 91 | sym++ 92 | goto retry // Avoid for-loop so that this function can be inlined 93 | } 94 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/html/const.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package html 6 | 7 | // Section 12.2.4.2 of the HTML5 specification says "The following elements 8 | // have varying levels of special parsing rules". 9 | // https://html.spec.whatwg.org/multipage/syntax.html#the-stack-of-open-elements 10 | var isSpecialElementMap = map[string]bool{ 11 | "address": true, 12 | "applet": true, 13 | "area": true, 14 | "article": true, 15 | "aside": true, 16 | "base": true, 17 | "basefont": true, 18 | "bgsound": true, 19 | "blockquote": true, 20 | "body": true, 21 | "br": true, 22 | "button": true, 23 | "caption": true, 24 | "center": true, 25 | "col": true, 26 | "colgroup": true, 27 | "dd": true, 28 | "details": true, 29 | "dir": true, 30 | "div": true, 31 | "dl": true, 32 | "dt": true, 33 | "embed": true, 34 | "fieldset": true, 35 | "figcaption": true, 36 | "figure": true, 37 | "footer": true, 38 | "form": true, 39 | "frame": true, 40 | "frameset": true, 41 | "h1": true, 42 | "h2": true, 43 | "h3": true, 44 | "h4": true, 45 | "h5": true, 46 | "h6": true, 47 | "head": true, 48 | "header": true, 49 | "hgroup": true, 50 | "hr": true, 51 | "html": true, 52 | "iframe": true, 53 | "img": true, 54 | "input": true, 55 | "isindex": true, // The 'isindex' element has been removed, but keep it for backwards compatibility. 56 | "keygen": true, 57 | "li": true, 58 | "link": true, 59 | "listing": true, 60 | "main": true, 61 | "marquee": true, 62 | "menu": true, 63 | "meta": true, 64 | "nav": true, 65 | "noembed": true, 66 | "noframes": true, 67 | "noscript": true, 68 | "object": true, 69 | "ol": true, 70 | "p": true, 71 | "param": true, 72 | "plaintext": true, 73 | "pre": true, 74 | "script": true, 75 | "section": true, 76 | "select": true, 77 | "source": true, 78 | "style": true, 79 | "summary": true, 80 | "table": true, 81 | "tbody": true, 82 | "td": true, 83 | "template": true, 84 | "textarea": true, 85 | "tfoot": true, 86 | "th": true, 87 | "thead": true, 88 | "title": true, 89 | "tr": true, 90 | "track": true, 91 | "ul": true, 92 | "wbr": true, 93 | "xmp": true, 94 | } 95 | 96 | func isSpecialElement(element *Node) bool { 97 | switch element.Namespace { 98 | case "", "html": 99 | return isSpecialElementMap[element.Data] 100 | case "svg": 101 | return element.Data == "foreignObject" 102 | } 103 | return false 104 | } 105 | -------------------------------------------------------------------------------- /vendor/github.com/PuerkitoBio/goquery/expand.go: -------------------------------------------------------------------------------- 1 | package goquery 2 | 3 | import "golang.org/x/net/html" 4 | 5 | // Add adds the selector string's matching nodes to those in the current 6 | // selection and returns a new Selection object. 7 | // The selector string is run in the context of the document of the current 8 | // Selection object. 9 | func (s *Selection) Add(selector string) *Selection { 10 | return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, compileMatcher(selector))...) 11 | } 12 | 13 | // AddMatcher adds the matcher's matching nodes to those in the current 14 | // selection and returns a new Selection object. 15 | // The matcher is run in the context of the document of the current 16 | // Selection object. 17 | func (s *Selection) AddMatcher(m Matcher) *Selection { 18 | return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, m)...) 19 | } 20 | 21 | // AddSelection adds the specified Selection object's nodes to those in the 22 | // current selection and returns a new Selection object. 23 | func (s *Selection) AddSelection(sel *Selection) *Selection { 24 | if sel == nil { 25 | return s.AddNodes() 26 | } 27 | return s.AddNodes(sel.Nodes...) 28 | } 29 | 30 | // Union is an alias for AddSelection. 31 | func (s *Selection) Union(sel *Selection) *Selection { 32 | return s.AddSelection(sel) 33 | } 34 | 35 | // AddNodes adds the specified nodes to those in the 36 | // current selection and returns a new Selection object. 37 | func (s *Selection) AddNodes(nodes ...*html.Node) *Selection { 38 | return pushStack(s, appendWithoutDuplicates(s.Nodes, nodes, nil)) 39 | } 40 | 41 | // AndSelf adds the previous set of elements on the stack to the current set. 42 | // It returns a new Selection object containing the current Selection combined 43 | // with the previous one. 44 | // Deprecated: This function has been deprecated and is now an alias for AddBack(). 45 | func (s *Selection) AndSelf() *Selection { 46 | return s.AddBack() 47 | } 48 | 49 | // AddBack adds the previous set of elements on the stack to the current set. 50 | // It returns a new Selection object containing the current Selection combined 51 | // with the previous one. 52 | func (s *Selection) AddBack() *Selection { 53 | return s.AddSelection(s.prevSel) 54 | } 55 | 56 | // AddBackFiltered reduces the previous set of elements on the stack to those that 57 | // match the selector string, and adds them to the current set. 58 | // It returns a new Selection object containing the current Selection combined 59 | // with the filtered previous one 60 | func (s *Selection) AddBackFiltered(selector string) *Selection { 61 | return s.AddSelection(s.prevSel.Filter(selector)) 62 | } 63 | 64 | // AddBackMatcher reduces the previous set of elements on the stack to those that match 65 | // the mateher, and adds them to the curernt set. 66 | // It returns a new Selection object containing the current Selection combined 67 | // with the filtered previous one 68 | func (s *Selection) AddBackMatcher(m Matcher) *Selection { 69 | return s.AddSelection(s.prevSel.FilterMatcher(m)) 70 | } 71 | -------------------------------------------------------------------------------- /vendor/github.com/dustin/go-humanize/si.go: -------------------------------------------------------------------------------- 1 | package humanize 2 | 3 | import ( 4 | "errors" 5 | "math" 6 | "regexp" 7 | "strconv" 8 | ) 9 | 10 | var siPrefixTable = map[float64]string{ 11 | -24: "y", // yocto 12 | -21: "z", // zepto 13 | -18: "a", // atto 14 | -15: "f", // femto 15 | -12: "p", // pico 16 | -9: "n", // nano 17 | -6: "µ", // micro 18 | -3: "m", // milli 19 | 0: "", 20 | 3: "k", // kilo 21 | 6: "M", // mega 22 | 9: "G", // giga 23 | 12: "T", // tera 24 | 15: "P", // peta 25 | 18: "E", // exa 26 | 21: "Z", // zetta 27 | 24: "Y", // yotta 28 | } 29 | 30 | var revSIPrefixTable = revfmap(siPrefixTable) 31 | 32 | // revfmap reverses the map and precomputes the power multiplier 33 | func revfmap(in map[float64]string) map[string]float64 { 34 | rv := map[string]float64{} 35 | for k, v := range in { 36 | rv[v] = math.Pow(10, k) 37 | } 38 | return rv 39 | } 40 | 41 | var riParseRegex *regexp.Regexp 42 | 43 | func init() { 44 | ri := `^([\-0-9.]+)\s?([` 45 | for _, v := range siPrefixTable { 46 | ri += v 47 | } 48 | ri += `]?)(.*)` 49 | 50 | riParseRegex = regexp.MustCompile(ri) 51 | } 52 | 53 | // ComputeSI finds the most appropriate SI prefix for the given number 54 | // and returns the prefix along with the value adjusted to be within 55 | // that prefix. 56 | // 57 | // See also: SI, ParseSI. 58 | // 59 | // e.g. ComputeSI(2.2345e-12) -> (2.2345, "p") 60 | func ComputeSI(input float64) (float64, string) { 61 | if input == 0 { 62 | return 0, "" 63 | } 64 | mag := math.Abs(input) 65 | exponent := math.Floor(logn(mag, 10)) 66 | exponent = math.Floor(exponent/3) * 3 67 | 68 | value := mag / math.Pow(10, exponent) 69 | 70 | // Handle special case where value is exactly 1000.0 71 | // Should return 1 M instead of 1000 k 72 | if value == 1000.0 { 73 | exponent += 3 74 | value = mag / math.Pow(10, exponent) 75 | } 76 | 77 | value = math.Copysign(value, input) 78 | 79 | prefix := siPrefixTable[exponent] 80 | return value, prefix 81 | } 82 | 83 | // SI returns a string with default formatting. 84 | // 85 | // SI uses Ftoa to format float value, removing trailing zeros. 86 | // 87 | // See also: ComputeSI, ParseSI. 88 | // 89 | // e.g. SI(1000000, "B") -> 1 MB 90 | // e.g. SI(2.2345e-12, "F") -> 2.2345 pF 91 | func SI(input float64, unit string) string { 92 | value, prefix := ComputeSI(input) 93 | return Ftoa(value) + " " + prefix + unit 94 | } 95 | 96 | var errInvalid = errors.New("invalid input") 97 | 98 | // ParseSI parses an SI string back into the number and unit. 99 | // 100 | // See also: SI, ComputeSI. 101 | // 102 | // e.g. ParseSI("2.2345 pF") -> (2.2345e-12, "F", nil) 103 | func ParseSI(input string) (float64, string, error) { 104 | found := riParseRegex.FindStringSubmatch(input) 105 | if len(found) != 4 { 106 | return 0, "", errInvalid 107 | } 108 | mag := revSIPrefixTable[found[2]] 109 | unit := found[3] 110 | 111 | base, err := strconv.ParseFloat(found[1], 64) 112 | return base * mag, unit, err 113 | } 114 | -------------------------------------------------------------------------------- /vendor/github.com/dsnet/compress/bzip2/rle1.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Joe Tsai. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE.md file. 4 | 5 | package bzip2 6 | 7 | import "github.com/dsnet/compress/internal/errors" 8 | 9 | // rleDone is a special "error" to indicate that the RLE stage is done. 10 | var rleDone = errorf(errors.Unknown, "RLE1 stage is completed") 11 | 12 | // runLengthEncoding implements the first RLE stage of bzip2. Every sequence 13 | // of 4..255 duplicated bytes is replaced by only the first 4 bytes, and a 14 | // single byte representing the repeat length. Similar to the C bzip2 15 | // implementation, the encoder will always terminate repeat sequences with a 16 | // count (even if it is the end of the buffer), and it will also never produce 17 | // run lengths of 256..259. The decoder can handle the latter case. 18 | // 19 | // For example, if the input was: 20 | // input: "AAAAAAABBBBCCCD" 21 | // 22 | // Then the output will be: 23 | // output: "AAAA\x03BBBB\x00CCCD" 24 | type runLengthEncoding struct { 25 | buf []byte 26 | idx int 27 | lastVal byte 28 | lastCnt int 29 | } 30 | 31 | func (rle *runLengthEncoding) Init(buf []byte) { 32 | *rle = runLengthEncoding{buf: buf} 33 | } 34 | 35 | func (rle *runLengthEncoding) Write(buf []byte) (int, error) { 36 | for i, b := range buf { 37 | if rle.lastVal != b { 38 | rle.lastCnt = 0 39 | } 40 | rle.lastCnt++ 41 | switch { 42 | case rle.lastCnt < 4: 43 | if rle.idx >= len(rle.buf) { 44 | return i, rleDone 45 | } 46 | rle.buf[rle.idx] = b 47 | rle.idx++ 48 | case rle.lastCnt == 4: 49 | if rle.idx+1 >= len(rle.buf) { 50 | return i, rleDone 51 | } 52 | rle.buf[rle.idx] = b 53 | rle.idx++ 54 | rle.buf[rle.idx] = 0 55 | rle.idx++ 56 | case rle.lastCnt < 256: 57 | rle.buf[rle.idx-1]++ 58 | default: 59 | if rle.idx >= len(rle.buf) { 60 | return i, rleDone 61 | } 62 | rle.lastCnt = 1 63 | rle.buf[rle.idx] = b 64 | rle.idx++ 65 | } 66 | rle.lastVal = b 67 | } 68 | return len(buf), nil 69 | } 70 | 71 | func (rle *runLengthEncoding) Read(buf []byte) (int, error) { 72 | for i := range buf { 73 | switch { 74 | case rle.lastCnt == -4: 75 | if rle.idx >= len(rle.buf) { 76 | return i, errorf(errors.Corrupted, "missing terminating run-length repeater") 77 | } 78 | rle.lastCnt = int(rle.buf[rle.idx]) 79 | rle.idx++ 80 | if rle.lastCnt > 0 { 81 | break // Break the switch 82 | } 83 | fallthrough // Count was zero, continue the work 84 | case rle.lastCnt <= 0: 85 | if rle.idx >= len(rle.buf) { 86 | return i, rleDone 87 | } 88 | b := rle.buf[rle.idx] 89 | rle.idx++ 90 | if b != rle.lastVal { 91 | rle.lastCnt = 0 92 | rle.lastVal = b 93 | } 94 | } 95 | buf[i] = rle.lastVal 96 | rle.lastCnt-- 97 | } 98 | return len(buf), nil 99 | } 100 | 101 | func (rle *runLengthEncoding) Bytes() []byte { return rle.buf[:rle.idx] } 102 | -------------------------------------------------------------------------------- /vendor/github.com/nwaples/rardecode/bit_reader.go: -------------------------------------------------------------------------------- 1 | package rardecode 2 | 3 | import "io" 4 | 5 | type bitReader interface { 6 | readBits(n uint) (int, error) // read n bits of data 7 | unreadBits(n uint) // revert the reading of the last n bits read 8 | } 9 | 10 | type limitedBitReader struct { 11 | br bitReader 12 | n int 13 | err error // error to return if br returns EOF before all n bits have been read 14 | } 15 | 16 | // limitBitReader returns a bitReader that reads from br and stops with io.EOF after n bits. 17 | // If br returns an io.EOF before reading n bits, err is returned. 18 | func limitBitReader(br bitReader, n int, err error) bitReader { 19 | return &limitedBitReader{br, n, err} 20 | } 21 | 22 | func (l *limitedBitReader) readBits(n uint) (int, error) { 23 | if int(n) > l.n { 24 | return 0, io.EOF 25 | } 26 | v, err := l.br.readBits(n) 27 | if err == nil { 28 | l.n -= int(n) 29 | } else if err == io.EOF { 30 | err = l.err 31 | } 32 | return v, err 33 | } 34 | 35 | func (l *limitedBitReader) unreadBits(n uint) { 36 | l.n += int(n) 37 | l.br.unreadBits(n) 38 | } 39 | 40 | // rarBitReader wraps an io.ByteReader to perform various bit and byte 41 | // reading utility functions used in RAR file processing. 42 | type rarBitReader struct { 43 | r io.ByteReader 44 | v int 45 | n uint 46 | } 47 | 48 | func (r *rarBitReader) reset(br io.ByteReader) { 49 | r.r = br 50 | r.n = 0 51 | r.v = 0 52 | } 53 | 54 | func (r *rarBitReader) readBits(n uint) (int, error) { 55 | for n > r.n { 56 | c, err := r.r.ReadByte() 57 | if err != nil { 58 | return 0, err 59 | } 60 | r.v = r.v<<8 | int(c) 61 | r.n += 8 62 | } 63 | r.n -= n 64 | return (r.v >> r.n) & ((1 << n) - 1), nil 65 | } 66 | 67 | func (r *rarBitReader) unreadBits(n uint) { 68 | r.n += n 69 | } 70 | 71 | // alignByte aligns the current bit reading input to the next byte boundary. 72 | func (r *rarBitReader) alignByte() { 73 | r.n -= r.n % 8 74 | } 75 | 76 | // readUint32 reads a RAR V3 encoded uint32 77 | func (r *rarBitReader) readUint32() (uint32, error) { 78 | n, err := r.readBits(2) 79 | if err != nil { 80 | return 0, err 81 | } 82 | if n != 1 { 83 | n, err = r.readBits(4 << uint(n)) 84 | return uint32(n), err 85 | } 86 | n, err = r.readBits(4) 87 | if err != nil { 88 | return 0, err 89 | } 90 | if n == 0 { 91 | n, err = r.readBits(8) 92 | n |= -1 << 8 93 | return uint32(n), err 94 | } 95 | nlow, err := r.readBits(4) 96 | n = n<<4 | nlow 97 | return uint32(n), err 98 | } 99 | 100 | func (r *rarBitReader) ReadByte() (byte, error) { 101 | n, err := r.readBits(8) 102 | return byte(n), err 103 | } 104 | 105 | // readFull reads len(p) bytes into p. If fewer bytes are read an error is returned. 106 | func (r *rarBitReader) readFull(p []byte) error { 107 | for i := range p { 108 | c, err := r.ReadByte() 109 | if err != nil { 110 | return err 111 | } 112 | p[i] = c 113 | } 114 | return nil 115 | } 116 | 117 | func newRarBitReader(r io.ByteReader) *rarBitReader { 118 | return &rarBitReader{r: r} 119 | } 120 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int Value 6 | type intValue int 7 | 8 | func newIntValue(val int, p *int) *intValue { 9 | *p = val 10 | return (*intValue)(p) 11 | } 12 | 13 | func (i *intValue) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | *i = intValue(v) 16 | return err 17 | } 18 | 19 | func (i *intValue) Type() string { 20 | return "int" 21 | } 22 | 23 | func (i *intValue) String() string { return strconv.Itoa(int(*i)) } 24 | 25 | func intConv(sval string) (interface{}, error) { 26 | return strconv.Atoi(sval) 27 | } 28 | 29 | // GetInt return the int value of a flag with the given name 30 | func (f *FlagSet) GetInt(name string) (int, error) { 31 | val, err := f.getFlagType(name, "int", intConv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(int), nil 36 | } 37 | 38 | // IntVar defines an int flag with specified name, default value, and usage string. 39 | // The argument p points to an int variable in which to store the value of the flag. 40 | func (f *FlagSet) IntVar(p *int, name string, value int, usage string) { 41 | f.VarP(newIntValue(value, p), name, "", usage) 42 | } 43 | 44 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) { 46 | f.VarP(newIntValue(value, p), name, shorthand, usage) 47 | } 48 | 49 | // IntVar defines an int flag with specified name, default value, and usage string. 50 | // The argument p points to an int variable in which to store the value of the flag. 51 | func IntVar(p *int, name string, value int, usage string) { 52 | CommandLine.VarP(newIntValue(value, p), name, "", usage) 53 | } 54 | 55 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. 56 | func IntVarP(p *int, name, shorthand string, value int, usage string) { 57 | CommandLine.VarP(newIntValue(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Int defines an int flag with specified name, default value, and usage string. 61 | // The return value is the address of an int variable that stores the value of the flag. 62 | func (f *FlagSet) Int(name string, value int, usage string) *int { 63 | p := new(int) 64 | f.IntVarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int { 70 | p := new(int) 71 | f.IntVarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Int defines an int flag with specified name, default value, and usage string. 76 | // The return value is the address of an int variable that stores the value of the flag. 77 | func Int(name string, value int, usage string) *int { 78 | return CommandLine.IntP(name, "", value, usage) 79 | } 80 | 81 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 82 | func IntP(name, shorthand string, value int, usage string) *int { 83 | return CommandLine.IntP(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/cobra/cmd/license_mit.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Steve Francia . 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Parts inspired by https://github.com/ryanuber/go-license 15 | 16 | package cmd 17 | 18 | func initMit() { 19 | Licenses["mit"] = License{ 20 | Name: "MIT License", 21 | PossibleMatches: []string{"mit"}, 22 | Header: ` 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 38 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 39 | THE SOFTWARE.`, 40 | Text: `The MIT License (MIT) 41 | 42 | {{ .copyright }} 43 | 44 | Permission is hereby granted, free of charge, to any person obtaining a copy 45 | of this software and associated documentation files (the "Software"), to deal 46 | in the Software without restriction, including without limitation the rights 47 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 48 | copies of the Software, and to permit persons to whom the Software is 49 | furnished to do so, subject to the following conditions: 50 | 51 | The above copyright notice and this permission notice shall be included in 52 | all copies or substantial portions of the Software. 53 | 54 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 55 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 56 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 57 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 58 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 59 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 60 | THE SOFTWARE. 61 | `, 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/lzma/reader.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package lzma supports the decoding and encoding of LZMA streams. 6 | // Reader and Writer support the classic LZMA format. Reader2 and 7 | // Writer2 support the decoding and encoding of LZMA2 streams. 8 | // 9 | // The package is written completely in Go and doesn't rely on any external 10 | // library. 11 | package lzma 12 | 13 | import ( 14 | "errors" 15 | "io" 16 | ) 17 | 18 | // ReaderConfig stores the parameters for the reader of the classic LZMA 19 | // format. 20 | type ReaderConfig struct { 21 | DictCap int 22 | } 23 | 24 | // fill converts the zero values of the configuration to the default values. 25 | func (c *ReaderConfig) fill() { 26 | if c.DictCap == 0 { 27 | c.DictCap = 8 * 1024 * 1024 28 | } 29 | } 30 | 31 | // Verify checks the reader configuration for errors. Zero values will 32 | // be replaced by default values. 33 | func (c *ReaderConfig) Verify() error { 34 | c.fill() 35 | if !(MinDictCap <= c.DictCap && int64(c.DictCap) <= MaxDictCap) { 36 | return errors.New("lzma: dictionary capacity is out of range") 37 | } 38 | return nil 39 | } 40 | 41 | // Reader provides a reader for LZMA files or streams. 42 | type Reader struct { 43 | lzma io.Reader 44 | h header 45 | d *decoder 46 | } 47 | 48 | // NewReader creates a new reader for an LZMA stream using the classic 49 | // format. NewReader reads and checks the header of the LZMA stream. 50 | func NewReader(lzma io.Reader) (r *Reader, err error) { 51 | return ReaderConfig{}.NewReader(lzma) 52 | } 53 | 54 | // NewReader creates a new reader for an LZMA stream in the classic 55 | // format. The function reads and verifies the the header of the LZMA 56 | // stream. 57 | func (c ReaderConfig) NewReader(lzma io.Reader) (r *Reader, err error) { 58 | if err = c.Verify(); err != nil { 59 | return nil, err 60 | } 61 | data := make([]byte, HeaderLen) 62 | if _, err := io.ReadFull(lzma, data); err != nil { 63 | if err == io.EOF { 64 | return nil, errors.New("lzma: unexpected EOF") 65 | } 66 | return nil, err 67 | } 68 | r = &Reader{lzma: lzma} 69 | if err = r.h.unmarshalBinary(data); err != nil { 70 | return nil, err 71 | } 72 | if r.h.dictCap < MinDictCap { 73 | return nil, errors.New("lzma: dictionary capacity too small") 74 | } 75 | dictCap := r.h.dictCap 76 | if c.DictCap > dictCap { 77 | dictCap = c.DictCap 78 | } 79 | 80 | state := newState(r.h.properties) 81 | dict, err := newDecoderDict(dictCap) 82 | if err != nil { 83 | return nil, err 84 | } 85 | r.d, err = newDecoder(ByteReader(lzma), state, dict, r.h.size) 86 | if err != nil { 87 | return nil, err 88 | } 89 | return r, nil 90 | } 91 | 92 | // EOSMarker indicates that an EOS marker has been encountered. 93 | func (r *Reader) EOSMarker() bool { 94 | return r.d.eosMarker 95 | } 96 | 97 | // Read returns uncompressed data. 98 | func (r *Reader) Read(p []byte) (n int, err error) { 99 | return r.d.Read(p) 100 | } 101 | -------------------------------------------------------------------------------- /engine/configure.go: -------------------------------------------------------------------------------- 1 | package engine 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "github.com/pkg/errors" 7 | "github.com/shivakishore14/govm/domain" 8 | "github.com/shivakishore14/govm/utils" 9 | "html/template" 10 | "os" 11 | "runtime" 12 | "strings" 13 | ) 14 | 15 | var scriptBash = ` 16 | govm() { 17 | export GOVMOS="{{.Os}}" 18 | export GOVMARCH="{{.Arch}}" 19 | if [[ $1 == "use" ]]; then 20 | shift; 21 | d=` + "`govm path $@`" + ` 22 | if [ ${d:0:5} == "PATH:" ]; then 23 | gopath=${d:5} 24 | PATH=$gopath/bin:$PATH 25 | export GOTOOLDIR="$gopath/pkg/tool/$GOVMOS_$GOVMARCH" 26 | export GOROOT=$gopath 27 | echo "Using version $1" 28 | else 29 | echo "could not find version" 30 | fi 31 | else 32 | command govm "$@" 33 | fi 34 | } 35 | ` 36 | 37 | func Configure() error { 38 | data := struct { 39 | Os string 40 | Arch string 41 | }{ 42 | Os: runtime.GOOS, 43 | Arch: runtime.GOARCH, 44 | } 45 | config := &domain.Config{} 46 | config.LoadConf() 47 | if err := createNecessaryDirs(config); err != nil { 48 | return nil 49 | } 50 | 51 | fmt.Printf("HomeDir for Govm [ %s ] \n", config.GovmHome) 52 | sourceCommand := "source " + config.ScriptPath 53 | scriptFile, err := os.Create(config.ScriptPath) 54 | if err != nil { 55 | return errors.Wrap(err, "error creating script file") 56 | } 57 | 58 | t, err := template.New("script").Parse(scriptBash) 59 | if err != nil { 60 | return errors.Wrap(err, "error getting parsing script template") 61 | } 62 | 63 | if err = t.Execute(scriptFile, data); err != nil { 64 | return errors.Wrap(err, "error executing error template") 65 | } 66 | 67 | // Update .bashrc 68 | if _, err := os.Stat(config.BashrcPath); err != nil { 69 | if os.IsNotExist(err) { 70 | os.Create(config.BashrcPath) 71 | } 72 | } 73 | if err := writeToFileIfNotPresent(config.BashrcPath, sourceCommand); err != nil { 74 | return err 75 | } 76 | return nil 77 | } 78 | 79 | func createNecessaryDirs(config *domain.Config) error { 80 | if err := utils.CreateDirIfNotPresent(config.GovmHome); err != nil { 81 | return err 82 | } 83 | if err := utils.CreateDirIfNotPresent(config.InstallationDir); err != nil { 84 | return err 85 | } 86 | if err := utils.CreateDirIfNotPresent(config.TempDir); err != nil { 87 | return err 88 | } 89 | return nil 90 | } 91 | 92 | func writeToFileIfNotPresent(filename string, content string) error { 93 | f, err := os.OpenFile(filename, os.O_APPEND | os.O_RDWR, 0666) 94 | if err != nil { 95 | return errors.Wrap(err, "error opening file :"+filename) 96 | } 97 | defer f.Close() 98 | 99 | // Splits on newlines by default. 100 | scanner := bufio.NewScanner(f) 101 | 102 | var foundFlag bool 103 | 104 | for scanner.Scan() { 105 | if strings.Contains(scanner.Text(), content) { 106 | foundFlag = true 107 | } 108 | } 109 | 110 | if !foundFlag { 111 | if _, err = f.WriteString(content + "\n"); err != nil { 112 | return errors.Wrap(err, "error writing to file") 113 | } 114 | } 115 | return err 116 | } -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/cmd/gxz/licenses.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | const goLicense = `Copyright (c) 2009 The Go Authors. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following disclaimer 13 | in the documentation and/or other materials provided with the 14 | distribution. 15 | * Neither the name of Google Inc. nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | ` 31 | const xzLicense = `Copyright (c) 2014-2017 Ulrich Kunitz 32 | All rights reserved. 33 | 34 | Redistribution and use in source and binary forms, with or without 35 | modification, are permitted provided that the following conditions are met: 36 | 37 | * Redistributions of source code must retain the above copyright notice, this 38 | list of conditions and the following disclaimer. 39 | 40 | * Redistributions in binary form must reproduce the above copyright notice, 41 | this list of conditions and the following disclaimer in the documentation 42 | and/or other materials provided with the distribution. 43 | 44 | * My name, Ulrich Kunitz, may not be used to endorse or promote products 45 | derived from this software without specific prior written permission. 46 | 47 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | ` 58 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/string.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | // -- string Value 4 | type stringValue string 5 | 6 | func newStringValue(val string, p *string) *stringValue { 7 | *p = val 8 | return (*stringValue)(p) 9 | } 10 | 11 | func (s *stringValue) Set(val string) error { 12 | *s = stringValue(val) 13 | return nil 14 | } 15 | func (s *stringValue) Type() string { 16 | return "string" 17 | } 18 | 19 | func (s *stringValue) String() string { return string(*s) } 20 | 21 | func stringConv(sval string) (interface{}, error) { 22 | return sval, nil 23 | } 24 | 25 | // GetString return the string value of a flag with the given name 26 | func (f *FlagSet) GetString(name string) (string, error) { 27 | val, err := f.getFlagType(name, "string", stringConv) 28 | if err != nil { 29 | return "", err 30 | } 31 | return val.(string), nil 32 | } 33 | 34 | // StringVar defines a string flag with specified name, default value, and usage string. 35 | // The argument p points to a string variable in which to store the value of the flag. 36 | func (f *FlagSet) StringVar(p *string, name string, value string, usage string) { 37 | f.VarP(newStringValue(value, p), name, "", usage) 38 | } 39 | 40 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 41 | func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) { 42 | f.VarP(newStringValue(value, p), name, shorthand, usage) 43 | } 44 | 45 | // StringVar defines a string flag with specified name, default value, and usage string. 46 | // The argument p points to a string variable in which to store the value of the flag. 47 | func StringVar(p *string, name string, value string, usage string) { 48 | CommandLine.VarP(newStringValue(value, p), name, "", usage) 49 | } 50 | 51 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 52 | func StringVarP(p *string, name, shorthand string, value string, usage string) { 53 | CommandLine.VarP(newStringValue(value, p), name, shorthand, usage) 54 | } 55 | 56 | // String defines a string flag with specified name, default value, and usage string. 57 | // The return value is the address of a string variable that stores the value of the flag. 58 | func (f *FlagSet) String(name string, value string, usage string) *string { 59 | p := new(string) 60 | f.StringVarP(p, name, "", value, usage) 61 | return p 62 | } 63 | 64 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash. 65 | func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string { 66 | p := new(string) 67 | f.StringVarP(p, name, shorthand, value, usage) 68 | return p 69 | } 70 | 71 | // String defines a string flag with specified name, default value, and usage string. 72 | // The return value is the address of a string variable that stores the value of the flag. 73 | func String(name string, value string, usage string) *string { 74 | return CommandLine.StringP(name, "", value, usage) 75 | } 76 | 77 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash. 78 | func StringP(name, shorthand string, value string, usage string) *string { 79 | return CommandLine.StringP(name, shorthand, value, usage) 80 | } 81 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int64 Value 6 | type int64Value int64 7 | 8 | func newInt64Value(val int64, p *int64) *int64Value { 9 | *p = val 10 | return (*int64Value)(p) 11 | } 12 | 13 | func (i *int64Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | *i = int64Value(v) 16 | return err 17 | } 18 | 19 | func (i *int64Value) Type() string { 20 | return "int64" 21 | } 22 | 23 | func (i *int64Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int64Conv(sval string) (interface{}, error) { 26 | return strconv.ParseInt(sval, 0, 64) 27 | } 28 | 29 | // GetInt64 return the int64 value of a flag with the given name 30 | func (f *FlagSet) GetInt64(name string) (int64, error) { 31 | val, err := f.getFlagType(name, "int64", int64Conv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(int64), nil 36 | } 37 | 38 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 39 | // The argument p points to an int64 variable in which to store the value of the flag. 40 | func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) { 41 | f.VarP(newInt64Value(value, p), name, "", usage) 42 | } 43 | 44 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 46 | f.VarP(newInt64Value(value, p), name, shorthand, usage) 47 | } 48 | 49 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 50 | // The argument p points to an int64 variable in which to store the value of the flag. 51 | func Int64Var(p *int64, name string, value int64, usage string) { 52 | CommandLine.VarP(newInt64Value(value, p), name, "", usage) 53 | } 54 | 55 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 56 | func Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 57 | CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Int64 defines an int64 flag with specified name, default value, and usage string. 61 | // The return value is the address of an int64 variable that stores the value of the flag. 62 | func (f *FlagSet) Int64(name string, value int64, usage string) *int64 { 63 | p := new(int64) 64 | f.Int64VarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64 { 70 | p := new(int64) 71 | f.Int64VarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Int64 defines an int64 flag with specified name, default value, and usage string. 76 | // The return value is the address of an int64 variable that stores the value of the flag. 77 | func Int64(name string, value int64, usage string) *int64 { 78 | return CommandLine.Int64P(name, "", value, usage) 79 | } 80 | 81 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 82 | func Int64P(name, shorthand string, value int64, usage string) *int64 { 83 | return CommandLine.Int64P(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int8 Value 6 | type int8Value int8 7 | 8 | func newInt8Value(val int8, p *int8) *int8Value { 9 | *p = val 10 | return (*int8Value)(p) 11 | } 12 | 13 | func (i *int8Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 8) 15 | *i = int8Value(v) 16 | return err 17 | } 18 | 19 | func (i *int8Value) Type() string { 20 | return "int8" 21 | } 22 | 23 | func (i *int8Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int8Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 8) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int8(v), nil 31 | } 32 | 33 | // GetInt8 return the int8 value of a flag with the given name 34 | func (f *FlagSet) GetInt8(name string) (int8, error) { 35 | val, err := f.getFlagType(name, "int8", int8Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int8), nil 40 | } 41 | 42 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 43 | // The argument p points to an int8 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string) { 45 | f.VarP(newInt8Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 50 | f.VarP(newInt8Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 54 | // The argument p points to an int8 variable in which to store the value of the flag. 55 | func Int8Var(p *int8, name string, value int8, usage string) { 56 | CommandLine.VarP(newInt8Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 61 | CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int8 defines an int8 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int8 variable that stores the value of the flag. 66 | func (f *FlagSet) Int8(name string, value int8, usage string) *int8 { 67 | p := new(int8) 68 | f.Int8VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8 { 74 | p := new(int8) 75 | f.Int8VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int8 defines an int8 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int8 variable that stores the value of the flag. 81 | func Int8(name string, value int8, usage string) *int8 { 82 | return CommandLine.Int8P(name, "", value, usage) 83 | } 84 | 85 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 86 | func Int8P(name, shorthand string, value int8, usage string) *int8 { 87 | return CommandLine.Int8P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint Value 6 | type uintValue uint 7 | 8 | func newUintValue(val uint, p *uint) *uintValue { 9 | *p = val 10 | return (*uintValue)(p) 11 | } 12 | 13 | func (i *uintValue) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 64) 15 | *i = uintValue(v) 16 | return err 17 | } 18 | 19 | func (i *uintValue) Type() string { 20 | return "uint" 21 | } 22 | 23 | func (i *uintValue) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uintConv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 0) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint(v), nil 31 | } 32 | 33 | // GetUint return the uint value of a flag with the given name 34 | func (f *FlagSet) GetUint(name string) (uint, error) { 35 | val, err := f.getFlagType(name, "uint", uintConv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint), nil 40 | } 41 | 42 | // UintVar defines a uint flag with specified name, default value, and usage string. 43 | // The argument p points to a uint variable in which to store the value of the flag. 44 | func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) { 45 | f.VarP(newUintValue(value, p), name, "", usage) 46 | } 47 | 48 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string) { 50 | f.VarP(newUintValue(value, p), name, shorthand, usage) 51 | } 52 | 53 | // UintVar defines a uint flag with specified name, default value, and usage string. 54 | // The argument p points to a uint variable in which to store the value of the flag. 55 | func UintVar(p *uint, name string, value uint, usage string) { 56 | CommandLine.VarP(newUintValue(value, p), name, "", usage) 57 | } 58 | 59 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 60 | func UintVarP(p *uint, name, shorthand string, value uint, usage string) { 61 | CommandLine.VarP(newUintValue(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint defines a uint flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint variable that stores the value of the flag. 66 | func (f *FlagSet) Uint(name string, value uint, usage string) *uint { 67 | p := new(uint) 68 | f.UintVarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint { 74 | p := new(uint) 75 | f.UintVarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint defines a uint flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint variable that stores the value of the flag. 81 | func Uint(name string, value uint, usage string) *uint { 82 | return CommandLine.UintP(name, "", value, usage) 83 | } 84 | 85 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 86 | func UintP(name, shorthand string, value uint, usage string) *uint { 87 | return CommandLine.UintP(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/count.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- count Value 6 | type countValue int 7 | 8 | func newCountValue(val int, p *int) *countValue { 9 | *p = val 10 | return (*countValue)(p) 11 | } 12 | 13 | func (i *countValue) Set(s string) error { 14 | // "+1" means that no specific value was passed, so increment 15 | if s == "+1" { 16 | *i = countValue(*i + 1) 17 | return nil 18 | } 19 | v, err := strconv.ParseInt(s, 0, 0) 20 | *i = countValue(v) 21 | return err 22 | } 23 | 24 | func (i *countValue) Type() string { 25 | return "count" 26 | } 27 | 28 | func (i *countValue) String() string { return strconv.Itoa(int(*i)) } 29 | 30 | func countConv(sval string) (interface{}, error) { 31 | i, err := strconv.Atoi(sval) 32 | if err != nil { 33 | return nil, err 34 | } 35 | return i, nil 36 | } 37 | 38 | // GetCount return the int value of a flag with the given name 39 | func (f *FlagSet) GetCount(name string) (int, error) { 40 | val, err := f.getFlagType(name, "count", countConv) 41 | if err != nil { 42 | return 0, err 43 | } 44 | return val.(int), nil 45 | } 46 | 47 | // CountVar defines a count flag with specified name, default value, and usage string. 48 | // The argument p points to an int variable in which to store the value of the flag. 49 | // A count flag will add 1 to its value evey time it is found on the command line 50 | func (f *FlagSet) CountVar(p *int, name string, usage string) { 51 | f.CountVarP(p, name, "", usage) 52 | } 53 | 54 | // CountVarP is like CountVar only take a shorthand for the flag name. 55 | func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string) { 56 | flag := f.VarPF(newCountValue(0, p), name, shorthand, usage) 57 | flag.NoOptDefVal = "+1" 58 | } 59 | 60 | // CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set 61 | func CountVar(p *int, name string, usage string) { 62 | CommandLine.CountVar(p, name, usage) 63 | } 64 | 65 | // CountVarP is like CountVar only take a shorthand for the flag name. 66 | func CountVarP(p *int, name, shorthand string, usage string) { 67 | CommandLine.CountVarP(p, name, shorthand, usage) 68 | } 69 | 70 | // Count defines a count flag with specified name, default value, and usage string. 71 | // The return value is the address of an int variable that stores the value of the flag. 72 | // A count flag will add 1 to its value evey time it is found on the command line 73 | func (f *FlagSet) Count(name string, usage string) *int { 74 | p := new(int) 75 | f.CountVarP(p, name, "", usage) 76 | return p 77 | } 78 | 79 | // CountP is like Count only takes a shorthand for the flag name. 80 | func (f *FlagSet) CountP(name, shorthand string, usage string) *int { 81 | p := new(int) 82 | f.CountVarP(p, name, shorthand, usage) 83 | return p 84 | } 85 | 86 | // Count defines a count flag with specified name, default value, and usage string. 87 | // The return value is the address of an int variable that stores the value of the flag. 88 | // A count flag will add 1 to its value evey time it is found on the command line 89 | func Count(name string, usage string) *int { 90 | return CommandLine.CountP(name, "", usage) 91 | } 92 | 93 | // CountP is like Count only takes a shorthand for the flag name. 94 | func CountP(name, shorthand string, usage string) *int { 95 | return CommandLine.CountP(name, shorthand, usage) 96 | } 97 | -------------------------------------------------------------------------------- /vendor/github.com/ulikunitz/xz/lzmafilter.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package xz 6 | 7 | import ( 8 | "errors" 9 | "fmt" 10 | "io" 11 | 12 | "github.com/ulikunitz/xz/lzma" 13 | ) 14 | 15 | // LZMA filter constants. 16 | const ( 17 | lzmaFilterID = 0x21 18 | lzmaFilterLen = 3 19 | ) 20 | 21 | // lzmaFilter declares the LZMA2 filter information stored in an xz 22 | // block header. 23 | type lzmaFilter struct { 24 | dictCap int64 25 | } 26 | 27 | // String returns a representation of the LZMA filter. 28 | func (f lzmaFilter) String() string { 29 | return fmt.Sprintf("LZMA dict cap %#x", f.dictCap) 30 | } 31 | 32 | // id returns the ID for the LZMA2 filter. 33 | func (f lzmaFilter) id() uint64 { return lzmaFilterID } 34 | 35 | // MarshalBinary converts the lzmaFilter in its encoded representation. 36 | func (f lzmaFilter) MarshalBinary() (data []byte, err error) { 37 | c := lzma.EncodeDictCap(f.dictCap) 38 | return []byte{lzmaFilterID, 1, c}, nil 39 | } 40 | 41 | // UnmarshalBinary unmarshals the given data representation of the LZMA2 42 | // filter. 43 | func (f *lzmaFilter) UnmarshalBinary(data []byte) error { 44 | if len(data) != lzmaFilterLen { 45 | return errors.New("xz: data for LZMA2 filter has wrong length") 46 | } 47 | if data[0] != lzmaFilterID { 48 | return errors.New("xz: wrong LZMA2 filter id") 49 | } 50 | if data[1] != 1 { 51 | return errors.New("xz: wrong LZMA2 filter size") 52 | } 53 | dc, err := lzma.DecodeDictCap(data[2]) 54 | if err != nil { 55 | return errors.New("xz: wrong LZMA2 dictionary size property") 56 | } 57 | 58 | f.dictCap = dc 59 | return nil 60 | } 61 | 62 | // reader creates a new reader for the LZMA2 filter. 63 | func (f lzmaFilter) reader(r io.Reader, c *ReaderConfig) (fr io.Reader, 64 | err error) { 65 | 66 | config := new(lzma.Reader2Config) 67 | if c != nil { 68 | config.DictCap = c.DictCap 69 | } 70 | dc := int(f.dictCap) 71 | if dc < 1 { 72 | return nil, errors.New("xz: LZMA2 filter parameter " + 73 | "dictionary capacity overflow") 74 | } 75 | if dc > config.DictCap { 76 | config.DictCap = dc 77 | } 78 | 79 | fr, err = config.NewReader2(r) 80 | if err != nil { 81 | return nil, err 82 | } 83 | return fr, nil 84 | } 85 | 86 | // writeCloser creates a io.WriteCloser for the LZMA2 filter. 87 | func (f lzmaFilter) writeCloser(w io.WriteCloser, c *WriterConfig, 88 | ) (fw io.WriteCloser, err error) { 89 | config := new(lzma.Writer2Config) 90 | if c != nil { 91 | *config = lzma.Writer2Config{ 92 | Properties: c.Properties, 93 | DictCap: c.DictCap, 94 | BufSize: c.BufSize, 95 | Matcher: c.Matcher, 96 | } 97 | } 98 | 99 | dc := int(f.dictCap) 100 | if dc < 1 { 101 | return nil, errors.New("xz: LZMA2 filter parameter " + 102 | "dictionary capacity overflow") 103 | } 104 | if dc > config.DictCap { 105 | config.DictCap = dc 106 | } 107 | 108 | fw, err = config.NewWriter2(w) 109 | if err != nil { 110 | return nil, err 111 | } 112 | return fw, nil 113 | } 114 | 115 | // last returns true, because an LZMA2 filter must be the last filter in 116 | // the filter list. 117 | func (f lzmaFilter) last() bool { return true } 118 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/golangflag.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pflag 6 | 7 | import ( 8 | goflag "flag" 9 | "reflect" 10 | "strings" 11 | ) 12 | 13 | // flagValueWrapper implements pflag.Value around a flag.Value. The main 14 | // difference here is the addition of the Type method that returns a string 15 | // name of the type. As this is generally unknown, we approximate that with 16 | // reflection. 17 | type flagValueWrapper struct { 18 | inner goflag.Value 19 | flagType string 20 | } 21 | 22 | // We are just copying the boolFlag interface out of goflag as that is what 23 | // they use to decide if a flag should get "true" when no arg is given. 24 | type goBoolFlag interface { 25 | goflag.Value 26 | IsBoolFlag() bool 27 | } 28 | 29 | func wrapFlagValue(v goflag.Value) Value { 30 | // If the flag.Value happens to also be a pflag.Value, just use it directly. 31 | if pv, ok := v.(Value); ok { 32 | return pv 33 | } 34 | 35 | pv := &flagValueWrapper{ 36 | inner: v, 37 | } 38 | 39 | t := reflect.TypeOf(v) 40 | if t.Kind() == reflect.Interface || t.Kind() == reflect.Ptr { 41 | t = t.Elem() 42 | } 43 | 44 | pv.flagType = strings.TrimSuffix(t.Name(), "Value") 45 | return pv 46 | } 47 | 48 | func (v *flagValueWrapper) String() string { 49 | return v.inner.String() 50 | } 51 | 52 | func (v *flagValueWrapper) Set(s string) error { 53 | return v.inner.Set(s) 54 | } 55 | 56 | func (v *flagValueWrapper) Type() string { 57 | return v.flagType 58 | } 59 | 60 | // PFlagFromGoFlag will return a *pflag.Flag given a *flag.Flag 61 | // If the *flag.Flag.Name was a single character (ex: `v`) it will be accessiblei 62 | // with both `-v` and `--v` in flags. If the golang flag was more than a single 63 | // character (ex: `verbose`) it will only be accessible via `--verbose` 64 | func PFlagFromGoFlag(goflag *goflag.Flag) *Flag { 65 | // Remember the default value as a string; it won't change. 66 | flag := &Flag{ 67 | Name: goflag.Name, 68 | Usage: goflag.Usage, 69 | Value: wrapFlagValue(goflag.Value), 70 | // Looks like golang flags don't set DefValue correctly :-( 71 | //DefValue: goflag.DefValue, 72 | DefValue: goflag.Value.String(), 73 | } 74 | // Ex: if the golang flag was -v, allow both -v and --v to work 75 | if len(flag.Name) == 1 { 76 | flag.Shorthand = flag.Name 77 | } 78 | if fv, ok := goflag.Value.(goBoolFlag); ok && fv.IsBoolFlag() { 79 | flag.NoOptDefVal = "true" 80 | } 81 | return flag 82 | } 83 | 84 | // AddGoFlag will add the given *flag.Flag to the pflag.FlagSet 85 | func (f *FlagSet) AddGoFlag(goflag *goflag.Flag) { 86 | if f.Lookup(goflag.Name) != nil { 87 | return 88 | } 89 | newflag := PFlagFromGoFlag(goflag) 90 | f.AddFlag(newflag) 91 | } 92 | 93 | // AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet 94 | func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet) { 95 | if newSet == nil { 96 | return 97 | } 98 | newSet.VisitAll(func(goflag *goflag.Flag) { 99 | f.AddGoFlag(goflag) 100 | }) 101 | if f.addedGoFlagSets == nil { 102 | f.addedGoFlagSets = make([]*goflag.FlagSet, 0) 103 | } 104 | f.addedGoFlagSets = append(f.addedGoFlagSets, newSet) 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint8 Value 6 | type uint8Value uint8 7 | 8 | func newUint8Value(val uint8, p *uint8) *uint8Value { 9 | *p = val 10 | return (*uint8Value)(p) 11 | } 12 | 13 | func (i *uint8Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 8) 15 | *i = uint8Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint8Value) Type() string { 20 | return "uint8" 21 | } 22 | 23 | func (i *uint8Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint8Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 8) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint8(v), nil 31 | } 32 | 33 | // GetUint8 return the uint8 value of a flag with the given name 34 | func (f *FlagSet) GetUint8(name string) (uint8, error) { 35 | val, err := f.getFlagType(name, "uint8", uint8Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint8), nil 40 | } 41 | 42 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint8 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) { 45 | f.VarP(newUint8Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 50 | f.VarP(newUint8Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint8 variable in which to store the value of the flag. 55 | func Uint8Var(p *uint8, name string, value uint8, usage string) { 56 | CommandLine.VarP(newUint8Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 61 | CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint8 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 { 67 | p := new(uint8) 68 | f.Uint8VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 74 | p := new(uint8) 75 | f.Uint8VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint8 variable that stores the value of the flag. 81 | func Uint8(name string, value uint8, usage string) *uint8 { 82 | return CommandLine.Uint8P(name, "", value, usage) 83 | } 84 | 85 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 87 | return CommandLine.Uint8P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int16.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int16 Value 6 | type int16Value int16 7 | 8 | func newInt16Value(val int16, p *int16) *int16Value { 9 | *p = val 10 | return (*int16Value)(p) 11 | } 12 | 13 | func (i *int16Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 16) 15 | *i = int16Value(v) 16 | return err 17 | } 18 | 19 | func (i *int16Value) Type() string { 20 | return "int16" 21 | } 22 | 23 | func (i *int16Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int16Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 16) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int16(v), nil 31 | } 32 | 33 | // GetInt16 returns the int16 value of a flag with the given name 34 | func (f *FlagSet) GetInt16(name string) (int16, error) { 35 | val, err := f.getFlagType(name, "int16", int16Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int16), nil 40 | } 41 | 42 | // Int16Var defines an int16 flag with specified name, default value, and usage string. 43 | // The argument p points to an int16 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int16Var(p *int16, name string, value int16, usage string) { 45 | f.VarP(newInt16Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int16VarP(p *int16, name, shorthand string, value int16, usage string) { 50 | f.VarP(newInt16Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int16Var defines an int16 flag with specified name, default value, and usage string. 54 | // The argument p points to an int16 variable in which to store the value of the flag. 55 | func Int16Var(p *int16, name string, value int16, usage string) { 56 | CommandLine.VarP(newInt16Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int16VarP(p *int16, name, shorthand string, value int16, usage string) { 61 | CommandLine.VarP(newInt16Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int16 defines an int16 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int16 variable that stores the value of the flag. 66 | func (f *FlagSet) Int16(name string, value int16, usage string) *int16 { 67 | p := new(int16) 68 | f.Int16VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int16P(name, shorthand string, value int16, usage string) *int16 { 74 | p := new(int16) 75 | f.Int16VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int16 defines an int16 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int16 variable that stores the value of the flag. 81 | func Int16(name string, value int16, usage string) *int16 { 82 | return CommandLine.Int16P(name, "", value, usage) 83 | } 84 | 85 | // Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash. 86 | func Int16P(name, shorthand string, value int16, usage string) *int16 { 87 | return CommandLine.Int16P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int32 Value 6 | type int32Value int32 7 | 8 | func newInt32Value(val int32, p *int32) *int32Value { 9 | *p = val 10 | return (*int32Value)(p) 11 | } 12 | 13 | func (i *int32Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 32) 15 | *i = int32Value(v) 16 | return err 17 | } 18 | 19 | func (i *int32Value) Type() string { 20 | return "int32" 21 | } 22 | 23 | func (i *int32Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int32(v), nil 31 | } 32 | 33 | // GetInt32 return the int32 value of a flag with the given name 34 | func (f *FlagSet) GetInt32(name string) (int32, error) { 35 | val, err := f.getFlagType(name, "int32", int32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int32), nil 40 | } 41 | 42 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 43 | // The argument p points to an int32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string) { 45 | f.VarP(newInt32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 50 | f.VarP(newInt32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 54 | // The argument p points to an int32 variable in which to store the value of the flag. 55 | func Int32Var(p *int32, name string, value int32, usage string) { 56 | CommandLine.VarP(newInt32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 61 | CommandLine.VarP(newInt32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int32 defines an int32 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int32 variable that stores the value of the flag. 66 | func (f *FlagSet) Int32(name string, value int32, usage string) *int32 { 67 | p := new(int32) 68 | f.Int32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32 { 74 | p := new(int32) 75 | f.Int32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int32 defines an int32 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int32 variable that stores the value of the flag. 81 | func Int32(name string, value int32, usage string) *int32 { 82 | return CommandLine.Int32P(name, "", value, usage) 83 | } 84 | 85 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 86 | func Int32P(name, shorthand string, value int32, usage string) *int32 { 87 | return CommandLine.Int32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/dustin/go-humanize/bytes.go: -------------------------------------------------------------------------------- 1 | package humanize 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | "strconv" 7 | "strings" 8 | "unicode" 9 | ) 10 | 11 | // IEC Sizes. 12 | // kibis of bits 13 | const ( 14 | Byte = 1 << (iota * 10) 15 | KiByte 16 | MiByte 17 | GiByte 18 | TiByte 19 | PiByte 20 | EiByte 21 | ) 22 | 23 | // SI Sizes. 24 | const ( 25 | IByte = 1 26 | KByte = IByte * 1000 27 | MByte = KByte * 1000 28 | GByte = MByte * 1000 29 | TByte = GByte * 1000 30 | PByte = TByte * 1000 31 | EByte = PByte * 1000 32 | ) 33 | 34 | var bytesSizeTable = map[string]uint64{ 35 | "b": Byte, 36 | "kib": KiByte, 37 | "kb": KByte, 38 | "mib": MiByte, 39 | "mb": MByte, 40 | "gib": GiByte, 41 | "gb": GByte, 42 | "tib": TiByte, 43 | "tb": TByte, 44 | "pib": PiByte, 45 | "pb": PByte, 46 | "eib": EiByte, 47 | "eb": EByte, 48 | // Without suffix 49 | "": Byte, 50 | "ki": KiByte, 51 | "k": KByte, 52 | "mi": MiByte, 53 | "m": MByte, 54 | "gi": GiByte, 55 | "g": GByte, 56 | "ti": TiByte, 57 | "t": TByte, 58 | "pi": PiByte, 59 | "p": PByte, 60 | "ei": EiByte, 61 | "e": EByte, 62 | } 63 | 64 | func logn(n, b float64) float64 { 65 | return math.Log(n) / math.Log(b) 66 | } 67 | 68 | func humanateBytes(s uint64, base float64, sizes []string) string { 69 | if s < 10 { 70 | return fmt.Sprintf("%d B", s) 71 | } 72 | e := math.Floor(logn(float64(s), base)) 73 | suffix := sizes[int(e)] 74 | val := math.Floor(float64(s)/math.Pow(base, e)*10+0.5) / 10 75 | f := "%.0f %s" 76 | if val < 10 { 77 | f = "%.1f %s" 78 | } 79 | 80 | return fmt.Sprintf(f, val, suffix) 81 | } 82 | 83 | // Bytes produces a human readable representation of an SI size. 84 | // 85 | // See also: ParseBytes. 86 | // 87 | // Bytes(82854982) -> 83 MB 88 | func Bytes(s uint64) string { 89 | sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB"} 90 | return humanateBytes(s, 1000, sizes) 91 | } 92 | 93 | // IBytes produces a human readable representation of an IEC size. 94 | // 95 | // See also: ParseBytes. 96 | // 97 | // IBytes(82854982) -> 79 MiB 98 | func IBytes(s uint64) string { 99 | sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"} 100 | return humanateBytes(s, 1024, sizes) 101 | } 102 | 103 | // ParseBytes parses a string representation of bytes into the number 104 | // of bytes it represents. 105 | // 106 | // See Also: Bytes, IBytes. 107 | // 108 | // ParseBytes("42 MB") -> 42000000, nil 109 | // ParseBytes("42 mib") -> 44040192, nil 110 | func ParseBytes(s string) (uint64, error) { 111 | lastDigit := 0 112 | hasComma := false 113 | for _, r := range s { 114 | if !(unicode.IsDigit(r) || r == '.' || r == ',') { 115 | break 116 | } 117 | if r == ',' { 118 | hasComma = true 119 | } 120 | lastDigit++ 121 | } 122 | 123 | num := s[:lastDigit] 124 | if hasComma { 125 | num = strings.Replace(num, ",", "", -1) 126 | } 127 | 128 | f, err := strconv.ParseFloat(num, 64) 129 | if err != nil { 130 | return 0, err 131 | } 132 | 133 | extra := strings.ToLower(strings.TrimSpace(s[lastDigit:])) 134 | if m, ok := bytesSizeTable[extra]; ok { 135 | f *= float64(m) 136 | if f >= math.MaxUint64 { 137 | return 0, fmt.Errorf("too large: %v", s) 138 | } 139 | return uint64(f), nil 140 | } 141 | 142 | return 0, fmt.Errorf("unhandled size name: %v", extra) 143 | } 144 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/zsh_completions.go: -------------------------------------------------------------------------------- 1 | package cobra 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io" 7 | "os" 8 | "strings" 9 | ) 10 | 11 | // GenZshCompletionFile generates zsh completion file. 12 | func (c *Command) GenZshCompletionFile(filename string) error { 13 | outFile, err := os.Create(filename) 14 | if err != nil { 15 | return err 16 | } 17 | defer outFile.Close() 18 | 19 | return c.GenZshCompletion(outFile) 20 | } 21 | 22 | // GenZshCompletion generates a zsh completion file and writes to the passed writer. 23 | func (c *Command) GenZshCompletion(w io.Writer) error { 24 | buf := new(bytes.Buffer) 25 | 26 | writeHeader(buf, c) 27 | maxDepth := maxDepth(c) 28 | writeLevelMapping(buf, maxDepth) 29 | writeLevelCases(buf, maxDepth, c) 30 | 31 | _, err := buf.WriteTo(w) 32 | return err 33 | } 34 | 35 | func writeHeader(w io.Writer, cmd *Command) { 36 | fmt.Fprintf(w, "#compdef %s\n\n", cmd.Name()) 37 | } 38 | 39 | func maxDepth(c *Command) int { 40 | if len(c.Commands()) == 0 { 41 | return 0 42 | } 43 | maxDepthSub := 0 44 | for _, s := range c.Commands() { 45 | subDepth := maxDepth(s) 46 | if subDepth > maxDepthSub { 47 | maxDepthSub = subDepth 48 | } 49 | } 50 | return 1 + maxDepthSub 51 | } 52 | 53 | func writeLevelMapping(w io.Writer, numLevels int) { 54 | fmt.Fprintln(w, `_arguments \`) 55 | for i := 1; i <= numLevels; i++ { 56 | fmt.Fprintf(w, ` '%d: :->level%d' \`, i, i) 57 | fmt.Fprintln(w) 58 | } 59 | fmt.Fprintf(w, ` '%d: :%s'`, numLevels+1, "_files") 60 | fmt.Fprintln(w) 61 | } 62 | 63 | func writeLevelCases(w io.Writer, maxDepth int, root *Command) { 64 | fmt.Fprintln(w, "case $state in") 65 | defer fmt.Fprintln(w, "esac") 66 | 67 | for i := 1; i <= maxDepth; i++ { 68 | fmt.Fprintf(w, " level%d)\n", i) 69 | writeLevel(w, root, i) 70 | fmt.Fprintln(w, " ;;") 71 | } 72 | fmt.Fprintln(w, " *)") 73 | fmt.Fprintln(w, " _arguments '*: :_files'") 74 | fmt.Fprintln(w, " ;;") 75 | } 76 | 77 | func writeLevel(w io.Writer, root *Command, i int) { 78 | fmt.Fprintf(w, " case $words[%d] in\n", i) 79 | defer fmt.Fprintln(w, " esac") 80 | 81 | commands := filterByLevel(root, i) 82 | byParent := groupByParent(commands) 83 | 84 | for p, c := range byParent { 85 | names := names(c) 86 | fmt.Fprintf(w, " %s)\n", p) 87 | fmt.Fprintf(w, " _arguments '%d: :(%s)'\n", i, strings.Join(names, " ")) 88 | fmt.Fprintln(w, " ;;") 89 | } 90 | fmt.Fprintln(w, " *)") 91 | fmt.Fprintln(w, " _arguments '*: :_files'") 92 | fmt.Fprintln(w, " ;;") 93 | 94 | } 95 | 96 | func filterByLevel(c *Command, l int) []*Command { 97 | cs := make([]*Command, 0) 98 | if l == 0 { 99 | cs = append(cs, c) 100 | return cs 101 | } 102 | for _, s := range c.Commands() { 103 | cs = append(cs, filterByLevel(s, l-1)...) 104 | } 105 | return cs 106 | } 107 | 108 | func groupByParent(commands []*Command) map[string][]*Command { 109 | m := make(map[string][]*Command) 110 | for _, c := range commands { 111 | parent := c.Parent() 112 | if parent == nil { 113 | continue 114 | } 115 | m[parent.Name()] = append(m[parent.Name()], c) 116 | } 117 | return m 118 | } 119 | 120 | func names(commands []*Command) []string { 121 | ns := make([]string, len(commands)) 122 | for i, c := range commands { 123 | ns[i] = c.Name() 124 | } 125 | return ns 126 | } 127 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ip.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | // -- net.IP value 10 | type ipValue net.IP 11 | 12 | func newIPValue(val net.IP, p *net.IP) *ipValue { 13 | *p = val 14 | return (*ipValue)(p) 15 | } 16 | 17 | func (i *ipValue) String() string { return net.IP(*i).String() } 18 | func (i *ipValue) Set(s string) error { 19 | ip := net.ParseIP(strings.TrimSpace(s)) 20 | if ip == nil { 21 | return fmt.Errorf("failed to parse IP: %q", s) 22 | } 23 | *i = ipValue(ip) 24 | return nil 25 | } 26 | 27 | func (i *ipValue) Type() string { 28 | return "ip" 29 | } 30 | 31 | func ipConv(sval string) (interface{}, error) { 32 | ip := net.ParseIP(sval) 33 | if ip != nil { 34 | return ip, nil 35 | } 36 | return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval) 37 | } 38 | 39 | // GetIP return the net.IP value of a flag with the given name 40 | func (f *FlagSet) GetIP(name string) (net.IP, error) { 41 | val, err := f.getFlagType(name, "ip", ipConv) 42 | if err != nil { 43 | return nil, err 44 | } 45 | return val.(net.IP), nil 46 | } 47 | 48 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 49 | // The argument p points to an net.IP variable in which to store the value of the flag. 50 | func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) { 51 | f.VarP(newIPValue(value, p), name, "", usage) 52 | } 53 | 54 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 55 | func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 56 | f.VarP(newIPValue(value, p), name, shorthand, usage) 57 | } 58 | 59 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 60 | // The argument p points to an net.IP variable in which to store the value of the flag. 61 | func IPVar(p *net.IP, name string, value net.IP, usage string) { 62 | CommandLine.VarP(newIPValue(value, p), name, "", usage) 63 | } 64 | 65 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 66 | func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 67 | CommandLine.VarP(newIPValue(value, p), name, shorthand, usage) 68 | } 69 | 70 | // IP defines an net.IP flag with specified name, default value, and usage string. 71 | // The return value is the address of an net.IP variable that stores the value of the flag. 72 | func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP { 73 | p := new(net.IP) 74 | f.IPVarP(p, name, "", value, usage) 75 | return p 76 | } 77 | 78 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 79 | func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP { 80 | p := new(net.IP) 81 | f.IPVarP(p, name, shorthand, value, usage) 82 | return p 83 | } 84 | 85 | // IP defines an net.IP flag with specified name, default value, and usage string. 86 | // The return value is the address of an net.IP variable that stores the value of the flag. 87 | func IP(name string, value net.IP, usage string) *net.IP { 88 | return CommandLine.IPP(name, "", value, usage) 89 | } 90 | 91 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 92 | func IPP(name, shorthand string, value net.IP, usage string) *net.IP { 93 | return CommandLine.IPP(name, shorthand, value, usage) 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint16.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint16 value 6 | type uint16Value uint16 7 | 8 | func newUint16Value(val uint16, p *uint16) *uint16Value { 9 | *p = val 10 | return (*uint16Value)(p) 11 | } 12 | 13 | func (i *uint16Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 16) 15 | *i = uint16Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint16Value) Type() string { 20 | return "uint16" 21 | } 22 | 23 | func (i *uint16Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint16Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 16) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint16(v), nil 31 | } 32 | 33 | // GetUint16 return the uint16 value of a flag with the given name 34 | func (f *FlagSet) GetUint16(name string) (uint16, error) { 35 | val, err := f.getFlagType(name, "uint16", uint16Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint16), nil 40 | } 41 | 42 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 43 | // The argument p points to a uint variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) { 45 | f.VarP(newUint16Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 50 | f.VarP(newUint16Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 54 | // The argument p points to a uint variable in which to store the value of the flag. 55 | func Uint16Var(p *uint16, name string, value uint16, usage string) { 56 | CommandLine.VarP(newUint16Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 61 | CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint16 defines a uint flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint variable that stores the value of the flag. 66 | func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 { 67 | p := new(uint16) 68 | f.Uint16VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 74 | p := new(uint16) 75 | f.Uint16VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint16 defines a uint flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint variable that stores the value of the flag. 81 | func Uint16(name string, value uint16, usage string) *uint16 { 82 | return CommandLine.Uint16P(name, "", value, usage) 83 | } 84 | 85 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 87 | return CommandLine.Uint16P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- float64 Value 6 | type float64Value float64 7 | 8 | func newFloat64Value(val float64, p *float64) *float64Value { 9 | *p = val 10 | return (*float64Value)(p) 11 | } 12 | 13 | func (f *float64Value) Set(s string) error { 14 | v, err := strconv.ParseFloat(s, 64) 15 | *f = float64Value(v) 16 | return err 17 | } 18 | 19 | func (f *float64Value) Type() string { 20 | return "float64" 21 | } 22 | 23 | func (f *float64Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) } 24 | 25 | func float64Conv(sval string) (interface{}, error) { 26 | return strconv.ParseFloat(sval, 64) 27 | } 28 | 29 | // GetFloat64 return the float64 value of a flag with the given name 30 | func (f *FlagSet) GetFloat64(name string) (float64, error) { 31 | val, err := f.getFlagType(name, "float64", float64Conv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(float64), nil 36 | } 37 | 38 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 39 | // The argument p points to a float64 variable in which to store the value of the flag. 40 | func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) { 41 | f.VarP(newFloat64Value(value, p), name, "", usage) 42 | } 43 | 44 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 46 | f.VarP(newFloat64Value(value, p), name, shorthand, usage) 47 | } 48 | 49 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 50 | // The argument p points to a float64 variable in which to store the value of the flag. 51 | func Float64Var(p *float64, name string, value float64, usage string) { 52 | CommandLine.VarP(newFloat64Value(value, p), name, "", usage) 53 | } 54 | 55 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. 56 | func Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 57 | CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Float64 defines a float64 flag with specified name, default value, and usage string. 61 | // The return value is the address of a float64 variable that stores the value of the flag. 62 | func (f *FlagSet) Float64(name string, value float64, usage string) *float64 { 63 | p := new(float64) 64 | f.Float64VarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 { 70 | p := new(float64) 71 | f.Float64VarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Float64 defines a float64 flag with specified name, default value, and usage string. 76 | // The return value is the address of a float64 variable that stores the value of the flag. 77 | func Float64(name string, value float64, usage string) *float64 { 78 | return CommandLine.Float64P(name, "", value, usage) 79 | } 80 | 81 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 82 | func Float64P(name, shorthand string, value float64, usage string) *float64 { 83 | return CommandLine.Float64P(name, shorthand, value, usage) 84 | } 85 | --------------------------------------------------------------------------------