forked from meshery/meshery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request meshery#11338 from humblenginr/model_export
[Feat] `mesheryctl model export` command
- Loading branch information
Showing
6 changed files
with
143 additions
and
7 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
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,62 @@ | ||
package model | ||
|
||
import ( | ||
"fmt" | ||
"github.com/layer5io/meshery/mesheryctl/internal/cli/root/config" | ||
"github.com/layer5io/meshery/mesheryctl/pkg/utils" | ||
"github.com/pkg/errors" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// mesheryctl model export <designname> | ||
var exportModal = &cobra.Command{ | ||
Use: "export", | ||
Short: "export registered models", | ||
Long: "export the registered model to the specified output type", | ||
Example: ` | ||
// Export a model by name | ||
mesheryctl model export <modelname> -o json | ||
mesheryctl model export <modelname> -o yaml | ||
mesheryctl model export <modelname> -l /home/meshery/ | ||
mesheryctl model export <modelname> --include-components true --include-relationships true | ||
`, | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
//Check prerequisite | ||
mctlCfg, err := config.GetMesheryCtl(viper.GetViper()) | ||
if err != nil { | ||
return err | ||
} | ||
err = utils.IsServerRunning(mctlCfg.GetBaseMesheryURL()) | ||
if err != nil { | ||
return err | ||
} | ||
ctx, err := mctlCfg.GetCurrentContext() | ||
if err != nil { | ||
return err | ||
} | ||
err = ctx.ValidateVersion() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
Args: func(_ *cobra.Command, args []string) error { | ||
const errMsg = "Usage: mesheryctl model export [model-name]\nRun 'mesheryctl model export --help' to see detailed help message" | ||
if len(args) == 0 { | ||
return utils.ErrInvalidArgument(errors.New("Please provide a model name. " + errMsg)) | ||
} | ||
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
mctlCfg, err := config.GetMesheryCtl(viper.GetViper()) | ||
if err != nil { | ||
log.Fatalln(err, "error processing config") | ||
} | ||
baseUrl := mctlCfg.GetBaseMesheryURL() | ||
modelName := args[0] | ||
url := fmt.Sprintf("%s/api/meshmodels/models/%s?components=%t&relationships=%t&%s", baseUrl, modelName, includeCompsFlag, includeRelsFlag, utils.GetPageQueryParameter(cmd, pageNumberFlag)) | ||
return exportModel(args[0], cmd, url, false) | ||
}, | ||
} |
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 |
---|---|---|
|
@@ -2074,4 +2074,4 @@ func createArtifactHubPkg(pattern *models.MesheryPattern, user string) ([]byte, | |
} | ||
|
||
return data, nil | ||
} | ||
} |