-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
luc10921
committed
Mar 27, 2023
1 parent
0d2febf
commit c67054a
Showing
5 changed files
with
116 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from abc import ABC, abstractmethod | ||
from argparse import ArgumentParser, _SubParsersAction | ||
|
||
|
||
class ICommand(ABC): | ||
|
||
def __init__(self, main_parser: _SubParsersAction, command_name: str, help_text: str): | ||
self.parser: ArgumentParser = main_parser.add_parser(command_name, help=help_text) | ||
|
||
@abstractmethod | ||
def add_arguments_and_callback(self): | ||
pass | ||
|
||
@staticmethod | ||
@abstractmethod | ||
def execute_command(args: dict): | ||
pass |
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,7 @@ | ||
from boa3.cli_commands.build_command import BuildCommand | ||
from boa3.cli_commands.test_command import TestCommand | ||
|
||
commands = ( | ||
BuildCommand, | ||
TestCommand | ||
) |
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 @@ | ||
import logging | ||
import os | ||
import sys | ||
from argparse import _SubParsersAction | ||
|
||
from boa3.cli_commands.ICommand import ICommand | ||
from boa3.not_boa3 import Boa3 | ||
from boa3.internal.exception.NotLoadedException import NotLoadedException | ||
|
||
|
||
class BuildCommand(ICommand): | ||
|
||
def __init__(self, main_parser: _SubParsersAction): | ||
super().__init__(main_parser, 'build', 'Builds your smart contract') | ||
|
||
def add_arguments_and_callback(self): | ||
self.parser.add_argument("input", help=".py smart contract to compile", type=str) | ||
self.parser.add_argument("-db", "--debug", action='store_true', help="generates a .nefdbgnfo file") | ||
self.parser.add_argument("--project-path", help="Project root path. Path of the contract by default.", type=str) | ||
self.parser.set_defaults(func=self.execute_command) | ||
|
||
@staticmethod | ||
def execute_command(args: dict): | ||
sc_path: str = args['input'] | ||
project_path: str = args['project_path'] | ||
debug: bool = args['debug'] | ||
|
||
if not sc_path.endswith(".py") or not os.path.isfile(sc_path): | ||
logging.error("Input file is not .py") | ||
sys.exit(1) | ||
|
||
fullpath = os.path.realpath(sc_path) | ||
path, filename = os.path.split(fullpath) | ||
|
||
if not project_path: | ||
project_path = os.path.dirname(path) | ||
|
||
try: | ||
Boa3.compile_and_save(sc_path, debug=debug, root_folder=project_path) | ||
logging.info(f"Wrote {filename.replace('.py', '.nef')} to {path}") | ||
except NotLoadedException as e: | ||
error_message = e.message | ||
log_error = 'Could not compile' | ||
if len(error_message) > 0: | ||
log_error += f': {error_message}' | ||
|
||
logging.error(log_error) | ||
except Exception as e: | ||
logging.exception(e) |
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,27 @@ | ||
import sys | ||
from argparse import _SubParsersAction | ||
|
||
from boa3.cli_commands.ICommand import ICommand | ||
|
||
|
||
class TestCommand(ICommand): | ||
|
||
def __init__(self, main_parser: _SubParsersAction): | ||
super().__init__(main_parser, 'test', 'TESTETSTESTSETSETSETSE') | ||
|
||
def add_arguments_and_callback(self): | ||
self.parser.add_argument("num1", help=".py smart contract to compile", type=int) | ||
self.parser.add_argument("num2", help=".py smart contract to compile", type=int) | ||
self.parser.set_defaults(func=self.execute_command) | ||
|
||
@staticmethod | ||
def execute_command(args: dict): | ||
num1: int = args['num1'] | ||
num2: int = args['num2'] | ||
|
||
print("~"*10) | ||
print("num1 = {0}, num2 = {1}".format(num1, num2)) | ||
print("result = {0}".format(num1 + num2)) | ||
print("~"*10) | ||
|
||
sys.exit(0) |