Skip to content

Commit feea891

Browse files
reduce deliverables footprint
- corectld is now just a symlink to corectl Signed-off-by: António Meireles <antonio.meireles@reformi.st>
1 parent 8a398fb commit feea891

22 files changed

Lines changed: 372 additions & 384 deletions

File tree

‎Makefile‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ CP = /bin/cp
2929
MV = /bin/mv
3030
RM = /bin/rm -rf
3131
DATE = /bin/date
32+
LN = /bin/ln -sf
3233
SED = /usr/bin/sed
3334
GREP = /usr/bin/grep
3435
TOUCH = /usr/bin/touch
@@ -52,20 +53,12 @@ documentation: documentation/man documentation/markdown
5253

5354
all: clean Godeps hyperkit documentation
5455

55-
cmd: cmd/client cmd/server
56-
57-
cmd/client: force
56+
cmd: force
5857
$(RM) $(BUILD_DIR)/$(PROG)
5958
$(MKDIR) $(BUILD_DIR)
6059
cd $@; $(GOBUILD) -o $(BUILD_DIR)/$(PROG) \
61-
-gcflags "$(GO_GCFLAGS)" -ldflags "$(GO_LDFLAGS)"
62-
@$(TOUCH) $@
63-
64-
cmd/server: force
65-
$(RM) $(BUILD_DIR)/$(DAEMON)
66-
$(MKDIR) $(BUILD_DIR)
67-
cd $@; $(GOBUILD) -o $(BUILD_DIR)/$(DAEMON) \
68-
-gcflags "$(GO_GCFLAGS)" -ldflags "$(GO_LDFLAGS)"
60+
-gcflags "$(GO_GCFLAGS)" -ldflags "$(GO_LDFLAGS)"; \
61+
cd $(BUILD_DIR); $(LN) $(PROG) $(DAEMON)
6962
@$(TOUCH) $@
7063

7164
components/common/assets: force

‎cmd/client/main.go‎

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package main
1818
import (
1919
"github.com/deis/pkg/log"
2020

21-
"github.com/TheNewNormal/corectl/components/common"
2221
"github.com/TheNewNormal/corectl/components/host/session"
2322
"github.com/TheNewNormal/corectl/components/server"
2423
"github.com/TheNewNormal/corectl/components/target/coreos"
@@ -30,7 +29,7 @@ var (
3029
Use: "rm",
3130
Aliases: []string{"rmi"},
3231
Short: "Remove(s) CoreOS image(s) from the local filesystem",
33-
PreRunE: common.DefaultPreRunE,
32+
PreRunE: defaultPreRunE,
3433
RunE: rmCommand,
3534
}
3635
)
@@ -86,5 +85,7 @@ func init() {
8685
rmCmd.Flags().StringP("channel", "c", "alpha", "CoreOS channel")
8786
rmCmd.Flags().StringP("version", "v", "latest", "CoreOS version")
8887
rmCmd.Flags().BoolP("purge", "p", false, "purges outdated images")
89-
rootCmd.AddCommand(rmCmd)
88+
if session.AppName() != "corectld" {
89+
rootCmd.AddCommand(rmCmd)
90+
}
9091
}

‎cmd/docs.go‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) 2016 by António Meireles <antonio.meireles@reformi.st>.
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+
//
15+
16+
package main
17+
18+
import (
19+
"path/filepath"
20+
21+
"github.com/TheNewNormal/corectl/components/common/assets"
22+
"github.com/TheNewNormal/corectl/components/host/session"
23+
"github.com/spf13/cobra"
24+
"github.com/spf13/cobra/doc"
25+
)
26+
27+
var (
28+
utilsCmd = &cobra.Command{
29+
Use: "utils",
30+
Short: "Some developer focused utilies",
31+
Run: func(cmd *cobra.Command, args []string) {
32+
cmd.UsageFunc()(cmd)
33+
},
34+
Hidden: true,
35+
}
36+
manCmd = &cobra.Command{
37+
Use: "genManPages",
38+
Short: "Generates man pages",
39+
PreRunE: defaultPreRunE,
40+
Run: func(cmd *cobra.Command, args []string) {
41+
header := &doc.GenManHeader{
42+
Title: session.AppName(), Source: " ",
43+
}
44+
doc.GenManTree(rootCmd, header,
45+
filepath.Join(session.ExecutableFolder(),
46+
"../documentation/man/"))
47+
},
48+
}
49+
mkdownCmd = &cobra.Command{
50+
Use: "genMarkdownDocs",
51+
Short: "Generates Markdown documentation",
52+
PreRunE: defaultPreRunE,
53+
Run: func(cmd *cobra.Command, args []string) {
54+
doc.GenMarkdownTree(rootCmd,
55+
filepath.Join(session.ExecutableFolder(),
56+
"../documentation/markdown/"))
57+
},
58+
}
59+
)
60+
61+
func init() {
62+
rootCmd.SetUsageTemplate(assets.Contents("cli/helpTemplate.tmpl"))
63+
rootCmd.PersistentFlags().BoolP("debug", "d", false,
64+
"adds additional verbosity, and options, directed at debugging "+
65+
"purposes and power users")
66+
utilsCmd.AddCommand(manCmd, mkdownCmd)
67+
rootCmd.AddCommand(utilsCmd, versionCmd)
68+
}

cmd/client/halt.go renamed to cmd/halt.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@ func killCommand(cmd *cobra.Command, args []string) (err error) {
6161

6262
func init() {
6363
killCmd.Flags().BoolP("all", "a", false, "halts all running instances")
64-
rootCmd.AddCommand(killCmd)
64+
if session.AppName() != "corectld" {
65+
rootCmd.AddCommand(killCmd)
66+
}
6567
}

cmd/client/list.go renamed to cmd/list.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"encoding/json"
2020
"fmt"
2121

22-
"github.com/TheNewNormal/corectl/components/common"
2322
"github.com/TheNewNormal/corectl/components/host/session"
2423
"github.com/TheNewNormal/corectl/components/server"
2524
"github.com/TheNewNormal/corectl/components/target/coreos"
@@ -31,7 +30,7 @@ var (
3130
Use: "ls",
3231
Aliases: []string{"list"},
3332
Short: "Lists the CoreOS images available locally",
34-
PreRunE: common.DefaultPreRunE,
33+
PreRunE: defaultPreRunE,
3534
RunE: lsCommand,
3635
}
3736
)
@@ -86,5 +85,7 @@ func init() {
8685
lsCmd.Flags().BoolP("all", "a", false, "browses all channels")
8786
lsCmd.Flags().BoolP("json", "j", false,
8887
"outputs in JSON for easy 3rd party integration")
89-
rootCmd.AddCommand(lsCmd)
88+
if session.AppName() != "corectld" {
89+
rootCmd.AddCommand(lsCmd)
90+
}
9091
}

cmd/client/load.go renamed to cmd/load.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,7 @@ func loadCommand(cmd *cobra.Command, args []string) (err error) {
121121
}
122122

123123
func init() {
124-
rootCmd.AddCommand(loadFCmd)
124+
if session.AppName() != "corectld" {
125+
rootCmd.AddCommand(loadFCmd)
126+
}
125127
}

‎cmd/main.go‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// Copyright (c) 2016 by António Meireles <antonio.meireles@reformi.st>.
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+
//
15+
16+
package main
17+
18+
import (
19+
"fmt"
20+
"os"
21+
"os/user"
22+
"strings"
23+
24+
"github.com/TheNewNormal/corectl/components/host/session"
25+
"github.com/TheNewNormal/corectl/release"
26+
"github.com/deis/pkg/log"
27+
"github.com/spf13/cobra"
28+
)
29+
30+
var (
31+
rootCmd = &cobra.Command{
32+
Use: session.AppName(),
33+
Short: release.ShortBanner,
34+
Long: release.Banner,
35+
Run: func(cmd *cobra.Command, args []string) {
36+
cmd.UsageFunc()(cmd)
37+
},
38+
SilenceUsage: true,
39+
SilenceErrors: true,
40+
}
41+
ErrNotEnoughRights = fmt.Errorf(
42+
"attempting a privileged operation without proper rights")
43+
ErrTooManyRights = fmt.Errorf("too many privileges invoking %v, "+
44+
"please call it as a regular user", session.AppName())
45+
ErrOwnerUnset = func(cmd *cobra.Command) error {
46+
return fmt.Errorf("attempting to call '%v' without "+
47+
"setting a valid user (--user)", cmd.Name())
48+
}
49+
)
50+
51+
func init() {
52+
if session.AppName() != "corectld" {
53+
rootCmd.PersistentFlags().StringP("server", "s", "127.0.0.1",
54+
"corectld location")
55+
rootCmd.PersistentFlags().MarkHidden("server")
56+
}
57+
rootCmd.PersistentPreRunE =
58+
func(cmd *cobra.Command, args []string) (err error) {
59+
cli := session.Caller.CmdLine
60+
cli.BindPFlags(cmd.Flags())
61+
log.DefaultLogger.SetDebug(cli.GetBool("debug"))
62+
if session.AppName() != "corectld" {
63+
if session.Caller.Privileged {
64+
return ErrTooManyRights
65+
}
66+
} else {
67+
if !session.Caller.Privileged && cmd.Name() == "uuid2mac" {
68+
return ErrNotEnoughRights
69+
}
70+
if session.Caller.Privileged {
71+
if cmd.Name() == "uuid2mac" {
72+
return
73+
}
74+
if cmd.Name() == "start" {
75+
var usr *user.User
76+
usr, err = user.Lookup(cli.GetString("user"))
77+
if err != nil {
78+
return ErrOwnerUnset(cmd)
79+
}
80+
session.Caller.User = usr
81+
} else {
82+
return ErrTooManyRights
83+
}
84+
}
85+
}
86+
if !(strings.HasPrefix(cmd.Name(), "genM") ||
87+
cmd.Name() == "version") {
88+
if err = session.Caller.Network.SetContext(); err != nil {
89+
return
90+
}
91+
err = session.Caller.NormalizeOnDiskLayout()
92+
}
93+
return
94+
}
95+
}
96+
97+
func defaultPreRunE(cmd *cobra.Command, args []string) error {
98+
if len(args) != 0 {
99+
return fmt.Errorf("Incorrect usage. " +
100+
"This command doesn't accept any arguments.")
101+
}
102+
return nil
103+
}
104+
105+
func viperStringSliceBugWorkaround(plain []string) []string {
106+
// getting around https://github.com/spf13/viper/issues/112
107+
var sliced []string
108+
for _, x := range plain {
109+
strip := strings.Replace(
110+
strings.Replace(x, "]", "", -1), "[", "", -1)
111+
for _, y := range strings.Split(strip, ",") {
112+
sliced = append(sliced, y)
113+
}
114+
}
115+
return sliced
116+
}
117+
118+
func main() {
119+
var err error
120+
if session.Caller, err = session.New(); err != nil {
121+
return
122+
}
123+
session.Caller.CmdLine.BindPFlags(rootCmd.PersistentFlags())
124+
if session.AppName() != "corectld" {
125+
session.Caller.ServerAddress =
126+
session.Caller.CmdLine.GetString("server") + ":2511"
127+
}
128+
if err = rootCmd.Execute(); err != nil {
129+
log.Err(err.Error())
130+
os.Exit(-1)
131+
}
132+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,7 @@ func panicCommand(cmd *cobra.Command, args []string) (err error) {
7676
func init() {
7777
panicCmd.Flags().BoolP("random", "r", false,
7878
"hard kill a randomly choosen running instance")
79-
rootCmd.AddCommand(panicCmd)
79+
if session.AppName() != "corectld" {
80+
rootCmd.AddCommand(panicCmd)
81+
}
8082
}

0 commit comments

Comments
 (0)
⌂ 换网址