-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpython
More file actions
executable file
·51 lines (43 loc) · 1.09 KB
/
npython
File metadata and controls
executable file
·51 lines (43 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env ruby
require_relative "lib/dsl/python"
require_relative "lib/dsl/python/version"
VERSION=Dsl::Python::VERSION
def open_repl
text = <<~TEXT
nPython #{VERSION} (main, Nov 16 1970) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
TEXT
puts text
system("irb --prompt simple --nocolorize --noecho-on-assignment -Ilib -rdsl/python")
end
def show_version
puts "npython (#{VERSION})"
end
def show_help
text = <<~TEXT
usage: npython [option | file ]
Options:
-h : print this help message and exit (also -? or --help)
-v : show current version (also -V or --version)
Arguments:
file : program read from script file
TEXT
puts text
end
def run_program(name)
unless File.exist? name
puts "npython: can't open file '#{name}': [Errno 2] No such file or directory"
exit 1
end
content = File.read(name)
eval(content)
end
if ARGV.size.zero?
open_repl
elsif ["-v", "--version", "-V"].include? ARGV.first
show_version
elsif ["-h", "--help", "-?"].include? ARGV.first
show_help
else
run_program ARGV.first
end