Skip to content

Commit

Permalink
fix double log issue
Browse files Browse the repository at this point in the history
Signed-off-by: Ripul Handoo <ripulhandoo1234@gmail.com>
  • Loading branch information
RipulHandoo committed Apr 5, 2024
1 parent 82f532b commit db80c7a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 42 deletions.
37 changes: 12 additions & 25 deletions mesheryctl/internal/cli/root/models/model.go
Expand Up @@ -12,13 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.


package models

import (
"fmt"

"github.com/fatih/color"
"github.com/layer5io/meshery/mesheryctl/internal/cli/root/config"
"github.com/layer5io/meshery/mesheryctl/internal/cli/root/system"
"github.com/layer5io/meshery/mesheryctl/pkg/utils"
Expand All @@ -30,22 +28,12 @@ import (

var (
availableSubcommands = []*cobra.Command{pushModelCmd, pullModelCmd}
// flag used to specify the page number in list command
pageNumberFlag int
// flag used to specify format of output of view {model-name} command
outFormatFlag string

// Maximum number of rows to be displayed in a page
maxRowsPerPage = 25

// Color for the whiteboard printer
whiteBoardPrinter = color.New(color.FgHiBlack, color.BgWhite, color.Bold)

username string
password string
registry string
repository string
tag string
username string
password string
registry string
repository string
tag string
pathToModel string
)

Expand All @@ -70,25 +58,24 @@ mesheryctl exp model view [model-name]
}
err = utils.IsServerRunning(mctlCfg.GetBaseMesheryURL())
if err != nil {
utils.Log.Error(err)
return err
}
ctx, err := mctlCfg.GetCurrentContext()
if err != nil {
utils.Log.Error(system.ErrGetCurrentContext(err))
return err
return system.ErrGetCurrentContext(err)
}
err = ctx.ValidateVersion()
if err != nil {
utils.Log.Error(err)
return err
}
return nil
},
Args: func(_ *cobra.Command, args []string) error {
const errMsg = "Usage: mesheryctl exp model [subcommand]\nRun 'mesheryctl exp model --help' to see detailed help message"
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return utils.ErrInvalidArgument(fmt.Errorf("model subcommand isn't specified\n\n%v", errMsg))
if err := cmd.Usage(); err != nil {
return err
}
return errors.New("Subcommand is required")
}
return nil
},
Expand All @@ -100,7 +87,7 @@ mesheryctl exp model view [model-name]
if err != nil {
log.Fatalln(err, "error processing config")
}

err = cmd.Usage()
if err != nil {
return err
Expand Down
26 changes: 17 additions & 9 deletions mesheryctl/internal/cli/root/models/pull.go
Expand Up @@ -14,13 +14,12 @@

package models


import (
"fmt"

"github.com/layer5io/meshery/mesheryctl/pkg/utils"
"github.com/layer5io/meshkit/models/oci"
"github.com/spf13/cobra"

"github.com/pkg/errors"
)

var pullModelCmd = &cobra.Command{
Expand All @@ -33,22 +32,31 @@ mesheryctl exp model push --username [username] --password [password] --registry
`,
// skip preRunE as it is not required for this command
Args: func(cmd *cobra.Command, args []string) error {
errMsg := "Usage: mesheryctl exp model pull --username [username] --password [password] --registry [registry] --tag [tag] --repository [repository]\nRun 'mesheryctl exp model pull --help' to see detailed help message"
if len(args) < 5 {
// also print 5 argument are required in the error message
return utils.ErrInvalidArgument(fmt.Errorf("%s: expected 5 arguments (username, password, registryURL, repository, image_tag)", errMsg))

// Check if all flags are set
usernameFlag, _ := cmd.Flags().GetString("username")
passwordFlag, _ := cmd.Flags().GetString("password")
registryFlag, _ := cmd.Flags().GetString("registry")
tagFlag, _ := cmd.Flags().GetString("tag")
repositoryFlag, _ := cmd.Flags().GetString("repository")

if usernameFlag == "" || passwordFlag == "" || registryFlag == "" || tagFlag == "" || repositoryFlag == "" {
if err := cmd.Usage(); err != nil {
return err
}
return errors.New("all flags are required")
}

return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
dirPath := "./meshery/models"
err := oci.PullFromOCIRegistry(dirPath, registry, repository, tag, username, password)
if err != nil {
utils.Log.Error(err)
return err
}

fmt.Println("Model pulled successfully")
utils.Log.Info("Model pulled successfully")
return nil
},
}
23 changes: 15 additions & 8 deletions mesheryctl/internal/cli/root/models/push.go
Expand Up @@ -15,10 +15,9 @@
package models

import (
"fmt"

"github.com/layer5io/meshery/mesheryctl/pkg/utils"
"github.com/layer5io/meshkit/models/oci"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand All @@ -31,9 +30,18 @@ var pushModelCmd = &cobra.Command{
mesheryctl exp model push [path-to-model] --username [username] --password [password] --registry [registry] --tag [tag] --repository [repository]
`,
Args: func(cmd *cobra.Command, args []string) error {
errMsg := "Usage: mesheryctl exp model push [path-to-model] --username [username] --password [password] --registry [registry] --tag [tag] --repository [repository]\nRun 'mesheryctl exp model push --help' to see detailed help message"
if len(args) < 5 {
return utils.ErrInvalidArgument(fmt.Errorf("%s: expected 5 arguments (username, password, registryURL, repository, image_tag)", errMsg))
// Check if all flags are set
usernameFlag, _ := cmd.Flags().GetString("username")
passwordFlag, _ := cmd.Flags().GetString("password")
registryFlag, _ := cmd.Flags().GetString("registry")
tagFlag, _ := cmd.Flags().GetString("tag")
repositoryFlag, _ := cmd.Flags().GetString("repository")

if usernameFlag == "" || passwordFlag == "" || registryFlag == "" || tagFlag == "" || repositoryFlag == "" {
if err := cmd.Usage(); err != nil {
return err
}
return errors.New("all flags are required")
}
return nil
},
Expand All @@ -42,11 +50,10 @@ mesheryctl exp model push [path-to-model] --username [username] --password [pass
modelPath := pathToModel
err := oci.PushToOCIRegistry(modelPath, registry, repository, tag, username, password)
if err != nil {
utils.Log.Error(err)
return err
}

fmt.Println("Model pushed successfully")
utils.Log.Info("Model pushed successfully")
return nil
},
}
}

0 comments on commit db80c7a

Please sign in to comment.