-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: CLI contract compile subcommand with --compiler-url option
- Loading branch information
1 parent
0bdf629
commit ae0891b
Showing
1 changed file
with
49 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,49 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/aeternity/aepp-sdk-go/aeternity" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var compilerURL string | ||
var contractCmd = &cobra.Command{ | ||
Use: "contract subcommand", | ||
Short: "Compile, call or deploy smart contracts", | ||
Long: ``, | ||
} | ||
|
||
var compileCmd = &cobra.Command{ | ||
Use: "compile FILENAME COMPILER_URL", | ||
Short: "Send a source file to a compiler", | ||
Long: ``, | ||
Args: cobra.ExactArgs(1), | ||
RunE: compileFunc, | ||
SilenceUsage: true, | ||
} | ||
|
||
func compileFunc(cmd *cobra.Command, args []string) (err error) { | ||
compiler := aeternity.NewCompiler(compilerURL, debug) | ||
file, err := os.Open(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
b, err := ioutil.ReadAll(file) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
bytecode, err := compiler.CompileContract(string(b)) | ||
fmt.Println(bytecode) | ||
return err | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(contractCmd) | ||
contractCmd.AddCommand(compileCmd) | ||
contractCmd.PersistentFlags().StringVarP(&compilerURL, "compiler-url", "c", "http://localhost:3080", "Compiler URL") | ||
} |