Skip to content

Remove resource type from CLI #458

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

Merged
merged 3 commits into from
Sep 13, 2019
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
6 changes: 3 additions & 3 deletions build/test-examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ for example in $ROOT/examples/*/cortex.yaml; do
echo "Deploying $example_base_dir"
$CORTEX refresh

api_names="$($CORTEX get api | sed '1,2d' | sed '/^$/d' | tr -s ' ' | cut -f 1 -d " ")"
api_names="$($CORTEX get | sed '1,2d' | sed '/^$/d' | tr -s ' ' | cut -f 1 -d " ")"
sample="$(find . -name "*.json")"

while true; do
Expand All @@ -41,8 +41,8 @@ for example in $ROOT/examples/*/cortex.yaml; do
exit 1
fi

ready_count="$($CORTEX get api | sed '1,2d' | sed '/^$/d' | { grep "ready" || test $? = 1; } | wc -l)"
total_count="$($CORTEX get api | sed '1,2d' | sed '/^$/d' | wc -l)"
ready_count="$($CORTEX get | sed '1,2d' | sed '/^$/d' | { grep "ready" || test $? = 1; } | wc -l)"
total_count="$($CORTEX get | sed '1,2d' | sed '/^$/d' | wc -l)"

sleep 15 # account for API startup delay

Expand Down
32 changes: 5 additions & 27 deletions cli/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func init() {
}

var getCmd = &cobra.Command{
Use: "get [RESOURCE_TYPE] [RESOURCE_NAME]",
Use: "get [RESOURCE_NAME]",
Short: "get information about resources",
Long: "Get information about resources.",
Args: cobra.RangeArgs(0, 2),
Args: cobra.RangeArgs(0, 1),
Run: func(cmd *cobra.Command, args []string) {
rerun(func() (string, error) {
return runGet(cmd, args)
Expand All @@ -79,34 +79,12 @@ func runGet(cmd *cobra.Command, args []string) (string, error) {
return allResourcesStr(resourcesRes), nil

case 1:
resourceNameOrType := args[0]

resourceType, err := resource.VisibleResourceTypeFromPrefix(resourceNameOrType)
if err != nil {
if rerr, ok := err.(resource.Error); ok && rerr.Kind != resource.ErrInvalidType {
return "", err
}
} else {
return resourcesByTypeStr(resourceType, resourcesRes)
}

if _, err = resourcesRes.Context.VisibleResourceByName(resourceNameOrType); err != nil {
if rerr, ok := err.(resource.Error); ok && rerr.Kind == resource.ErrNameNotFound {
return "", resource.ErrorNameOrTypeNotFound(resourceNameOrType)
}
resourceName := args[0]
if _, err = resourcesRes.Context.VisibleResourceByName(resourceName); err != nil {
return "", err
}

return resourceByNameStr(resourceNameOrType, resourcesRes, flagVerbose)

case 2:
userResourceType := args[0]
resourceName := args[1]
resourceType, err := resource.VisibleResourceTypeFromPrefix(userResourceType)
if err != nil {
return "", resource.ErrorInvalidType(userResourceType)
}
return resourceByNameAndTypeStr(resourceName, resourceType, resourcesRes, flagVerbose)
return resourceByNameStr(resourceName, resourcesRes, flagVerbose)
}

return "", errors.New("too many args") // unexpected
Expand Down
24 changes: 4 additions & 20 deletions cli/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,19 @@ func init() {
}

var logsCmd = &cobra.Command{
Use: "logs [RESOURCE_TYPE] RESOURCE_NAME",
Use: "logs RESOURCE_NAME",
Short: "get logs for a resource",
Long: "Get logs for a resource.",
Args: cobra.RangeArgs(1, 2),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
resourceName, resourceTypeStr := "", ""
switch len(args) {
case 1:
resourceName = args[0]
case 2:
userResourceType := args[0]
resourceName = args[1]

if userResourceType != "" {
resourceType, err := resource.VisibleResourceTypeFromPrefix(userResourceType)
if err != nil {
errors.Exit(err)
}

resourceTypeStr = resourceType.String()
}
}
resourceName := args[0]

appName, err := AppNameFromFlagOrConfig()
if err != nil {
errors.Exit(err)
}

err = StreamLogs(appName, resourceName, resourceTypeStr)
err = StreamLogs(appName, resourceName, resource.APIType.String())
if err != nil {
errors.Exit(err)
}
Expand Down
6 changes: 3 additions & 3 deletions docs/cluster/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The `deploy` command sends all deployment configuration and code to Cortex. If v
Get information about resources.

Usage:
cortex get [RESOURCE_TYPE] [RESOURCE_NAME] [flags]
cortex get [RESOURCE_NAME] [flags]

Flags:
-a, --all-deployments list all deployments
Expand All @@ -42,15 +42,15 @@ The `get` command displays the current state of all resources on the cluster. Sp
Get logs for a resource.

Usage:
cortex logs [RESOURCE_TYPE] RESOURCE_NAME [flags]
cortex logs RESOURCE_NAME [flags]

Flags:
-d, --deployment string deployment name
-e, --env string environment (default "default")
-h, --help help for logs
```

The `logs` command streams logs from the workload corresponding to the specified resource. For example, `cortex logs api my-api` will stream the logs from the most recent api named `my-api`. `RESOURCE_TYPE` is optional (unless there are name colisions), so `cortex logs my-api` will also work.
The `logs` command streams logs from the workload corresponding to the specified resource. For example, `cortex logs my-api` will stream the logs from the most recent api named `my-api`.

## refresh

Expand Down