Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use kutil/tool/cli to send analytics #355

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/kubedb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func main() {
cmd := cmds.NewKubedbCommand(os.Stdin, os.Stdout, os.Stderr, Version)
cmd := cmds.NewKubedbCommand(os.Stdin, os.Stdout, os.Stderr)
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/kubedb.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ kubedb [flags]
-n, --namespace string If present, the namespace scope for this CLI request
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
-s, --server string The address and port of the Kubernetes API server
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
--stderrthreshold severity logs at or above this threshold go to stderr
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
-v, --v Level log level for V logs
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/kubedb_api-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ kubedb api-resources [flags]
-n, --namespace string If present, the namespace scope for this CLI request
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
-s, --server string The address and port of the Kubernetes API server
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
--stderrthreshold severity logs at or above this threshold go to stderr
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
-v, --v Level log level for V logs
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/kubedb_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ kubedb create -f FILENAME
-n, --namespace string If present, the namespace scope for this CLI request
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
-s, --server string The address and port of the Kubernetes API server
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
--stderrthreshold severity logs at or above this threshold go to stderr
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
-v, --v Level log level for V logs
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/kubedb_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ kubedb delete ([-f FILENAME] | TYPE [(NAME | -l label | --all)])
-n, --namespace string If present, the namespace scope for this CLI request
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
-s, --server string The address and port of the Kubernetes API server
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
--stderrthreshold severity logs at or above this threshold go to stderr
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
-v, --v Level log level for V logs
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/kubedb_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ kubedb describe (-f FILENAME | TYPE [NAME_PREFIX | -l label] | TYPE/NAME)
-n, --namespace string If present, the namespace scope for this CLI request
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
-s, --server string The address and port of the Kubernetes API server
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
--stderrthreshold severity logs at or above this threshold go to stderr
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
-v, --v Level log level for V logs
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/kubedb_edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ kubedb edit (RESOURCE/NAME | -f FILENAME)
-f, --filename strings Filename, directory, or URL to files to use to edit the resource
-h, --help help for edit
--include-uninitialized If true, the kubectl command applies to uninitialized objects. If explicitly set to false, this flag overrides other flags that make the kubectl commands apply to uninitialized objects, e.g., "--all". Objects with empty metadata.initializers are regarded as initialized.
-o, --output string Output format. One of: json|yaml|name|go-template|go-template-file|templatefile|template|jsonpath|jsonpath-file.
-o, --output string Output format. One of: json|yaml|name|template|go-template|go-template-file|templatefile|jsonpath|jsonpath-file.
--output-patch Output the patch if the resource is edited.
--record Record current kubectl command in the resource annotation. If set to false, do not record the command. If set to true, record the command. If not set, default to updating the existing annotation value only if one already exists.
-R, --recursive Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.
Expand Down Expand Up @@ -71,7 +71,7 @@ kubedb edit (RESOURCE/NAME | -f FILENAME)
-n, --namespace string If present, the namespace scope for this CLI request
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
-s, --server string The address and port of the Kubernetes API server
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
--stderrthreshold severity logs at or above this threshold go to stderr
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
-v, --v Level log level for V logs
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/kubedb_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ kubedb get [(-o|--output=)json|yaml|wide|custom-columns=...|custom-columns-file=
-n, --namespace string If present, the namespace scope for this CLI request
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
-s, --server string The address and port of the Kubernetes API server
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
--stderrthreshold severity logs at or above this threshold go to stderr
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
-v, --v Level log level for V logs
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/kubedb_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ kubedb version [flags]
-n, --namespace string If present, the namespace scope for this CLI request
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
-s, --server string The address and port of the Kubernetes API server
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
--stderrthreshold severity logs at or above this threshold go to stderr
--token string Bearer token for authentication to the API server
--user string The name of the kubeconfig user to use
-v, --v Level log level for V logs
Expand Down
42 changes: 30 additions & 12 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@ import:
version: v1.1.1
- package: k8s.io/kube-openapi
version: 0cf8f7e6ed1d2e3d47d02e3b6e559369af24d803
- package: gopkg.in/square/go-jose.v2
version: v2.2.0
2 changes: 1 addition & 1 deletion hack/gendocs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ aliases:

// ref: https://github.com/spf13/cobra/blob/master/doc/md_docs.md
func main() {
rootCmd := cmds.NewKubedbCommand(os.Stdin, os.Stdout, os.Stderr, version)
rootCmd := cmds.NewKubedbCommand(os.Stdin, os.Stdout, os.Stderr)
dir := runtime.GOPath() + "/src/github.com/kubedb/cli/docs/reference"
fmt.Printf("Generating cli markdown tree in: %v\n", dir)
err := os.RemoveAll(dir)
Expand Down
4 changes: 4 additions & 0 deletions hack/revendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def check_antipackage():
{
"package": "github.com/gorilla/websocket",
"version": "v1.4.0"
},
{
"package": "gopkg.in/square/go-jose.v2",
"version": "v2.2.0"
}
]
DEP_LIST = [
Expand Down
21 changes: 4 additions & 17 deletions pkg/cmds/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package cmds
import (
"flag"
"io"
"strings"

v "github.com/appscode/go/version"
"github.com/appscode/kutil/tools/analytics"
"github.com/jpillora/go-ogle-analytics"
"github.com/appscode/kutil/tools/cli"
"github.com/kubedb/cli/pkg/cmds/create"
"github.com/kubedb/cli/pkg/cmds/get"
"github.com/spf13/cobra"
Expand All @@ -17,13 +15,8 @@ import (
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
)

const (
gaTrackingCode = "UA-62096468-20"
)

// NewKubedbCommand creates the `kubedb` command and its nested children.
func NewKubedbCommand(in io.Reader, out, err io.Writer, version string) *cobra.Command {
enableAnalytics := true
func NewKubedbCommand(in io.Reader, out, err io.Writer) *cobra.Command {
cmds := &cobra.Command{
Use: "kubedb",
Short: "Command line interface for KubeDB",
Expand All @@ -32,13 +25,7 @@ func NewKubedbCommand(in io.Reader, out, err io.Writer, version string) *cobra.C

Find more information at https://github.com/kubedb/cli.`),
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if enableAnalytics && gaTrackingCode != "" {
if client, err := ga.NewClient(gaTrackingCode); err == nil {
client.ClientID(analytics.ClientID())
parts := strings.Split(cmd.CommandPath(), " ")
client.Send(ga.NewEvent(parts[0], strings.Join(parts[1:], "/")).Label(version))
}
}
cli.SendAnalytics(cmd, v.Version.Version)
},
Run: runHelp,
}
Expand All @@ -56,7 +43,7 @@ func NewKubedbCommand(in io.Reader, out, err io.Writer, version string) *cobra.C
flags.AddGoFlagSet(flag.CommandLine)
// ref: https://github.com/kubernetes/kubernetes/issues/17162#issuecomment-225596212
flag.CommandLine.Parse([]string{})
flags.BoolVar(&enableAnalytics, "analytics", enableAnalytics, "Send analytical events to Google Analytics")
flags.BoolVar(&cli.EnableAnalytics, "analytics", cli.EnableAnalytics, "Send analytical events to Google Analytics")

f := cmdutil.NewFactory(matchVersionKubeConfigFlags)

Expand Down
43 changes: 43 additions & 0 deletions vendor/github.com/appscode/go/log/golog/flags.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions vendor/github.com/appscode/go/log/golog/logs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading