Module: Erhu

Defined in:
lib/erhu.rb,
lib/erhu/app.rb,
lib/erhu/cli.rb,
lib/erhu/version.rb

Defined Under Namespace

Classes: App, Error

Constant Summary collapse

VERSION =
"0.1.10"

Class Method Summary collapse

Class Method Details

.cliObject



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
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/erhu/cli.rb', line 3

def cli()
  options = {}
  subcommands = {}

  OptionParser.new do |opts|
    opts.banner = "Usage: erhu [command]"
  
    opts.on("-h", "--help", "Prints help") do
      puts """
      erhu init -> init your project
      erhu install(options) -> install your project depends
      erhu exec -> run some shell (add .env to ENV)
      """
      exit
    end
  
    # Define global options here
  
  end.parse!

  subcommands['init'] = Proc.new do |args|
    File.open("Erhufile", "w") do |f|
      f.puts 'target "./thirdparty"'
      f.puts 'git "https://github.com/Tencent/rapidjson", tag: "v1.1.0"'
      f.puts 'package "https://github.com/DaveGamble/cJSON/archive/refs/tags/v1.7.15.zip", name: "cjson"'
    end
    
    # Create Rakefile
    File.open("Rakefile", "w") do |f|
      f.puts 'require "erhu"'
      f.puts
      f.puts 'task :build do |t|'
      f.puts '  Cmd.new().chdir("./build")'
      f.puts '    .run("cmake", "..")'
      f.puts '    .run("make")'
      f.puts 'end'
      f.puts
      f.puts 'task run: [:build] do |t|'
      f.puts '  Cmd.new().chdir("./target").run("./Erhu")'
      f.puts 'end'
    end
  end
  
  subcommands['install'] = Proc.new do |args|
    Erhu::App.new.run
  end

  subcommands['exec'] = Proc.new do |args|
    exec args.join(" ")
  end

  if ARGV.blank?
    Erhu::App.new.run
  elsif subcommands.key?(ARGV.first)
    subcommands[ARGV.first].call(ARGV[1..-1])
  else
    puts "Invalid command. Use -h or --help for usage information."
  end

end