-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds initial implementation for macro
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 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,9 @@ | ||
version: '1' | ||
|
||
domains: | ||
- derivws.com | ||
- binaryws.com | ||
- deriv.dev | ||
|
||
macro: | ||
ticks: ['edit {"ticks": "R_50"}'] |
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,50 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type Config struct { | ||
Version string `yaml:"version"` | ||
Macro map[string][]string `yaml:"macro"` | ||
Domains []string `yaml:"domains"` | ||
} | ||
|
||
type Macro map[string]Executer | ||
|
||
func LoadMacro(path string) (*Macro, error) { | ||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var cfg Config | ||
if err = yaml.Unmarshal(data, &cfg); err != nil { | ||
return nil, err | ||
} | ||
|
||
if cfg.Version != "1" { | ||
return nil, fmt.Errorf("unsupported macro version: %s", cfg.Version) | ||
} | ||
|
||
macro := make(Macro) | ||
for name, rawCommands := range cfg.Macro { | ||
var command Executer | ||
for _, rawCommand := range rawCommands { | ||
cmd, err := CommandFactory(rawCommand, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
command = cmd | ||
break | ||
} | ||
|
||
macro[name] = command | ||
} | ||
|
||
return ¯o, nil | ||
} |