bashly 0.7.0 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/bashly/cli.rb +1 -0
 - data/lib/bashly/commands/add.rb +14 -25
 - data/lib/bashly/commands/generate.rb +20 -19
 - data/lib/bashly/commands/validate.rb +19 -0
 - data/lib/bashly/concerns/command_scopes.rb +68 -0
 - data/lib/bashly/config_validator.rb +143 -0
 - data/lib/bashly/extensions/string.rb +4 -0
 - data/lib/bashly/libraries/base.rb +19 -0
 - data/lib/bashly/libraries/completions.rb +14 -0
 - data/lib/bashly/{library → libraries}/completions_function.rb +18 -6
 - data/lib/bashly/libraries/completions_script.rb +29 -0
 - data/lib/bashly/libraries/completions_yaml.rb +27 -0
 - data/lib/bashly/libraries.yml +39 -0
 - data/lib/bashly/library.rb +63 -0
 - data/lib/bashly/refinements/compose_refinements.rb +45 -0
 - data/lib/bashly/script/base.rb +5 -3
 - data/lib/bashly/script/catch_all.rb +49 -0
 - data/lib/bashly/script/command.rb +9 -111
 - data/lib/bashly/version.rb +1 -1
 - data/lib/bashly/views/command/catch_all_filter.erb +2 -2
 - data/lib/bashly/views/command/command_filter.erb +1 -1
 - data/lib/bashly/views/command/default_assignments.erb +2 -2
 - data/lib/bashly/views/command/default_initialize_script.erb +6 -6
 - data/lib/bashly/views/command/default_root_script.erb +1 -1
 - data/lib/bashly/views/command/environment_variables_filter.erb +1 -1
 - data/lib/bashly/views/command/fixed_flags_filter.erb +1 -1
 - data/lib/bashly/views/command/initialize.erb +1 -1
 - data/lib/bashly/views/command/parse_requirements.erb +1 -0
 - data/lib/bashly/views/command/parse_requirements_case.erb +2 -2
 - data/lib/bashly/views/command/parse_requirements_while.erb +2 -2
 - data/lib/bashly/views/command/root_command.erb +1 -1
 - data/lib/bashly/views/command/run.erb +4 -4
 - data/lib/bashly/views/command/usage.erb +1 -1
 - data/lib/bashly/views/command/usage_args.erb +3 -3
 - data/lib/bashly/views/command/usage_commands.erb +1 -1
 - data/lib/bashly/views/command/user_filter.erb +11 -0
 - data/lib/bashly.rb +2 -1
 - metadata +18 -16
 - data/lib/bashly/library/base.rb +0 -57
 - data/lib/bashly/library/colors.rb +0 -9
 - data/lib/bashly/library/completions.rb +0 -28
 - data/lib/bashly/library/completions_script.rb +0 -17
 - data/lib/bashly/library/completions_yaml.rb +0 -15
 - data/lib/bashly/library/config.rb +0 -9
 - data/lib/bashly/library/sample.rb +0 -9
 - data/lib/bashly/library/strings.rb +0 -12
 - data/lib/bashly/library/validations.rb +0 -9
 - data/lib/bashly/library/yaml.rb +0 -9
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 111e5735cbcae769cf990a20aabd6d2868181251bf366b180d1e0325316a29b0
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 017c1fc803802af3c186b356e9720ed3fd362990ed30b455e12aa2b34b4be6a3
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 743c31be7ec2553940700cda415dcbf377dcf6362b18edc4b3e292130024ddf6b3230e26d48603ca4e90ce17464dc71c07e685741614e5047b6f9570d369b8da
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 88ce26cb94af15fb3813b387d93723a60aea6487038eaeb467ee22e23ea3823cf5bfc06ed8cccab0e8a7d1f5a89a198a117a468516734bce8a92033462f6741a
         
     | 
    
        data/lib/bashly/cli.rb
    CHANGED
    
    
    
        data/lib/bashly/commands/add.rb
    CHANGED
    
    | 
         @@ -32,27 +32,27 @@ module Bashly 
     | 
|
| 
       32 
32 
     | 
    
         
             
                  environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
                  def strings_command
         
     | 
| 
       35 
     | 
    
         
            -
                    add_lib  
     | 
| 
      
 35 
     | 
    
         
            +
                    add_lib 'strings'
         
     | 
| 
       36 
36 
     | 
    
         
             
                  end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
                  def lib_command
         
     | 
| 
       39 
     | 
    
         
            -
                    add_lib  
     | 
| 
      
 39 
     | 
    
         
            +
                    add_lib 'lib'
         
     | 
| 
       40 
40 
     | 
    
         
             
                  end
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         
             
                  def config_command
         
     | 
| 
       43 
     | 
    
         
            -
                    add_lib  
     | 
| 
      
 43 
     | 
    
         
            +
                    add_lib 'config'
         
     | 
| 
       44 
44 
     | 
    
         
             
                  end
         
     | 
| 
       45 
45 
     | 
    
         | 
| 
       46 
46 
     | 
    
         
             
                  def colors_command
         
     | 
| 
       47 
     | 
    
         
            -
                    add_lib  
     | 
| 
      
 47 
     | 
    
         
            +
                    add_lib 'colors'
         
     | 
| 
       48 
48 
     | 
    
         
             
                  end
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
                  def yaml_command
         
     | 
| 
       51 
     | 
    
         
            -
                    add_lib  
     | 
| 
      
 51 
     | 
    
         
            +
                    add_lib 'yaml'
         
     | 
| 
       52 
52 
     | 
    
         
             
                  end
         
     | 
| 
       53 
53 
     | 
    
         | 
| 
       54 
54 
     | 
    
         
             
                  def validations_command
         
     | 
| 
       55 
     | 
    
         
            -
                    add_lib  
     | 
| 
      
 55 
     | 
    
         
            +
                    add_lib 'validations'
         
     | 
| 
       56 
56 
     | 
    
         
             
                  end
         
     | 
| 
       57 
57 
     | 
    
         | 
| 
       58 
58 
     | 
    
         
             
                  def comp_command
         
     | 
| 
         @@ -60,35 +60,24 @@ module Bashly 
     | 
|
| 
       60 
60 
     | 
    
         
             
                    output = args['OUTPUT']
         
     | 
| 
       61 
61 
     | 
    
         | 
| 
       62 
62 
     | 
    
         
             
                    case format
         
     | 
| 
       63 
     | 
    
         
            -
                    when "script"
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
                    
         
     | 
| 
       67 
     | 
    
         
            -
                    when "function"
         
     | 
| 
       68 
     | 
    
         
            -
                      function = output || "send_completions"
         
     | 
| 
       69 
     | 
    
         
            -
                      path = "#{Settings.source_dir}/lib/#{function}.sh"
         
     | 
| 
       70 
     | 
    
         
            -
                      add_lib Library::CompletionsFunction.new(path, function: function)
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
                    when "yaml"
         
     | 
| 
       73 
     | 
    
         
            -
                      path = output || "#{Settings.target_dir}/completions.yml"
         
     | 
| 
       74 
     | 
    
         
            -
                      add_lib Library::CompletionsYAML.new(path)
         
     | 
| 
       75 
     | 
    
         
            -
                    
         
     | 
| 
       76 
     | 
    
         
            -
                    else
         
     | 
| 
       77 
     | 
    
         
            -
                      raise Error, "Unrecognized format: #{format}"
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
      
 63 
     | 
    
         
            +
                    when "script"   then add_lib 'completions_script', output
         
     | 
| 
      
 64 
     | 
    
         
            +
                    when "function" then add_lib 'completions', output
         
     | 
| 
      
 65 
     | 
    
         
            +
                    when "yaml"     then add_lib 'completions_yaml', output
         
     | 
| 
      
 66 
     | 
    
         
            +
                    else            raise Error, "Unrecognized format: #{format}"
         
     | 
| 
       79 
67 
     | 
    
         
             
                    end
         
     | 
| 
       80 
68 
     | 
    
         | 
| 
       81 
69 
     | 
    
         
             
                  end
         
     | 
| 
       82 
70 
     | 
    
         | 
| 
       83 
71 
     | 
    
         
             
                private
         
     | 
| 
       84 
72 
     | 
    
         | 
| 
       85 
     | 
    
         
            -
                  def add_lib( 
     | 
| 
      
 73 
     | 
    
         
            +
                  def add_lib(name, *args)
         
     | 
| 
      
 74 
     | 
    
         
            +
                    library = Bashly::Library.new name, *args
         
     | 
| 
       86 
75 
     | 
    
         
             
                    files_created = 0
         
     | 
| 
       87 
     | 
    
         
            -
                     
     | 
| 
      
 76 
     | 
    
         
            +
                    library.files.each do |file|
         
     | 
| 
       88 
77 
     | 
    
         
             
                      created = safe_write file[:path], file[:content]
         
     | 
| 
       89 
78 
     | 
    
         
             
                      files_created += 1 if created
         
     | 
| 
       90 
79 
     | 
    
         
             
                    end
         
     | 
| 
       91 
     | 
    
         
            -
                    message =  
     | 
| 
      
 80 
     | 
    
         
            +
                    message = library.post_install_message
         
     | 
| 
       92 
81 
     | 
    
         
             
                    say "\n#{message}" if message and files_created > 0
         
     | 
| 
       93 
82 
     | 
    
         
             
                  end
         
     | 
| 
       94 
83 
     | 
    
         | 
| 
         @@ -1,6 +1,8 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Bashly
         
     | 
| 
       2 
2 
     | 
    
         
             
              module Commands
         
     | 
| 
       3 
3 
     | 
    
         
             
                class Generate < Base
         
     | 
| 
      
 4 
     | 
    
         
            +
                  using ComposeRefinements
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
       4 
6 
     | 
    
         
             
                  help "Generate the bash script and required files"
         
     | 
| 
       5 
7 
     | 
    
         | 
| 
       6 
8 
     | 
    
         
             
                  usage "bashly generate [--force --quiet --upgrade --wrap FUNCTION]"
         
     | 
| 
         @@ -13,6 +15,7 @@ module Bashly 
     | 
|
| 
       13 
15 
     | 
    
         | 
| 
       14 
16 
     | 
    
         
             
                  environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
         
     | 
| 
       15 
17 
     | 
    
         
             
                  environment "BASHLY_TARGET_DIR", "The path to use for creating the bash script [default: .]"
         
     | 
| 
      
 18 
     | 
    
         
            +
                  environment "BASHLY_STRICT", "When not empty, enable bash strict mode (set -euo pipefail)"
         
     | 
| 
       16 
19 
     | 
    
         | 
| 
       17 
20 
     | 
    
         
             
                  example "bashly generate --force"
         
     | 
| 
       18 
21 
     | 
    
         
             
                  example "bashly generate --wrap my_function"
         
     | 
| 
         @@ -35,20 +38,9 @@ module Bashly 
     | 
|
| 
       35 
38 
     | 
    
         
             
                      content = File.read file
         
     | 
| 
       36 
39 
     | 
    
         | 
| 
       37 
40 
     | 
    
         
             
                      if content =~ /\[@bashly-upgrade (.+)\]/
         
     | 
| 
       38 
     | 
    
         
            -
                         
     | 
| 
       39 
     | 
    
         
            -
                        
         
     | 
| 
       40 
     | 
    
         
            -
                         
     | 
| 
       41 
     | 
    
         
            -
                        when "colors"
         
     | 
| 
       42 
     | 
    
         
            -
                          upgrade file, Library::Colors.new
         
     | 
| 
       43 
     | 
    
         
            -
                        when "config"
         
     | 
| 
       44 
     | 
    
         
            -
                          upgrade file, Library::Config.new
         
     | 
| 
       45 
     | 
    
         
            -
                        when "yaml"
         
     | 
| 
       46 
     | 
    
         
            -
                          upgrade file, Library::YAML.new
         
     | 
| 
       47 
     | 
    
         
            -
                        when "validations"
         
     | 
| 
       48 
     | 
    
         
            -
                          upgrade file, Library::Validations.new
         
     | 
| 
       49 
     | 
    
         
            -
                        when /completions (.+)/
         
     | 
| 
       50 
     | 
    
         
            -
                          upgrade file, Library::CompletionsFunction.new(file, function: $1)
         
     | 
| 
       51 
     | 
    
         
            -
                        end
         
     | 
| 
      
 41 
     | 
    
         
            +
                        args = $1.split ' '
         
     | 
| 
      
 42 
     | 
    
         
            +
                        library_name = args.shift
         
     | 
| 
      
 43 
     | 
    
         
            +
                        upgrade file, library_name, *args
         
     | 
| 
       52 
44 
     | 
    
         
             
                      end
         
     | 
| 
       53 
45 
     | 
    
         
             
                    end
         
     | 
| 
       54 
46 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -57,8 +49,17 @@ module Bashly 
     | 
|
| 
       57 
49 
     | 
    
         
             
                    Dir["#{Settings.source_dir}/**/*.*"].sort
         
     | 
| 
       58 
50 
     | 
    
         
             
                  end
         
     | 
| 
       59 
51 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
                  def upgrade(existing_file,  
     | 
| 
       61 
     | 
    
         
            -
                     
     | 
| 
      
 52 
     | 
    
         
            +
                  def upgrade(existing_file, library_name, *args)
         
     | 
| 
      
 53 
     | 
    
         
            +
                    if Library.exist? library_name
         
     | 
| 
      
 54 
     | 
    
         
            +
                      upgrade! existing_file, library_name, *args
         
     | 
| 
      
 55 
     | 
    
         
            +
                    else
         
     | 
| 
      
 56 
     | 
    
         
            +
                      quiet_say "!txtred!warning!txtrst! not upgrading !txtcyn!#{existing_file}!txtrst!, unknown library '#{library_name}'"
         
     | 
| 
      
 57 
     | 
    
         
            +
                    end
         
     | 
| 
      
 58 
     | 
    
         
            +
                  end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                  def upgrade!(existing_file, library_name, *args)
         
     | 
| 
      
 61 
     | 
    
         
            +
                    library = Bashly::Library.new library_name, *args
         
     | 
| 
      
 62 
     | 
    
         
            +
                    file = library.find_file existing_file
         
     | 
| 
       62 
63 
     | 
    
         | 
| 
       63 
64 
     | 
    
         
             
                    if file
         
     | 
| 
       64 
65 
     | 
    
         
             
                      File.deep_write file[:path], file[:content]
         
     | 
| 
         @@ -81,7 +82,7 @@ module Bashly 
     | 
|
| 
       81 
82 
     | 
    
         
             
                  end
         
     | 
| 
       82 
83 
     | 
    
         | 
| 
       83 
84 
     | 
    
         
             
                  def create_root_command_file
         
     | 
| 
       84 
     | 
    
         
            -
                    create_file "#{Settings.source_dir} 
     | 
| 
      
 85 
     | 
    
         
            +
                    create_file "#{Settings.source_dir}/#{command.filename}", command.render(:default_root_script)
         
     | 
| 
       85 
86 
     | 
    
         
             
                  end
         
     | 
| 
       86 
87 
     | 
    
         | 
| 
       87 
88 
     | 
    
         
             
                  def create_all_command_files
         
     | 
| 
         @@ -97,7 +98,7 @@ module Bashly 
     | 
|
| 
       97 
98 
     | 
    
         
             
                    if File.exist? file and !args['--force']
         
     | 
| 
       98 
99 
     | 
    
         
             
                      quiet_say "!txtblu!skipped!txtrst! #{file} (exists)"
         
     | 
| 
       99 
100 
     | 
    
         
             
                    else
         
     | 
| 
       100 
     | 
    
         
            -
                      File. 
     | 
| 
      
 101 
     | 
    
         
            +
                      File.deep_write file, content
         
     | 
| 
       101 
102 
     | 
    
         
             
                      quiet_say "!txtgrn!created!txtrst! #{file}"
         
     | 
| 
       102 
103 
     | 
    
         
             
                    end
         
     | 
| 
       103 
104 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -117,7 +118,7 @@ module Bashly 
     | 
|
| 
       117 
118 
     | 
    
         
             
                  end
         
     | 
| 
       118 
119 
     | 
    
         | 
| 
       119 
120 
     | 
    
         
             
                  def config
         
     | 
| 
       120 
     | 
    
         
            -
                    @config ||= Config.new 
     | 
| 
      
 121 
     | 
    
         
            +
                    @config ||= Config.new("#{Settings.source_dir}/bashly.yml").compose
         
     | 
| 
       121 
122 
     | 
    
         
             
                  end
         
     | 
| 
       122 
123 
     | 
    
         | 
| 
       123 
124 
     | 
    
         
             
                  def command
         
     | 
| 
         @@ -0,0 +1,19 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Bashly
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Commands
         
     | 
| 
      
 3 
     | 
    
         
            +
                class Validate < Base
         
     | 
| 
      
 4 
     | 
    
         
            +
                  help "Scan the configuration file for errors"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                  usage "bashly validate"
         
     | 
| 
      
 7 
     | 
    
         
            +
                  usage "bashly validate (-h|--help)"
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                  environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  def run
         
     | 
| 
      
 12 
     | 
    
         
            +
                    config = Config.new "#{Settings.source_dir}/bashly.yml"
         
     | 
| 
      
 13 
     | 
    
         
            +
                    validator = ConfigValidator.new config
         
     | 
| 
      
 14 
     | 
    
         
            +
                    validator.validate
         
     | 
| 
      
 15 
     | 
    
         
            +
                    say "!txtgrn!OK"
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,68 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Bashly
         
     | 
| 
      
 2 
     | 
    
         
            +
              # This is a `Command` concern responsible for providing additional scopes.
         
     | 
| 
      
 3 
     | 
    
         
            +
              module CommandScopes
         
     | 
| 
      
 4 
     | 
    
         
            +
                # Returns only the names of the Commands
         
     | 
| 
      
 5 
     | 
    
         
            +
                def command_names
         
     | 
| 
      
 6 
     | 
    
         
            +
                  commands.map &:name
         
     | 
| 
      
 7 
     | 
    
         
            +
                end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                # Returns a flat array containing all the commands in this tree.
         
     | 
| 
      
 10 
     | 
    
         
            +
                # This includes self + children + grandchildres + ...
         
     | 
| 
      
 11 
     | 
    
         
            +
                def deep_commands
         
     | 
| 
      
 12 
     | 
    
         
            +
                  result = []
         
     | 
| 
      
 13 
     | 
    
         
            +
                  commands.each do |command|
         
     | 
| 
      
 14 
     | 
    
         
            +
                    result << command
         
     | 
| 
      
 15 
     | 
    
         
            +
                    if command.commands.any?
         
     | 
| 
      
 16 
     | 
    
         
            +
                      result += command.deep_commands
         
     | 
| 
      
 17 
     | 
    
         
            +
                    end
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
                  result
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                # If any of this command's subcommands has the default option set to
         
     | 
| 
      
 23 
     | 
    
         
            +
                # true, this default command will be returned, nil otherwise.
         
     | 
| 
      
 24 
     | 
    
         
            +
                def default_command
         
     | 
| 
      
 25 
     | 
    
         
            +
                  commands.find { |c| c.default }
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                # Returns an array of all the default Args
         
     | 
| 
      
 29 
     | 
    
         
            +
                def default_args
         
     | 
| 
      
 30 
     | 
    
         
            +
                  args.select &:default
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                # Returns an array of all the default Environment Variables
         
     | 
| 
      
 34 
     | 
    
         
            +
                def default_environment_variables
         
     | 
| 
      
 35 
     | 
    
         
            +
                  environment_variables.select &:default
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                # Returns an array of all the default Flags
         
     | 
| 
      
 39 
     | 
    
         
            +
                def default_flags
         
     | 
| 
      
 40 
     | 
    
         
            +
                  flags.select &:default
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                # Returns an array of all the required Arguments
         
     | 
| 
      
 44 
     | 
    
         
            +
                def required_args
         
     | 
| 
      
 45 
     | 
    
         
            +
                  args.select &:required
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                # Returns an array of all the required EnvironmentVariables
         
     | 
| 
      
 49 
     | 
    
         
            +
                def required_environment_variables
         
     | 
| 
      
 50 
     | 
    
         
            +
                  environment_variables.select &:required
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                # Returns an array of all the required Flags
         
     | 
| 
      
 54 
     | 
    
         
            +
                def required_flags
         
     | 
| 
      
 55 
     | 
    
         
            +
                  flags.select &:required
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                # Returns an array of all the args with a whitelist
         
     | 
| 
      
 59 
     | 
    
         
            +
                def whitelisted_args
         
     | 
| 
      
 60 
     | 
    
         
            +
                  args.select &:allowed
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                # Returns an array of all the flags with a whitelist arg
         
     | 
| 
      
 64 
     | 
    
         
            +
                def whitelisted_flags
         
     | 
| 
      
 65 
     | 
    
         
            +
                  flags.select &:allowed
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
              end
         
     | 
| 
      
 68 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,143 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Bashly
         
     | 
| 
      
 2 
     | 
    
         
            +
              class ConfigValidator
         
     | 
| 
      
 3 
     | 
    
         
            +
                attr_reader :data
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize(data)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @data = data
         
     | 
| 
      
 7 
     | 
    
         
            +
                end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                def validate
         
     | 
| 
      
 10 
     | 
    
         
            +
                  assert_command "root", data
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              private
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                def assert(valid, message)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  raise ConfigurationError, message unless valid
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                def refute(invalid, message)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  assert !invalid, message
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                def assert_string(key, value)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  assert value.is_a?(String), "#{key} must be a string"
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                def assert_optional_string(key, value)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  assert_string key, value if value
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                def assert_boolean(key, value)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  assert [true, false, nil].include?(value), "#{key} must be a boolean" 
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                def assert_array(key, value, of: nil)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  return unless value
         
     | 
| 
      
 37 
     | 
    
         
            +
                  assert value.is_a?(Array), "#{key} must be an array"
         
     | 
| 
      
 38 
     | 
    
         
            +
                  if of
         
     | 
| 
      
 39 
     | 
    
         
            +
                    value.each_with_index do |val, i|
         
     | 
| 
      
 40 
     | 
    
         
            +
                      send "assert_#{of}".to_sym, "#{key}[#{i}]", val
         
     | 
| 
      
 41 
     | 
    
         
            +
                    end
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                def assert_hash(key, value)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  assert value.is_a?(Hash), "#{key} must be a hash"
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                def assert_version(key, value)
         
     | 
| 
      
 50 
     | 
    
         
            +
                  return unless value
         
     | 
| 
      
 51 
     | 
    
         
            +
                  assert [String, Integer, Float].include?(value.class),
         
     | 
| 
      
 52 
     | 
    
         
            +
                    "#{key} must be a string or a number" 
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                def assert_catch_all(key, value)
         
     | 
| 
      
 56 
     | 
    
         
            +
                  return unless value
         
     | 
| 
      
 57 
     | 
    
         
            +
                  assert [TrueClass, String, Hash].include?(value.class),
         
     | 
| 
      
 58 
     | 
    
         
            +
                    "#{key} must be a boolean, a string or a hash" 
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                  assert_catch_all_hash key, value if value.is_a? Hash
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                def assert_catch_all_hash(key, value)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  assert_string "#{key}.label", value['label']
         
     | 
| 
      
 65 
     | 
    
         
            +
                  assert_optional_string "#{key}.help", value['help']
         
     | 
| 
      
 66 
     | 
    
         
            +
                  assert_boolean "#{key}.required", value['required']
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                def assert_extensible(key, value)
         
     | 
| 
      
 70 
     | 
    
         
            +
                  return unless value
         
     | 
| 
      
 71 
     | 
    
         
            +
                  assert [TrueClass, String].include?(value.class),
         
     | 
| 
      
 72 
     | 
    
         
            +
                    "#{key} must be a boolean or a string" 
         
     | 
| 
      
 73 
     | 
    
         
            +
                end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                def assert_arg(key, value)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  assert_hash key, value
         
     | 
| 
      
 77 
     | 
    
         
            +
                  assert_string "#{key}.name", value['name']
         
     | 
| 
      
 78 
     | 
    
         
            +
                  assert_optional_string "#{key}.help", value['help']
         
     | 
| 
      
 79 
     | 
    
         
            +
                  assert_optional_string "#{key}.default", value['default']
         
     | 
| 
      
 80 
     | 
    
         
            +
                  assert_optional_string "#{key}.validate", value['validate']
         
     | 
| 
      
 81 
     | 
    
         
            +
                  assert_boolean "#{key}.required", value['required']
         
     | 
| 
      
 82 
     | 
    
         
            +
                  
         
     | 
| 
      
 83 
     | 
    
         
            +
                  assert_array "#{key}.allowed", value['allowed'], of: :string
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                  refute value['name'].match(/^-/), "#{key}.name must not start with '-'"
         
     | 
| 
      
 86 
     | 
    
         
            +
                end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                def assert_flag(key, value)
         
     | 
| 
      
 89 
     | 
    
         
            +
                  assert_hash key, value
         
     | 
| 
      
 90 
     | 
    
         
            +
                  assert value['short'] || value['long'], "#{key} must have at least one of long or short name"
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                  assert_optional_string "#{key}.long", value['long']
         
     | 
| 
      
 93 
     | 
    
         
            +
                  assert_optional_string "#{key}.short", value['short']
         
     | 
| 
      
 94 
     | 
    
         
            +
                  assert_optional_string "#{key}.help", value['help']
         
     | 
| 
      
 95 
     | 
    
         
            +
                  assert_optional_string "#{key}.arg", value['arg']
         
     | 
| 
      
 96 
     | 
    
         
            +
                  assert_optional_string "#{key}.default", value['default']
         
     | 
| 
      
 97 
     | 
    
         
            +
                  assert_optional_string "#{key}.validate", value['validate']
         
     | 
| 
      
 98 
     | 
    
         
            +
                  
         
     | 
| 
      
 99 
     | 
    
         
            +
                  assert_boolean "#{key}.required", value['required']
         
     | 
| 
      
 100 
     | 
    
         
            +
                  assert_array "#{key}.allowed", value['allowed'], of: :string
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                  assert value['long'].match(/^--[a-zA-Z0-9_\-]+$/), "#{key}.long must be in the form of '--name'" if value['long']
         
     | 
| 
      
 103 
     | 
    
         
            +
                  assert value['short'].match(/^-[a-zA-Z0-9]$/), "#{key}.short must be in the form of '-n'" if value['short']
         
     | 
| 
      
 104 
     | 
    
         
            +
                  refute value['arg'].match(/^-/), "#{key}.arg must not start with '-'" if value['arg']
         
     | 
| 
      
 105 
     | 
    
         
            +
                end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
                def assert_env_var(key, value)
         
     | 
| 
      
 108 
     | 
    
         
            +
                  assert_hash key, value
         
     | 
| 
      
 109 
     | 
    
         
            +
                  assert_string "#{key}.name", value['name']
         
     | 
| 
      
 110 
     | 
    
         
            +
                  assert_optional_string "#{key}.help", value['help']
         
     | 
| 
      
 111 
     | 
    
         
            +
                  assert_optional_string "#{key}.default", value['default']
         
     | 
| 
      
 112 
     | 
    
         
            +
                  assert_boolean "#{key}.required", value['required']
         
     | 
| 
      
 113 
     | 
    
         
            +
                end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
                def assert_command(key, value)
         
     | 
| 
      
 116 
     | 
    
         
            +
                  assert_hash key, value
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
                  refute value['commands'] && value['args'], "#{key} cannot have both commands and args"
         
     | 
| 
      
 119 
     | 
    
         
            +
                  refute value['commands'] && value['flags'], "#{key} cannot have both commands and flags"
         
     | 
| 
      
 120 
     | 
    
         
            +
                  
         
     | 
| 
      
 121 
     | 
    
         
            +
                  assert_string "#{key}.name", value['name']
         
     | 
| 
      
 122 
     | 
    
         
            +
                  assert_optional_string "#{key}.short", value['short']
         
     | 
| 
      
 123 
     | 
    
         
            +
                  assert_optional_string "#{key}.help", value['help']
         
     | 
| 
      
 124 
     | 
    
         
            +
                  assert_optional_string "#{key}.footer", value['footer']
         
     | 
| 
      
 125 
     | 
    
         
            +
                  assert_optional_string "#{key}.group", value['group']
         
     | 
| 
      
 126 
     | 
    
         
            +
                  assert_optional_string "#{key}.filename", value['filename']
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
                  assert_boolean "#{key}.default", value['default']
         
     | 
| 
      
 129 
     | 
    
         
            +
                  assert_version "#{key}.version", value['version']
         
     | 
| 
      
 130 
     | 
    
         
            +
                  assert_catch_all "#{key}.catch_all", value['catch_all']
         
     | 
| 
      
 131 
     | 
    
         
            +
                  assert_extensible "#{key}.extensible", value['extensible']
         
     | 
| 
      
 132 
     | 
    
         
            +
                  
         
     | 
| 
      
 133 
     | 
    
         
            +
                  assert_array "#{key}.args", value['args'], of: :arg
         
     | 
| 
      
 134 
     | 
    
         
            +
                  assert_array "#{key}.flags", value['flags'] , of: :flag
         
     | 
| 
      
 135 
     | 
    
         
            +
                  assert_array "#{key}.commands", value['commands'], of: :command
         
     | 
| 
      
 136 
     | 
    
         
            +
                  assert_array "#{key}.completions", value['completions'], of: :string
         
     | 
| 
      
 137 
     | 
    
         
            +
                  assert_array "#{key}.dependencies", value['dependencies'], of: :string
         
     | 
| 
      
 138 
     | 
    
         
            +
                  assert_array "#{key}.filters", value['filters'], of: :string
         
     | 
| 
      
 139 
     | 
    
         
            +
                  assert_array "#{key}.environment_variables", value['environment_variables'], of: :env_var
         
     | 
| 
      
 140 
     | 
    
         
            +
                  assert_array "#{key}.examples", value['examples'], of: :string
         
     | 
| 
      
 141 
     | 
    
         
            +
                end
         
     | 
| 
      
 142 
     | 
    
         
            +
              end
         
     | 
| 
      
 143 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,19 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Bashly
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Libraries
         
     | 
| 
      
 3 
     | 
    
         
            +
                class Base
         
     | 
| 
      
 4 
     | 
    
         
            +
                  attr_reader :args
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                  def initialize(*args)
         
     | 
| 
      
 7 
     | 
    
         
            +
                    @args = args
         
     | 
| 
      
 8 
     | 
    
         
            +
                  end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  def files
         
     | 
| 
      
 11 
     | 
    
         
            +
                    raise NotImplementedError, "Please implement #files"
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                  def post_install_message
         
     | 
| 
      
 15 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,11 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Bashly
         
     | 
| 
       2 
     | 
    
         
            -
              module  
     | 
| 
      
 2 
     | 
    
         
            +
              module Libraries
         
     | 
| 
       3 
3 
     | 
    
         
             
                class CompletionsFunction < Completions
         
     | 
| 
       4 
     | 
    
         
            -
                  def  
     | 
| 
      
 4 
     | 
    
         
            +
                  def files
         
     | 
| 
       5 
5 
     | 
    
         
             
                    [
         
     | 
| 
       6 
     | 
    
         
            -
                       
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
                      {
         
     | 
| 
      
 7 
     | 
    
         
            +
                        path: "#{Settings.source_dir}/lib/#{function_name}.sh",
         
     | 
| 
      
 8 
     | 
    
         
            +
                        content: completions_function_code(function_name)
         
     | 
| 
      
 9 
     | 
    
         
            +
                      }
         
     | 
| 
      
 10 
     | 
    
         
            +
                    ]
         
     | 
| 
       9 
11 
     | 
    
         
             
                  end
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
13 
     | 
    
         
             
                  def post_install_message
         
     | 
| 
         @@ -18,9 +20,19 @@ module Bashly 
     | 
|
| 
       18 
20 
     | 
    
         
             
                    EOF
         
     | 
| 
       19 
21 
     | 
    
         
             
                  end
         
     | 
| 
       20 
22 
     | 
    
         | 
| 
      
 23 
     | 
    
         
            +
                private
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
       21 
25 
     | 
    
         
             
                  def function_name
         
     | 
| 
       22 
     | 
    
         
            -
                     
     | 
| 
      
 26 
     | 
    
         
            +
                    @function_name ||= args[0] || 'send_completions'
         
     | 
| 
       23 
27 
     | 
    
         
             
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                  def completions_function_code(function_name)
         
     | 
| 
      
 30 
     | 
    
         
            +
                    [
         
     | 
| 
      
 31 
     | 
    
         
            +
                      "## [@bashly-upgrade completions #{function_name}]",
         
     | 
| 
      
 32 
     | 
    
         
            +
                      command.completion_function(function_name)
         
     | 
| 
      
 33 
     | 
    
         
            +
                    ].join "\n"
         
     | 
| 
      
 34 
     | 
    
         
            +
                  end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
       24 
36 
     | 
    
         
             
                end
         
     | 
| 
       25 
37 
     | 
    
         
             
              end
         
     | 
| 
       26 
38 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,29 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Bashly
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Libraries
         
     | 
| 
      
 3 
     | 
    
         
            +
                class CompletionsScript < Completions
         
     | 
| 
      
 4 
     | 
    
         
            +
                  def files
         
     | 
| 
      
 5 
     | 
    
         
            +
                    [
         
     | 
| 
      
 6 
     | 
    
         
            +
                      {
         
     | 
| 
      
 7 
     | 
    
         
            +
                        path: target_path,
         
     | 
| 
      
 8 
     | 
    
         
            +
                        content: command.completion_script
         
     | 
| 
      
 9 
     | 
    
         
            +
                      }
         
     | 
| 
      
 10 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 11 
     | 
    
         
            +
                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  def post_install_message
         
     | 
| 
      
 14 
     | 
    
         
            +
                    <<~EOF
         
     | 
| 
      
 15 
     | 
    
         
            +
                      In order to enable completions, run:
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                        !txtpur!$ source #{target_path}
         
     | 
| 
      
 18 
     | 
    
         
            +
                    EOF
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                private
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                  def target_path
         
     | 
| 
      
 24 
     | 
    
         
            +
                    @target_path ||= args[0] || "#{Settings.target_dir}/completions.bash"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Bashly
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Libraries
         
     | 
| 
      
 3 
     | 
    
         
            +
                class CompletionsYAML < Completions
         
     | 
| 
      
 4 
     | 
    
         
            +
                  def files
         
     | 
| 
      
 5 
     | 
    
         
            +
                    [
         
     | 
| 
      
 6 
     | 
    
         
            +
                      {
         
     | 
| 
      
 7 
     | 
    
         
            +
                        path: target_path,
         
     | 
| 
      
 8 
     | 
    
         
            +
                        content: command.completion_data.to_yaml
         
     | 
| 
      
 9 
     | 
    
         
            +
                      }
         
     | 
| 
      
 10 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 11 
     | 
    
         
            +
                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  def post_install_message
         
     | 
| 
      
 14 
     | 
    
         
            +
                    <<~EOF
         
     | 
| 
      
 15 
     | 
    
         
            +
                      This file can be converted to a completions script using the !txtgrn!completely!txtrst! gem.
         
     | 
| 
      
 16 
     | 
    
         
            +
                    EOF
         
     | 
| 
      
 17 
     | 
    
         
            +
                  end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                private
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  def target_path
         
     | 
| 
      
 22 
     | 
    
         
            +
                    @target_path ||= args[0] || "#{Settings.target_dir}/completions.yml"
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,39 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            colors:
         
     | 
| 
      
 2 
     | 
    
         
            +
              files:
         
     | 
| 
      
 3 
     | 
    
         
            +
                - source: "templates/lib/colors.sh"
         
     | 
| 
      
 4 
     | 
    
         
            +
                  target: "%{user_source_dir}/lib/colors.sh"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            config:
         
     | 
| 
      
 7 
     | 
    
         
            +
              files:
         
     | 
| 
      
 8 
     | 
    
         
            +
                - source: "templates/lib/config.sh"
         
     | 
| 
      
 9 
     | 
    
         
            +
                  target: "%{user_source_dir}/lib/config.sh"
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            yaml:
         
     | 
| 
      
 12 
     | 
    
         
            +
              files:
         
     | 
| 
      
 13 
     | 
    
         
            +
                - source: "templates/lib/yaml.sh"
         
     | 
| 
      
 14 
     | 
    
         
            +
                  target: "%{user_source_dir}/lib/yaml.sh"
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            lib:
         
     | 
| 
      
 17 
     | 
    
         
            +
              files:
         
     | 
| 
      
 18 
     | 
    
         
            +
                - source: "templates/lib/sample_function.sh"
         
     | 
| 
      
 19 
     | 
    
         
            +
                  target: "%{user_source_dir}/lib/sample_function.sh"
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            strings:
         
     | 
| 
      
 22 
     | 
    
         
            +
              files:
         
     | 
| 
      
 23 
     | 
    
         
            +
                - source: "templates/strings.yml"
         
     | 
| 
      
 24 
     | 
    
         
            +
                  target: "%{user_source_dir}/bashly-strings.yml"
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            validations:
         
     | 
| 
      
 27 
     | 
    
         
            +
              files:
         
     | 
| 
      
 28 
     | 
    
         
            +
                - source: "templates/lib/validations/validate_dir_exists.sh"
         
     | 
| 
      
 29 
     | 
    
         
            +
                  target: "%{user_source_dir}/lib/validations/validate_dir_exists.sh"
         
     | 
| 
      
 30 
     | 
    
         
            +
                - source: "templates/lib/validations/validate_file_exists.sh"
         
     | 
| 
      
 31 
     | 
    
         
            +
                  target: "%{user_source_dir}/lib/validations/validate_file_exists.sh"
         
     | 
| 
      
 32 
     | 
    
         
            +
                - source: "templates/lib/validations/validate_integer.sh"
         
     | 
| 
      
 33 
     | 
    
         
            +
                  target: "%{user_source_dir}/lib/validations/validate_integer.sh"
         
     | 
| 
      
 34 
     | 
    
         
            +
                - source: "templates/lib/validations/validate_not_empty.sh"
         
     | 
| 
      
 35 
     | 
    
         
            +
                  target: "%{user_source_dir}/lib/validations/validate_not_empty.sh"
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            completions: :CompletionsFunction
         
     | 
| 
      
 38 
     | 
    
         
            +
            completions_script: :CompletionsScript
         
     | 
| 
      
 39 
     | 
    
         
            +
            completions_yaml: :CompletionsYAML
         
     | 
| 
         @@ -0,0 +1,63 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Bashly
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Library
         
     | 
| 
      
 3 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 4 
     | 
    
         
            +
                  def exist?(name)
         
     | 
| 
      
 5 
     | 
    
         
            +
                    config.has_key? name.to_s
         
     | 
| 
      
 6 
     | 
    
         
            +
                  end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                  def config
         
     | 
| 
      
 9 
     | 
    
         
            +
                    @config ||= YAML.load_file(config_path)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  def config_path
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @config_path ||= File.expand_path 'libraries.yml', __dir__
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                include AssetHelper
         
     | 
| 
      
 18 
     | 
    
         
            +
                attr_reader :name, :args
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def initialize(name, *args)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  @name, @args = name.to_s, args
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                def files
         
     | 
| 
      
 25 
     | 
    
         
            +
                  if custom_handler
         
     | 
| 
      
 26 
     | 
    
         
            +
                    custom_handler.files
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                  else
         
     | 
| 
      
 29 
     | 
    
         
            +
                    config['files'].map do |file|
         
     | 
| 
      
 30 
     | 
    
         
            +
                      { path: file['target'] % target_file_args,
         
     | 
| 
      
 31 
     | 
    
         
            +
                        content: asset_content(file['source']) }
         
     | 
| 
      
 32 
     | 
    
         
            +
                    end
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                def post_install_message
         
     | 
| 
      
 37 
     | 
    
         
            +
                  if custom_handler
         
     | 
| 
      
 38 
     | 
    
         
            +
                    custom_handler.post_install_message
         
     | 
| 
      
 39 
     | 
    
         
            +
                  else
         
     | 
| 
      
 40 
     | 
    
         
            +
                    config['post_install_message']
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                def find_file(path)
         
     | 
| 
      
 45 
     | 
    
         
            +
                  files.select { |f| f[:path] == path }.first
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
              private
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                def custom_handler
         
     | 
| 
      
 51 
     | 
    
         
            +
                  return nil unless config.is_a? Symbol
         
     | 
| 
      
 52 
     | 
    
         
            +
                  @custom_handler ||= Bashly::Libraries.const_get(config).new(*args)
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                def config
         
     | 
| 
      
 56 
     | 
    
         
            +
                  @config ||= self.class.config[name]
         
     | 
| 
      
 57 
     | 
    
         
            +
                end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                def target_file_args
         
     | 
| 
      
 60 
     | 
    
         
            +
                  { user_source_dir: Settings.source_dir }
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
              end
         
     | 
| 
      
 63 
     | 
    
         
            +
            end
         
     |