#!/usr/bin/env ruby
require 'gli'
# begin # XXX: Remove this begin/rescue before distributing your app
require 'DictFlutterCommand'
# rescue LoadError
#   STDERR.puts "In development, you need to use `bundle exec bin/DictFlutterCommand` to run your app"
#   STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
#   STDERR.puts "Feel free to remove this message from bin/DictFlutterCommand now"
#   exit 64
# end

class App
  extend GLI::App

  program_desc '词典flutter工程管理命令'

  version DictFlutterCommand::VERSION

  subcommand_option_handling :normal
  arguments :strict

  desc 'Describe some switch here'
  switch [:s,:switch]

  desc 'Describe some flag here'
  default_value 'the default'
  arg_name 'The name of the argument'
  flag [:f,:flagname]

  desc 'Describe list here'
  arg_name 'Describe arguments to list here'
  command :list do |c|
    c.desc 'Describe a switch to list'
    c.switch :s

    c.desc 'Describe a flag to list'
    c.default_value 'default'
    c.flag :f
    c.action do |global_options,options,args|

      # Your command logic here

      # If you have any errors, just raise them
      # raise "that command made no sense"

      puts "list command ran"
    end
  end

  desc '下载词典flutter工程'
  arg_name 'Describe arguments to complete here'
  command :clone do |c|
    c.action do |global_options,options,args|
      DictFlutterCommand.clone
    end
  end

  desc '配置flutter环境'
  arg_name 'Describe arguments to add here'
  command :init_flutter do |c|
    c.action do |global_options,options,args|
      DictFlutterCommand.init_flutter
    end
  end

  desc '运行ios demo工程'
  arg_name 'Describe arguments to add here'
  command :run_ios do |c|
    c.action do |global_options,options,args|
      DictFlutterCommand.run_ios
    end
  end

  desc '运行android demo工程'
  arg_name 'Describe arguments to add here'
  command :run_android do |c|
    c.action do |global_options,options,args|
      DictFlutterCommand.run_android
    end
  end

  desc '链接到手机'
  arg_name 'Describe arguments to add here'
  command :attach do |c|
    c.action do |global_options,options,args|
      DictFlutterCommand.attach
    end
  end

  desc '创建一个flutter package'
  arg_name 'Describe arguments to add here'
  command :create_package do |c|
    c.action do |global_options,options,args|
      DictFlutterCommand.create_package(args[0])
    end
  end

  desc 'flutter pub get'
  arg_name 'Describe arguments to add here'
  command :pub_get do |c|
    c.action do |global_options,options,args|
      DictFlutterCommand.pub_get
    end
  end

  desc 'flutter clean'
  arg_name 'Describe arguments to add here'
  command :flutter_clean do |c|
    c.action do |global_options,options,args|
      DictFlutterCommand.flutter_clean
    end
  end

  pre do |global,command,options,args|
    # Pre logic here
    # Return true to proceed; false to abort and not call the
    # chosen command
    # Use skips_pre before a command to skip this block
    # on that command only
    true
  end

  post do |global,command,options,args|
    # Post logic here
    # Use skips_post before a command to skip this
    # block on that command only
  end

  on_error do |exception|
    # Error logic here
    # return false to skip default error handling
    true
  end
end

exit App.run(ARGV)
