Repository: datreeio/datree (go)

Issue:
Add examples for commands
**Describe the solution you'd like**
Add examples for  test, publish, config commands. Eventually, we’d want the examples  to show all the possible ways to use the command. Ultimately this will look something this(`kubectl`): 
![image](https://user-images.githubusercontent.com/47917189/149793736-529ff987-4ea6-4a93-a1de-1bdf0cfab083.png)

**Required knowledge**
Golang basic level.

”**How to implement” Suggestion**
In a nutshell, we’ll use Cobra’s `Command` . For instance, adding examples for test command will look like this:

```
cmd := &cobra.Command{
	Use: "name of command",
	Example: Examples(`
		# test the configuration located in root kube folder
		datree test ./kube/**/**.yaml`)
	Run: func(cmd *cobra.Command, args []string) {...},
}
```
1. Inside `pkg/utils`, Add `Examples()` function that accept an input string and will normalize the input. For that, add also a private struct  `normalizer` that will handle the normalization. 

> ``` 
> // Examples normalizes a command's examples.
> func Examples(s string) string {
> 	if len(s) == 0 {
> 		return s
> 	}
> 	return normalizer{s}.trim().indent().string
> }
> 
> // normalizer is a helper struct to normalize the output of the examples.
> const Indentation = `  `
> 
> type normalizer struct {
> 	string
> }
> 
> func (s normalizer) trim() normalizer {
> 	s.string = strings.TrimSpace(s.string)
> 	return s
> }
> 
> func (s normalizer) indent() normalizer {
> 	indentedLines := []string{}
> 	for _, line := range strings.Split(s.string, "\n") {
> 		trimmed := strings.TrimSpace(line)
> 		indented := Indentation + trimmed
> 		indentedLines = append(indentedLines, indented)
> 	}
> 	s.string = strings.Join(indentedLines, "\n")
> 	return s
> }
> ```

2. Create and use the examples in all commands: publish `/cmd/publish/main.go`, test `/cmd/test/main.go`, and config `/cmd/config/main.go`


Pull request:
fix: add examples for commands
Fixes #378 

Please let me know if you want to display examples other than this or need changes in these ones.

Patch:
diff --git a/cmd/config/main.go b/cmd/config/main.go
index f2153df..ee2910a 100644
--- a/cmd/config/main.go
+++ b/cmd/config/main.go
@@ -3,6 +3,7 @@ package config
 import (
 	"github.com/datreeio/datree/bl/messager"
 	"github.com/datreeio/datree/pkg/localConfig"
+	"github.com/datreeio/datree/pkg/utils"
 	"github.com/spf13/cobra"
 )
 
@@ -31,6 +32,10 @@ func New(ctx *ConfigCommandContext) *cobra.Command {
 		Use:   "config",
 		Short: "Configuration management",
 		Long:  `Internal configuration management for datree config file`,
+		Example: utils.Example(`
+		# Change the token in the datree config.yaml file
+		datree config set token <MY_EXAMPLE_TOKEN>
+		`),
 	}
 
 	configCommand.AddCommand(NewSetCommand(ctx))
diff --git a/cmd/publish/main.go b/cmd/publish/main.go
index a4bdc0d..5998f16 100644
--- a/cmd/publish/main.go
+++ b/cmd/publish/main.go
@@ -7,6 +7,7 @@ import (
 	"github.com/datreeio/datree/bl/messager"
 	"github.com/datreeio/datree/pkg/cliClient"
 	"github.com/datreeio/datree/pkg/localConfig"
+	"github.com/datreeio/datree/pkg/utils"
 	"github.com/spf13/cobra"
 )
 
@@ -39,6 +40,12 @@ func New(ctx *PublishCommandContext) *cobra.Command {
 		Use:   "publish <fileName>",
 		Short: "Publish policies configuration for given <fileName>.",
 		Long:  "Publish policies configuration for given <fileName>. Input should be the path to the Policy-as-Code yaml configuration file",
+		Example: utils.Example(`
+		# Publish the policies configuration YAML file
+		datree publish policies.yaml
+
+		# Note You need to first enable Policy-as-Code (PaC) on the settings page in the dashboard
+		`),
 		Args: func(cmd *cobra.Command, args []string) error {
 			if len(args) != 1 {
 				errMessage := "Requires 1 arg\n"
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
new file mode 100644
index 0000000..c498eac
--- /dev/null
+++ b/pkg/utils/utils.go
@@ -0,0 +1,32 @@
+package utils
+
+import "strings"
+
+func Example(s string) string {
+	if len(s) == 0 {
+		return s
+	}
+	return normalize{s}.trim().indent().string
+}
+
+const Indentation = `  `
+
+type normalize struct {
+	string
+}
+
+func (s normalize) trim() normalize {
+	s.string = strings.TrimSpace(s.string)
+	return s
+}
+
+func (s normalize) indent() normalize {
+	indentedLines := []string{}
+	for _, line := range strings.Split(s.string, "\n") {
+		trimmed := strings.TrimSpace(line)
+		indented := Indentation + trimmed
+		indentedLines = append(indentedLines, indented)
+	}
+	s.string = strings.Join(indentedLines, "\n")
+	return s
+}


Test patch:
diff --git a/cmd/test/main.go b/cmd/test/main.go
index 57ea3d2..9521efd 100644
--- a/cmd/test/main.go
+++ b/cmd/test/main.go
@@ -15,6 +15,7 @@ import (
 	"github.com/datreeio/datree/pkg/extractor"
 	"github.com/datreeio/datree/pkg/localConfig"
 	"github.com/datreeio/datree/pkg/printer"
+	"github.com/datreeio/datree/pkg/utils"
 
 	"github.com/briandowns/spinner"
 	"github.com/eiannone/keyboard"
@@ -100,6 +101,16 @@ func New(ctx *TestCommandContext) *cobra.Command {
 		Use:   "test <pattern>",
 		Short: "Execute static analysis for given <pattern>",
 		Long:  "Execute static analysis for given <pattern>. Input should be glob or `-` for stdin",
+		Example: utils.Example(`
+		# Test the configuration using file path
+		datree test kube-prod/deployment.yaml
+
+		# Test the configuration using glob pattern
+		datree test kube-*/*.yaml
+
+		# Test the configuration by sending manifests through stdin
+		cat kube-prod/deployment.yaml | datree test -
+		`),
 		Args: func(cmd *cobra.Command, args []string) error {
 			if len(args) < 1 {
 				errMessage := "Requires at least 1 arg\n"