-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use urfave/cli package; add verbose flag; print metrics; refactor driver
- Loading branch information
1 parent
7ebd2c8
commit cdd2f5d
Showing
13 changed files
with
315 additions
and
165 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
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
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 |
---|---|---|
@@ -1,10 +1,8 @@ | ||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= | ||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= | ||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= | ||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= | ||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= | ||
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= | ||
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= | ||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= | ||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= | ||
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= |
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 |
---|---|---|
@@ -1,69 +1,82 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"salami/common/constants" | ||
"salami/common/driver" | ||
"strings" | ||
|
||
"github.com/fatih/color" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
const GENERAL_COMMAND = "salami" | ||
|
||
var command_list = map[string]map[string]string{ | ||
"version": { | ||
"cmd": "version", | ||
"description": "Print the version of the installed Salami CLI", | ||
}, | ||
"compile": { | ||
"cmd": "compile", | ||
"description": "Run the compilation end-to-end", | ||
}, | ||
type SalamiMultiError struct { | ||
errors []error | ||
} | ||
|
||
func showCommands() { | ||
fmt.Println("Usage: \n \t ", GENERAL_COMMAND, "<command>\n ") | ||
fmt.Println("The commands are:") | ||
for id, command_ := range command_list { | ||
fmt.Println(color.HiBlueString(id), ":", command_["description"]) | ||
func (m *SalamiMultiError) Error() string { | ||
msgs := []string{} | ||
for _, err := range m.errors { | ||
msgs = append(msgs, err.Error()) | ||
} | ||
fmt.Println() | ||
return strings.Join(msgs, ", ") | ||
} | ||
|
||
func runSystem() { | ||
errors := driver.Run() | ||
|
||
for _, err := range errors { | ||
color.Red(err.Error()) | ||
} | ||
func (m *SalamiMultiError) Errors() []error { | ||
return m.errors | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
command := flag.Arg(0) | ||
app := &cli.App{ | ||
Name: "salami", | ||
HelpName: "Salami", | ||
Version: constants.SalamiVersion, | ||
Usage: "a declarative DSL for cloud infrastructure based on natural language descriptions", | ||
UsageText: "salami [global options] [command] [command options]", | ||
HideVersion: true, | ||
Suggest: true, | ||
Flags: []cli.Flag{ | ||
&cli.BoolFlag{ | ||
Name: "verbose", | ||
Aliases: []string{"v"}, | ||
Usage: "Enable verbose mode", | ||
}, | ||
}, | ||
Commands: []*cli.Command{ | ||
{ | ||
Name: "compile", | ||
Usage: "Runs the compilation end-to-end", | ||
UsageText: "salami [global options] compile [command options]", | ||
Action: func(cCtx *cli.Context) error { | ||
verbose := cCtx.Bool("verbose") | ||
errors := driver.Run(verbose) | ||
|
||
if len(errors) == 1 { | ||
return errors[0] | ||
} else if len(errors) > 1 { | ||
return &SalamiMultiError{errors: errors} | ||
} | ||
|
||
if command == "" { | ||
color.Green("====================================") | ||
color.Green("======= Welcome to Salami CLI ======") | ||
color.Green("====================================\n ") | ||
fmt.Println("Salami is a declarative domain-specific language for cloud infrastructure based on natural language descriptions. " + | ||
"Salami compiler uses GPT4 to convert the natural language to Terraform code. You can think of Salami as writing documentation " + | ||
"for each cloud resource object, and letting the compiler take care of converting that to IaC (Infrastructure as Code).", | ||
) | ||
showCommands() | ||
return | ||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: "version", | ||
Usage: "Prints the version", | ||
Action: func(cCtx *cli.Context) error { | ||
fmt.Println("Salami version " + constants.SalamiVersion) | ||
return nil | ||
}, | ||
}, | ||
}, | ||
Authors: []*cli.Author{{ | ||
Name: "Petr Gazarov", | ||
Email: "[email protected]", | ||
}}, | ||
} | ||
|
||
switch cmd := command; cmd { | ||
case command_list["version"]["cmd"]: | ||
fmt.Println("Salami version " + constants.SalamiVersion) | ||
case command_list["compile"]["cmd"]: | ||
runSystem() | ||
case "help": | ||
showCommands() | ||
default: | ||
msg := "Invalid command passed. Type '" + GENERAL_COMMAND + " help'" | ||
color.Red(msg) | ||
if err := app.Run(os.Args); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
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.