-
Notifications
You must be signed in to change notification settings - Fork 14
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 #4 from Peefy/feat-plugin-framework
feat: add plugin framework and mod and registry subcommands
- Loading branch information
Showing
6 changed files
with
416 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/spf13/cobra" | ||
cli "github.com/urfave/cli/v2" | ||
"kcl-lang.io/cli/pkg/version" | ||
"kcl-lang.io/kpm/pkg/client" | ||
kpmcmd "kcl-lang.io/kpm/pkg/cmd" | ||
"kcl-lang.io/kpm/pkg/reporter" | ||
) | ||
|
||
const ( | ||
modDesc = ` | ||
This command manages the kcl module | ||
` | ||
modExample = ` # Init one kcl module | ||
kcl mod init | ||
# Push the module | ||
kcl mod push | ||
` | ||
) | ||
|
||
// NewModCmd returns the mod command. | ||
func NewModCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "mod", | ||
Short: "KCL module management", | ||
Long: modDesc, | ||
Example: modExample, | ||
RunE: func(_ *cobra.Command, args []string) error { | ||
return RunWithKpmMod("mod", args) | ||
}, | ||
SilenceUsage: true, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func RunWithKpmMod(cmd string, args []string) error { | ||
reporter.InitReporter() | ||
kpmcli, err := client.NewKpmClient() | ||
if err != nil { | ||
return err | ||
} | ||
app := cli.NewApp() | ||
app.Usage = "module related functions" | ||
app.Name = "kcl mod" | ||
app.Version = version.GetVersionString() | ||
app.UsageText = "kcl mod <command> [arguments]..." | ||
app.Commands = []*cli.Command{ | ||
kpmcmd.NewInitCmd(kpmcli), | ||
kpmcmd.NewAddCmd(kpmcli), | ||
kpmcmd.NewPkgCmd(kpmcli), | ||
kpmcmd.NewMetadataCmd(kpmcli), | ||
kpmcmd.NewRunCmd(kpmcli), | ||
kpmcmd.NewLoginCmd(kpmcli), | ||
kpmcmd.NewLogoutCmd(kpmcli), | ||
kpmcmd.NewPushCmd(kpmcli), | ||
kpmcmd.NewPullCmd(kpmcli), | ||
} | ||
app.Flags = []cli.Flag{ | ||
&cli.BoolFlag{ | ||
Name: kpmcmd.FLAG_QUIET, | ||
Usage: "push in vendor mode", | ||
}, | ||
} | ||
app.Before = func(c *cli.Context) error { | ||
if c.Bool(kpmcmd.FLAG_QUIET) { | ||
kpmcli.SetLogWriter(nil) | ||
} | ||
return nil | ||
} | ||
argsWithCmd := []string{cmd} | ||
argsWithCmd = append(argsWithCmd, args...) | ||
return app.Run(argsWithCmd) | ||
} |
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,70 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
cli "github.com/urfave/cli/v2" | ||
"kcl-lang.io/cli/pkg/version" | ||
"kcl-lang.io/kpm/pkg/client" | ||
kpmcmd "kcl-lang.io/kpm/pkg/cmd" | ||
"kcl-lang.io/kpm/pkg/reporter" | ||
) | ||
|
||
const ( | ||
registryDesc = ` | ||
This command manages the kcl registry | ||
` | ||
registryExample = ` # Login the registry | ||
kcl registry login docker.io | ||
# Logout the registry | ||
kcl registry logout | ||
` | ||
) | ||
|
||
// NewModCmd returns the mod command. | ||
func NewRegistryCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "registry", | ||
Short: "KCL registry management", | ||
Long: registryDesc, | ||
Example: registryExample, | ||
RunE: func(_ *cobra.Command, args []string) error { | ||
return RunWithKpmRegistry("registry", args) | ||
}, | ||
SilenceUsage: true, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func RunWithKpmRegistry(cmd string, args []string) error { | ||
reporter.InitReporter() | ||
kpmcli, err := client.NewKpmClient() | ||
if err != nil { | ||
return err | ||
} | ||
app := cli.NewApp() | ||
app.Usage = "registry related functions" | ||
app.Name = "kcl registry" | ||
app.Version = version.GetVersionString() | ||
app.UsageText = "kcl registry <command> [arguments]..." | ||
app.Commands = []*cli.Command{ | ||
kpmcmd.NewLoginCmd(kpmcli), | ||
kpmcmd.NewLogoutCmd(kpmcli), | ||
} | ||
app.Flags = []cli.Flag{ | ||
&cli.BoolFlag{ | ||
Name: kpmcmd.FLAG_QUIET, | ||
Usage: "push in vendor mode", | ||
}, | ||
} | ||
app.Before = func(c *cli.Context) error { | ||
if c.Bool(kpmcmd.FLAG_QUIET) { | ||
kpmcli.SetLogWriter(nil) | ||
} | ||
return nil | ||
} | ||
argsWithCmd := []string{cmd} | ||
argsWithCmd = append(argsWithCmd, args...) | ||
return app.Run(argsWithCmd) | ||
} |
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
Oops, something went wrong.