[#929] Modification to comand vela show WORKLOAD_TYPE or TRAIT (#948)

* [#929] Modification to comand vela show WORKLOAD_TYPE or TRAIT

* update the describetion of --web

* [#929] update --web describtion

* update the doc of check-ref-doc.md
This commit is contained in:
just-do1
2021-01-28 12:28:47 +08:00
committed by GitHub
parent fa58501a97
commit 0a6065d7d0
4 changed files with 16 additions and 15 deletions

View File

@@ -11,14 +11,14 @@ Actually, as a important part of its "extensibility" design, KubeVela will alway
Thus, as an end user, the only thing you need to do is:
```console
$ vela show WORKLOAD_TYPE or TRAIT
$ vela show WORKLOAD_TYPE or TRAIT --web
```
This command will automatically open the reference documentation for given workload type or trait in your default browser.
### For Workload Types
Let's take `$ vela show webservice` as example. The detailed schema documentation for `Web Service` workload type will show up immediately as below:
Let's take `$ vela show webservice --web` as example. The detailed schema documentation for `Web Service` workload type will show up immediately as below:
![](../../resources/vela_show_webservice.jpg)
@@ -26,7 +26,7 @@ Note that there's in the section named `Specification`, it even provides you wit
### For Traits
Similarly, we can also do `$ vela show autoscale`:
Similarly, we can also do `$ vela show autoscale --web`:
![](../../resources/vela_show_autoscale.jpg)
@@ -58,7 +58,7 @@ services:
This reference doc feature also works for terminal-only case. For example:
```shell
$ vela show webservice --no-website
$ vela show webservice
# Properties
+-------+----------------------------------------------------------------------------------+---------------+----------+---------+
| NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |

View File

@@ -38,7 +38,7 @@ const (
Port = ":18081"
)
var noWebSite bool
var webSite bool
// NewAppShowCommand shows the reference doc for a workload type or trait
func NewAppShowCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
@@ -56,16 +56,17 @@ func NewAppShowCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command
}
ctx := context.Background()
capabilityName := args[0]
if noWebSite {
return showReferenceConsole(ctx, c, ioStreams, capabilityName)
if webSite {
return startReferenceDocsSite(ctx, c, ioStreams, capabilityName)
}
return startReferenceDocsSite(ctx, c, ioStreams, capabilityName)
return showReferenceConsole(ctx, c, ioStreams, capabilityName)
},
Annotations: map[string]string{
types.TagCommandType: types.TypeStart,
},
}
cmd.Flags().BoolVarP(&noWebSite, "no-website", "", false, "do not start web doc site")
cmd.Flags().BoolVarP(&webSite, "web", "", false, " start web doc site")
cmd.SetOut(ioStreams.Out)
return cmd
}

View File

@@ -265,5 +265,5 @@ func SyncDefinitionToLocal(ctx context.Context, c types.Args, localDefinitionDir
return &template, nil
}
}
return nil, nil
return nil, fmt.Errorf("%s is not a valid workload type or trait", capabilityName)
}

View File

@@ -185,7 +185,7 @@ func setDisplayFormat(format string) {
func (ref *MarkdownReference) GenerateReferenceDocs(baseRefPath string) error {
caps, err := LoadAllInstalledCapability()
if err != nil {
return fmt.Errorf("failed to generate reference docs for all capabilities: %s", err)
return fmt.Errorf("failed to generate reference docs for all capabilities: %w", err)
}
if baseRefPath == "" {
baseRefPath = BaseRefPath
@@ -221,16 +221,16 @@ func (ref *MarkdownReference) CreateMarkdown(caps []types.Capability, baseRefPat
markdownFile := filepath.Join(baseRefPath, capabilityType, fileName)
f, err := os.OpenFile(filepath.Clean(markdownFile), os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
return fmt.Errorf("failed to open file %s: %s", markdownFile, err)
return fmt.Errorf("failed to open file %s: %w", markdownFile, err)
}
if err = os.Truncate(markdownFile, 0); err != nil {
return fmt.Errorf("failed to truncate file %s: %s", markdownFile, err)
return fmt.Errorf("failed to truncate file %s: %w", markdownFile, err)
}
capName := c.Name
cueValue, err := common.GetCUEParameterValue(c.CueTemplate)
if err != nil {
return fmt.Errorf("failed to retrieve `parameters` value from %s with err: %s", c.Name, err)
return fmt.Errorf("failed to retrieve `parameters` value from %s with err: %w", c.Name, err)
}
refContent = ""
var defaultDepth = 0
@@ -407,7 +407,7 @@ func (ref *ConsoleReference) GenerateCapabilityProperties(capability *types.Capa
cueValue, err := common.GetCUEParameterValue(capability.CueTemplate)
if err != nil {
return nil, fmt.Errorf("failed to retrieve `parameters` value from %s with err: %s", capName, err)
return nil, fmt.Errorf("failed to retrieve `parameters` value from %s with err: %w", capName, err)
}
var defaultDepth = 0
recurseDepth = &defaultDepth