Sha256: 9ec4ec19ae10abb24af3600c361c09c5a889b8adafabb6d33e36cf7b071a5ab3

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 KB

Contents

#!/usr/bin/env ruby
require 'gli'
require 'clenver'
require 'clenver/project'

include GLI::App

program_desc 'Describe your application here'

version Clenver::VERSION

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 init here'
arg_name 'Describe arguments to init here'
command :init do |c|
  c.desc 'Describe a switch to init'
  c.switch :s

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

    # Your command logic here

    puts "args: #{args}"
    puts "options: #{options}"
    puts "global_options: #{global_options}"
    unless args.empty?
      path = args[0]
      dst_dist = args[1]
      if File.exist?(path)
        begin
          yaml = Psych.load_file("#{path}")
          p = Project.new(File.basename("#{path}", ".yml"), yaml)
          if dst_dist
            p.create_repos(dst_dist)
          else
            p.create_repos()
          end
          p.init_repos
        rescue Psych::SyntaxError => ex
          exit_now!("#{path}: syntax error : #{ex.message}", 1)
        end
      else
        exit_now!("#{path} no such file or directory", 2)
      end
    else
      exit_now!("pass config file as a clenver init argument", 2)
    end
    # If you have any errors, just raise them
    # raise "that command made no sense"
  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

exit run(ARGV)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clenver-0.1.3 bin/clenver
clenver-0.1.2 bin/clenver