-
-
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.
- Loading branch information
Showing
6 changed files
with
218 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from wandbox import __bash__ as bash | ||
from wandbox import __cc__ as cc | ||
from wandbox import __cmake__ as cmake | ||
from wandbox import __coffee__ as coffee | ||
from wandbox import __cpp__ as cpp | ||
from wandbox import __crystal__ as crystal | ||
from wandbox import __csharp__ as cs | ||
from wandbox import __cxx__ as cxx | ||
from wandbox import __dmd__ as dmd | ||
from wandbox import __elixir__ as elixir | ||
from wandbox import __erlang__ as erlang | ||
from wandbox import __fsharp__ as fs | ||
from wandbox import __ghc__ as ghc | ||
from wandbox import __go__ as go | ||
from wandbox import __groovy__ as groovy | ||
from wandbox import __java__ as java | ||
from wandbox import __js__ as js | ||
from wandbox import __julia__ as julia | ||
from wandbox import __lazyk__ as lazyk | ||
from wandbox import __lisp__ as lisp | ||
from wandbox import __lua__ as lua | ||
from wandbox import __nim__ as nim | ||
from wandbox import __ocaml__ as ocaml | ||
from wandbox import __openssl__ as openssl | ||
from wandbox import __pascal__ as pascal | ||
from wandbox import __perl__ as perl | ||
from wandbox import __php__ as php | ||
from wandbox import __pony__ as pony | ||
from wandbox import __python__ as python | ||
from wandbox import __r__ as rscript | ||
from wandbox import __ruby__ as ruby | ||
from wandbox import __rust__ as rust | ||
from wandbox import __scala__ as scala | ||
from wandbox import __sql__ as sql | ||
from wandbox import __swift__ as swift | ||
from wandbox import __tsc__ as tsc | ||
from wandbox import __vim__ as vim | ||
|
||
|
||
def get_all_cli(): | ||
clis = [ | ||
bash.BashCLI.InnerCLI(), | ||
cc.CcCLI(), | ||
cmake.CMakeCLI(), | ||
coffee.CoffeeCLI(), | ||
cpp.CppCLI(), | ||
crystal.CrystalCLI(), | ||
cs.CsCLI(), | ||
cxx.CxxCLI(), | ||
dmd.DCLI(), | ||
elixir.ElixirCLI(), | ||
erlang.ErlangCLI(), | ||
fs.FsCLI(), | ||
ghc.GhcCLI(), | ||
go.GoCLI(), | ||
groovy.GroovyCLI(), | ||
java.JavaCLI(), | ||
js.JsCLI(), | ||
julia.JuliaCLI(), | ||
lazyk.LazyKCLI(), | ||
lisp.LispCLI(), | ||
lua.LuaCLI(), | ||
nim.NimCLI(), | ||
ocaml.OCamlCLI(), | ||
openssl.OpenSSLCLI.InnerCLI(), | ||
pascal.PascalCLI(), | ||
perl.PerlCLI(), | ||
php.PhpCLI(), | ||
pony.PonyCLI(), | ||
python.PythonCLI(), | ||
rscript.RscriptCLI(), | ||
ruby.RubyCLI(), | ||
rust.RustCLI(), | ||
scala.ScalaCLI(), | ||
sql.SqlCLI(), | ||
swift.SwiftCLI(), | ||
tsc.TscCLI(), | ||
vim.VimCLI() | ||
] | ||
return clis |
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,123 @@ | ||
import re | ||
import sys | ||
from . import __version__ as VERSION | ||
|
||
from .__all__ import get_all_cli | ||
|
||
from .wandbox import Wandbox | ||
from .wandbox_compile_response import WandboxCompileResponse | ||
from .utils import text_transform | ||
from argparse import ArgumentParser | ||
|
||
|
||
class StatusCLI: | ||
|
||
def __init__(self): | ||
self.setup() | ||
|
||
# command line option | ||
def setup(self): | ||
self.parser = ArgumentParser() | ||
self.parser.add_argument( | ||
'-v', | ||
'--version', | ||
action='version', | ||
version=u'%(prog)s version ' + VERSION | ||
) | ||
self.parser.add_argument( | ||
'-l', | ||
'--language', | ||
required=True, | ||
help='specify language' | ||
) | ||
self.parser.add_argument( | ||
'-c', | ||
'--compiler', | ||
help='specify compiler (can use fnmatch, use first match compiler. e.g. clang-3.9.*[!c] => clang-3.9.1)' | ||
) | ||
self.parser.add_argument( | ||
'-V', | ||
'--verbose', | ||
action='store_true', | ||
help='verbose log' | ||
) | ||
|
||
def parse_command_line(self, argv): | ||
return self.parser.parse_args(argv) | ||
|
||
def execute(self): | ||
self.execute_with_args() | ||
|
||
def execute_with_args(self, args=None): | ||
opts = self.parse_command_line(args) | ||
|
||
language, compiler, *_ = re.split(r'[\s:,]', opts.language, 2) + [None] | ||
clis = get_all_cli() | ||
cli = next((cli for cli in clis if cli.language == language), None) | ||
|
||
if cli is None: | ||
print("error: \"{}\" language is not found".format(language)) | ||
self.parser.print_help() | ||
sys.exit(1) | ||
|
||
if opts.compiler: | ||
compiler = opts.compiler | ||
|
||
run_options = ['run-template'] | ||
cli_options = ['-c', compiler] if compiler else [] | ||
StatusCLI.verbose = opts.verbose | ||
if opts.verbose: | ||
cli_options.append('-V') | ||
|
||
cli.on_run_response = type(cli.on_run_response)(StatusCLI.OnRunResponse, cli) | ||
cli.execute_with_args(cli_options + run_options) | ||
|
||
@staticmethod | ||
def OnRunResponse(cli, response): | ||
r = WandboxCompileResponse(response) | ||
if r.has_error(): | ||
print(r.error()) | ||
return 1 | ||
if StatusCLI.verbose: | ||
Wandbox.ShowResult(response) | ||
if StatusCLI.CheckResponse(cli, r): | ||
if r.has_signal(): | ||
print(r.signal()) | ||
else: | ||
print('Compile/Runtime Error') | ||
return 1 | ||
print('OK') | ||
return 0 | ||
|
||
@staticmethod | ||
def CheckResponse(cli, r): | ||
if r.has_program_output(): | ||
if not StatusCLI.CheckOutput(cli.language, text_transform(r.program_output())): | ||
return 1 | ||
else: | ||
return 1 | ||
if r.has_status(): | ||
return int(r.status()) | ||
return 0 | ||
|
||
@staticmethod | ||
def CheckOutput(language, output): | ||
if language == "OpenSSL": | ||
return "PRIVATE KEY" in output | ||
elif language == "CPP": | ||
return "42" in output | ||
else: | ||
return "Hello" in output | ||
|
||
|
||
def status(): | ||
cli = StatusCLI() | ||
cli.execute() | ||
|
||
|
||
def main(): | ||
status() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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