Skip to content
This repository was archived by the owner on Feb 27, 2018. It is now read-only.

Commit 35e2fc4

Browse files
nathanleclairetianon
authored andcommitted
Make error message configurable by HTTP call
Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
1 parent 901b10c commit 35e2fc4

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Deprecated
22

3-
This project is officially deprecated in favor of [Docker Machine](https://docs.docker.com/machine/). The code and documentation here only exist as a reference for users who have not yet switched over (but please do soon).
3+
This project is officially deprecated in favor of [Docker
4+
Machine](https://docs.docker.com/machine/). The code and documentation here
5+
only exist as a reference for users who have not yet switched over (but please
6+
do soon). The recommended way to install Machine is with the [Docker
7+
Toolbox](https://docker.com/toolbox).
48

59
# boot2docker command line management tool
610

main.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package main
22

33
import (
44
"fmt"
5+
"io/ioutil"
6+
"net/http"
57
"os"
6-
"path/filepath"
78
)
89

910
// The following vars will be injected during the build process.
@@ -12,6 +13,16 @@ var (
1213
GitSHA string
1314
)
1415

16+
const (
17+
hardcodedWarning = `
18+
WARNING: The 'boot2docker' command line interface is being officially deprecated.
19+
Users are expected to switch to Docker Machine (https://docs.docker.com/machine/) instead ASAP.
20+
The Docker Toolbox is the recommended way to install it: https://docker.com/toolbox/
21+
22+
`
23+
warningURL = "https://raw.githubusercontent.com/boot2docker/boot2docker-cli/master/DEPRECATION_WARNING"
24+
)
25+
1526
type unknownCommandError struct {
1627
cmd string
1728
}
@@ -21,8 +32,6 @@ func (e unknownCommandError) Error() string {
2132
}
2233

2334
func main() {
24-
fmt.Fprintf(os.Stderr, "\n WARNING: the %q command is officially deprecated.\n Please switch to Docker Machine (https://docs.docker.com/machine/)\n as soon as possible.\n\n", filepath.Base(os.Args[0]))
25-
2635
// os.Exit will terminate the program at the place of call without running
2736
// any deferred cleanup statements. It might cause unintended effects. To
2837
// be safe, we wrap the program in run() and only os.Exit() outside the
@@ -51,8 +60,10 @@ func run() error {
5160
case "config", "cfg":
5261
return cmdConfig()
5362
case "init":
63+
printDeprecationWarning()
5464
return cmdInit()
5565
case "up", "start", "boot", "resume":
66+
printDeprecationWarning()
5667
return cmdUp()
5768
case "save", "suspend":
5869
return cmdSave()
@@ -91,3 +102,27 @@ func run() error {
91102
return unknownCommandError{cmd: cmd}
92103
}
93104
}
105+
106+
func printDeprecationWarning() {
107+
var (
108+
warning string
109+
)
110+
111+
// Try to get the warning from the Github raw URL. If there's any
112+
// failure along the way, e.g. network, just fall back to the default
113+
// warning hardcoded in the source.
114+
resp, err := http.Get(warningURL)
115+
if err != nil || resp.StatusCode != http.StatusOK {
116+
warning = hardcodedWarning
117+
} else {
118+
defer resp.Body.Close()
119+
body, err := ioutil.ReadAll(resp.Body)
120+
if err != nil {
121+
warning = hardcodedWarning
122+
} else {
123+
warning = string(body)
124+
}
125+
}
126+
127+
fmt.Fprintln(os.Stderr, warning)
128+
}

0 commit comments

Comments
 (0)