This repository has been archived by the owner on Sep 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding possbility to add alternate states * Adding alternate states doc * Adding spec for alternate states * Update golden files for help (command added) * Adding doc * Add tests * Fixes after review * Update after review * And update spec * Setting API to experimental * Removed superfluous code * Fixed typo, changed to plurarl, testing remove as well
- Loading branch information
1 parent
0dcc4cd
commit 420e67b
Showing
15 changed files
with
364 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/qlik-oss/corectl/internal" | ||
"github.com/qlik-oss/corectl/printer" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var listAlternateStatesCmd = &cobra.Command{ | ||
Use: "ls", | ||
Args: cobra.ExactArgs(0), | ||
Short: "Print a list of all alternate states in the current app", | ||
Long: "Print a list of all alternate states in the current app", | ||
Example: "corectl state ls", | ||
|
||
Run: func(ccmd *cobra.Command, args []string) { | ||
state := internal.PrepareEngineState(rootCtx, headers, certificates, false) | ||
items := internal.ListAlternateStates(state.Ctx, state.Doc) | ||
printer.PrintStates(items, viper.GetBool("bash")) | ||
}, | ||
} | ||
|
||
var addAlternateStateCmd = &cobra.Command{ | ||
Use: "add <alternate-state-name>", | ||
Args: cobra.ExactArgs(1), | ||
Short: "Add an alternate states in the current app", | ||
Long: "Add an alternate states in the current app", | ||
Example: "corectl state add NAME-1", | ||
|
||
Run: func(ccmd *cobra.Command, args []string) { | ||
stateName := args[0] | ||
if stateName == "" { | ||
internal.FatalError("no state name specified") | ||
} | ||
state := internal.PrepareEngineState(rootCtx, headers, certificates, false) | ||
internal.AddAlternateState(state.Ctx, state.Doc, stateName) | ||
if !viper.GetBool("no-save") { | ||
internal.Save(rootCtx, state.Doc) | ||
} | ||
}, | ||
} | ||
|
||
var removeAlternateStateCmd = &cobra.Command{ | ||
Use: "rm <alternate-state-name>", | ||
Args: cobra.ExactArgs(1), | ||
Short: "Removes an alternate state in the current app", | ||
Long: "Removes an alternate state in the current app", | ||
Example: "corectl state rm NAME-1", | ||
|
||
Run: func(ccmd *cobra.Command, args []string) { | ||
stateName := args[0] | ||
if stateName == "" { | ||
internal.FatalError("no state name specified") | ||
} | ||
state := internal.PrepareEngineState(rootCtx, headers, certificates, false) | ||
internal.RemoveAlternateState(state.Ctx, state.Doc, stateName) | ||
if !viper.GetBool("no-save") { | ||
internal.Save(rootCtx, state.Doc) | ||
} | ||
}, | ||
} | ||
|
||
var alternateStateCmd = &cobra.Command{ | ||
Use: "state", | ||
Short: "Explore and manage alternate states", | ||
Long: "Explore and manage alternate states", | ||
Aliases: []string{"alternatestate"}, | ||
Annotations: map[string]string{ | ||
"command_category": "sub", | ||
"x-qlik-stability": "experimental", | ||
}, | ||
} | ||
|
||
func init() { | ||
alternateStateCmd.AddCommand(listAlternateStatesCmd, addAlternateStateCmd, removeAlternateStateCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## corectl state | ||
|
||
Explore and manage alternate states | ||
|
||
### Synopsis | ||
|
||
Explore and manage alternate states | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for state | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-a, --app string Name or identifier of the app | ||
--certificates string path/to/folder containing client.pem, client_key.pem and root.pem certificates | ||
-c, --config string path/to/config.yml where parameters can be set instead of on the command line | ||
--context string Name of the context used when connecting to Qlik Associative Engine | ||
-e, --engine string URL to the Qlik Associative Engine (default "localhost:9076") | ||
--headers stringToString Http headers to use when connecting to Qlik Associative Engine (default []) | ||
--json Returns output in JSON format if possible, disables verbose and traffic output | ||
--no-data Open app without data | ||
-t, --traffic Log JSON websocket traffic to stdout | ||
--ttl string Qlik Associative Engine session time to live in seconds (default "0") | ||
-v, --verbose Log extra information | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [corectl](corectl.md) - | ||
* [corectl state add](corectl_state_add.md) - Add an alternate states in the current app | ||
* [corectl state ls](corectl_state_ls.md) - Print a list of all alternate states in the current app | ||
* [corectl state rm](corectl_state_rm.md) - Removes an alternate state in the current app | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
## corectl state add | ||
|
||
Add an alternate states in the current app | ||
|
||
### Synopsis | ||
|
||
Add an alternate states in the current app | ||
|
||
``` | ||
corectl state add <alternate-state-name> [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
corectl state add NAME-1 | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for add | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-a, --app string Name or identifier of the app | ||
--certificates string path/to/folder containing client.pem, client_key.pem and root.pem certificates | ||
-c, --config string path/to/config.yml where parameters can be set instead of on the command line | ||
--context string Name of the context used when connecting to Qlik Associative Engine | ||
-e, --engine string URL to the Qlik Associative Engine (default "localhost:9076") | ||
--headers stringToString Http headers to use when connecting to Qlik Associative Engine (default []) | ||
--json Returns output in JSON format if possible, disables verbose and traffic output | ||
--no-data Open app without data | ||
-t, --traffic Log JSON websocket traffic to stdout | ||
--ttl string Qlik Associative Engine session time to live in seconds (default "0") | ||
-v, --verbose Log extra information | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [corectl state](corectl_state.md) - Explore and manage alternate states | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
## corectl state ls | ||
|
||
Print a list of all alternate states in the current app | ||
|
||
### Synopsis | ||
|
||
Print a list of all alternate states in the current app | ||
|
||
``` | ||
corectl state ls [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
corectl state ls | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for ls | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-a, --app string Name or identifier of the app | ||
--certificates string path/to/folder containing client.pem, client_key.pem and root.pem certificates | ||
-c, --config string path/to/config.yml where parameters can be set instead of on the command line | ||
--context string Name of the context used when connecting to Qlik Associative Engine | ||
-e, --engine string URL to the Qlik Associative Engine (default "localhost:9076") | ||
--headers stringToString Http headers to use when connecting to Qlik Associative Engine (default []) | ||
--json Returns output in JSON format if possible, disables verbose and traffic output | ||
--no-data Open app without data | ||
-t, --traffic Log JSON websocket traffic to stdout | ||
--ttl string Qlik Associative Engine session time to live in seconds (default "0") | ||
-v, --verbose Log extra information | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [corectl state](corectl_state.md) - Explore and manage alternate states | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
## corectl state rm | ||
|
||
Removes an alternate state in the current app | ||
|
||
### Synopsis | ||
|
||
Removes an alternate state in the current app | ||
|
||
``` | ||
corectl state rm <alternate-state-name> [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
corectl state rm NAME-1 | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for rm | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-a, --app string Name or identifier of the app | ||
--certificates string path/to/folder containing client.pem, client_key.pem and root.pem certificates | ||
-c, --config string path/to/config.yml where parameters can be set instead of on the command line | ||
--context string Name of the context used when connecting to Qlik Associative Engine | ||
-e, --engine string URL to the Qlik Associative Engine (default "localhost:9076") | ||
--headers stringToString Http headers to use when connecting to Qlik Associative Engine (default []) | ||
--json Returns output in JSON format if possible, disables verbose and traffic output | ||
--no-data Open app without data | ||
-t, --traffic Log JSON websocket traffic to stdout | ||
--ttl string Qlik Associative Engine session time to live in seconds (default "0") | ||
-v, --verbose Log extra information | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [corectl state](corectl_state.md) - Explore and manage alternate states | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package internal | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/qlik-oss/enigma-go" | ||
) | ||
|
||
// ListAlternateStates will return a list of all alternate states in an app. | ||
func ListAlternateStates(ctx context.Context, doc *enigma.Doc) []string { | ||
appLayout, _ := doc.GetAppLayout(ctx) | ||
return appLayout.StateNames | ||
} | ||
|
||
// AddAlternateState will add a named alternate state in the app. | ||
func AddAlternateState(ctx context.Context, doc *enigma.Doc, alternateStateName string) { | ||
err := doc.AddAlternateState(ctx, alternateStateName) | ||
if err != nil { | ||
FatalErrorf("could not add state %s: %s ", alternateStateName, err) | ||
} | ||
} | ||
|
||
// RemoveAlternateState will remove a named alternate state in the app. | ||
func RemoveAlternateState(ctx context.Context, doc *enigma.Doc, alternateStateName string) { | ||
states := ListAlternateStates(ctx, doc) | ||
var stateNameExists bool | ||
for _, state := range states { | ||
if state == alternateStateName { | ||
stateNameExists = true | ||
break | ||
} | ||
} | ||
|
||
if !stateNameExists { | ||
FatalErrorf("no alternate state with the name '%s' found in the app", alternateStateName) | ||
} | ||
|
||
err := doc.RemoveAlternateState(ctx, alternateStateName) | ||
if err != nil { | ||
FatalErrorf("could not remove state %s: %s ", alternateStateName, err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package printer | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/qlik-oss/corectl/internal" | ||
|
||
"github.com/olekukonko/tablewriter" | ||
) | ||
|
||
// PrintStates prints a list of states to system out. | ||
func PrintStates(statesList []string, printAsBash bool) { | ||
if internal.PrintJSON { | ||
internal.PrintAsJSON(statesList) | ||
} else if printAsBash { | ||
for _, state := range statesList { | ||
PrintToBashComp(state) | ||
} | ||
} else { | ||
writer := tablewriter.NewWriter(os.Stdout) | ||
writer.SetAutoFormatHeaders(false) | ||
writer.SetHeader([]string{"Name"}) | ||
|
||
for _, state := range statesList { | ||
writer.Append([]string{state}) | ||
} | ||
writer.Render() | ||
} | ||
} |
Oops, something went wrong.