mukan-ignite/ignite/internal/tools/gen-mig-diffs/pkg/scaffold/commands.go
Mukan Erkin Törük c32551b6f7
Some checks failed
Docs Deploy / build_and_deploy (push) Has been cancelled
Generate Docs / cli (push) Has been cancelled
Generate Config Doc / cli (push) Has been cancelled
Go formatting / go-formatting (push) Has been cancelled
Check links / markdown-link-check (push) Has been cancelled
Integration / pre-test (push) Has been cancelled
Integration / test on (push) Has been cancelled
Integration / status (push) Has been cancelled
Lint / Lint Go code (push) Has been cancelled
Test / test (ubuntu-latest) (push) Has been cancelled
refactor: replace all github.com upstream refs with git.cw.tr/mukan-network
2026-05-11 03:36:24 +03:00

119 lines
3.3 KiB
Go

package scaffold
import "git.cw.tr/mukan-network/mukan-ignite/ignite/pkg/errors"
type (
// Command represents a set of command and prerequisites scaffold command that are required to run before them.
Command struct {
// Name is the unique identifier of the command
Name string
// Prerequisite is the name of command that need to be run before this command set
Prerequisite string
// Commands is the list of scaffold command that are going to be run
// The command will be prefixed with "ignite scaffold" and executed in order
Commands []string
}
Commands []Command
)
func (c Commands) Get(name string) (Command, error) {
for _, cmd := range c {
if cmd.Name == name {
return cmd, nil
}
}
return Command{}, errors.Errorf("command %s not exist", name)
}
func (c Commands) Has(name string) bool {
for _, cmd := range c {
if cmd.Name == name {
return true
}
}
return false
}
func (c Commands) Validate() error {
cmdMap := make(map[string]bool)
for i, command := range c {
if cmdMap[command.Name] {
return errors.Errorf("duplicate command name found: %s", command.Name)
}
cmdMap[command.Name] = true
if command.Name == "" {
return errors.Errorf("empty command name at index %d: %v", i, command)
}
if len(command.Commands) == 0 {
return errors.Errorf("empty command list at index %d: %v", i, command)
}
}
for _, command := range c {
if command.Prerequisite != "" && !cmdMap[command.Prerequisite] {
return errors.Errorf("command %s pre-requisete %s not found", command.Name, command.Prerequisite)
}
}
return nil
}
var defaultCommands = Commands{
Command{
Name: "chain",
Commands: []string{"chain example --no-module"},
},
Command{
Name: "module",
Prerequisite: "chain",
Commands: []string{"module example --ibc"},
},
Command{
Name: "list",
Prerequisite: "module",
Commands: []string{
"list list1 f1:string f2:strings f3:bool f4:int f5:ints f6:uint f7:uints f8:coin f9:coins --module example --yes",
},
},
Command{
Name: "map",
Prerequisite: "module",
Commands: []string{
"map map1 f1:string f2:strings f3:bool f4:int f5:ints f6:uint f7:uints f8:coin f9:coins --index i1:string --module example --yes",
},
},
Command{
Name: "single",
Prerequisite: "module",
Commands: []string{
"single single1 f1:string f2:strings f3:bool f4:int f5:ints f6:uint f7:uints f8:coin f9:coins --module example --yes",
},
},
Command{
Name: "type",
Prerequisite: "module",
Commands: []string{
"type type1 f1:string f2:strings f3:bool f4:int f5:ints f6:uint f7:uints f8:coin f9:coins --module example --yes",
},
},
Command{
Name: "message",
Prerequisite: "module",
Commands: []string{
"message message1 f1:string f2:strings f3:bool f4:int f5:ints f6:uint f7:uints f8:coin f9:coins --module example --yes",
},
},
Command{
Name: "query",
Prerequisite: "module",
Commands: []string{
"query query1 f1:string f2:strings f3:bool f4:int f5:ints f6:uint f7:uints --module example --yes",
},
},
Command{
Name: "packet",
Prerequisite: "module",
Commands: []string{
"packet packet1 f1:string f2:strings f3:bool f4:int f5:ints f6:uint f7:uints f8:coin f9:coins --ack f1:string,f2:strings,f3:bool,f4:int,f5:ints,f6:uint,f7:uints,f8:coin,f9:coins --module example --yes",
},
},
}