added ctl manuals
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* Distribution of this work is permitted, but commercial use and
|
||||
* modifications are strictly prohibited.
|
||||
*/
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -7,7 +7,7 @@
|
||||
* Distribution of this work is permitted, but commercial use and
|
||||
* modifications are strictly prohibited.
|
||||
*/
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -7,7 +7,7 @@
|
||||
* Distribution of this work is permitted, but commercial use and
|
||||
* modifications are strictly prohibited.
|
||||
*/
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -7,7 +7,7 @@
|
||||
* Distribution of this work is permitted, but commercial use and
|
||||
* modifications are strictly prohibited.
|
||||
*/
|
||||
package main
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*
|
||||
* This work is published and licensed under a Creative Commons
|
||||
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
||||
*
|
||||
* Distribution of this work is permitted, but commercial use and
|
||||
* modifications are strictly prohibited.
|
||||
*/
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
yaml "go.yaml.in/yaml/v4"
|
||||
)
|
||||
|
||||
type Util struct {
|
||||
FileUtil
|
||||
ImageUtil
|
||||
AccountUtil
|
||||
GrantUtil
|
||||
rootCmd *cobra.Command
|
||||
}
|
||||
|
||||
func NewUtil() *Util {
|
||||
return &Util{}
|
||||
}
|
||||
|
||||
func (util *Util) GetRooCmd() *cobra.Command {
|
||||
return util.rootCmd
|
||||
}
|
||||
|
||||
func (util *Util) Build() error {
|
||||
var err error
|
||||
execName := filepath.Base(os.Args[0])
|
||||
rootCmd := &cobra.Command{
|
||||
Use: execName,
|
||||
Short: "\nA brief description the command",
|
||||
//SilenceUsage: true,
|
||||
}
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
|
||||
rootCmd.AddCommand(util.CreateFileCmds())
|
||||
rootCmd.AddCommand(util.CreateCollectionCmds())
|
||||
rootCmd.AddCommand(util.CreateImageCmds())
|
||||
rootCmd.AddCommand(util.CreateAccountCmds())
|
||||
rootCmd.AddCommand(util.CreateGrantCmds())
|
||||
|
||||
util.rootCmd = rootCmd
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (util *Util) Exec(args []string) error {
|
||||
var err error
|
||||
util.rootCmd.SetArgs(args)
|
||||
err = util.rootCmd.Execute()
|
||||
return err
|
||||
}
|
||||
|
||||
func (util *Util) Hello(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("hello, world!")
|
||||
}
|
||||
|
||||
func printResponse(res any, err error) {
|
||||
type Response struct {
|
||||
Error bool `yaml:"error" yaml:"error"`
|
||||
Message string `yaml:"message,omitempty" yaml:"message,omitempty"`
|
||||
Result any `yaml:"result,omitempty" yaml:"result,omitempty"`
|
||||
}
|
||||
resp := Response{}
|
||||
if err != nil {
|
||||
resp.Error = true
|
||||
resp.Message = err.Error()
|
||||
} else {
|
||||
resp.Result = res
|
||||
}
|
||||
respBytes, _ := yaml.Marshal(resp)
|
||||
fmt.Printf("---\n%s\n", string(respBytes))
|
||||
}
|
||||
+2
-65
@@ -10,17 +10,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
yaml "go.yaml.in/yaml/v4"
|
||||
"mstore/cmd/mstorectl/command"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
util := NewUtil()
|
||||
util := command.NewUtil()
|
||||
err = util.Build()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
@@ -31,63 +28,3 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
type Util struct {
|
||||
FileUtil
|
||||
ImageUtil
|
||||
AccountUtil
|
||||
GrantUtil
|
||||
rootCmd cobra.Command
|
||||
}
|
||||
|
||||
func NewUtil() *Util {
|
||||
return &Util{}
|
||||
}
|
||||
|
||||
func (util *Util) Build() error {
|
||||
var err error
|
||||
execName := filepath.Base(os.Args[0])
|
||||
rootCmd := cobra.Command{
|
||||
Use: execName,
|
||||
Short: "\nA brief description the command",
|
||||
//SilenceUsage: true,
|
||||
}
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
|
||||
rootCmd.AddCommand(util.CreateFileCmds())
|
||||
rootCmd.AddCommand(util.CreateCollectionCmds())
|
||||
rootCmd.AddCommand(util.CreateImageCmds())
|
||||
rootCmd.AddCommand(util.CreateAccountCmds())
|
||||
rootCmd.AddCommand(util.CreateGrantCmds())
|
||||
|
||||
util.rootCmd = rootCmd
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (util *Util) Exec(args []string) error {
|
||||
var err error
|
||||
util.rootCmd.SetArgs(args)
|
||||
err = util.rootCmd.Execute()
|
||||
return err
|
||||
}
|
||||
|
||||
func (util *Util) Hello(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("hello, world!")
|
||||
}
|
||||
|
||||
func printResponse(res any, err error) {
|
||||
type Response struct {
|
||||
Error bool `yaml:"error" yaml:"error"`
|
||||
Message string `yaml:"message,omitempty" yaml:"message,omitempty"`
|
||||
Result any `yaml:"result,omitempty" yaml:"result,omitempty"`
|
||||
}
|
||||
resp := Response{}
|
||||
if err != nil {
|
||||
resp.Error = true
|
||||
resp.Message = err.Error()
|
||||
} else {
|
||||
resp.Result = res
|
||||
}
|
||||
respBytes, _ := yaml.Marshal(resp)
|
||||
fmt.Printf("---\n%s\n", string(respBytes))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user