Class: Ki::BuildVersionMetadataFile

Inherits:
Object
  • Object
show all
Defined in:
lib/cmd/version_cmd.rb

Overview

Builds and updates ki-metada.json file based on parameters and added files

Instance Method Summary collapse

Instance Method Details

#execute(ctx, args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/cmd/version_cmd.rb', line 29

def execute(ctx, args)
  # opts.parse parses input parameters and fills in configuration parameters
  files = opts.parse(args)
  if source_parameters.size > 0
    .source(source_parameters)
  end
  # adds files to metadata and fills in parameters
  .add_files(input_dir, files, default_parameters)
  .save
end

#helpObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/cmd/version_cmd.rb', line 84

def help
  <<EOF
"#{shell_command}" can be used to generate version metadata files. Version metadata files
contain information about files (size, permission bits, hash checksums), version origins
and dependencies.

After version metadata file is ready, it can be imported to repository using version-import.

### Usage

#{shell_command} <parameters> file_pattern1*.* file_pattern2*.*

### Examples

#{shell_command} test.sh
#{shell_command} readme* -t doc
#{shell_command} -d my/component/1,name=comp,path=doc,internal -O "mv doc/test.sh helloworld.sh"
ki version-import

### Parameters
#{opts}
EOF
end

#optsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/cmd/version_cmd.rb', line 40

def opts
  OptionParser.new do |opts|
    opts.banner = ""
    opts.on("-f", "--file FILE", "Version file target") do |v|
      if !defined? @input_dir
        input_dir(File.dirname(v))
      end
      .init_from_path(v)
    end
    opts.on("-i", "--input-directory INPUT-DIR", "Input directory") do |v|
      input_dir(v)
    end
    opts.on("-v", "--version-id VERSION-ID", "Version's id") do |v|
      .version_id=v
    end
    ["url", "tag-url", "author", "repotype"].each do |source_param|
      opts.on("--source-#{source_param} #{source_param.upcase}", "Build source parameter #{source_param}") do |v|
        source_parameters[source_param]=v
      end
    end
    opts.on("-t", "--tags TAGS", "Tag files with keywords") do |v|
      default_parameters["tags"]= v.split(",").sort
    end
    hash_prefix = "/hashing"
    hashes = KiCommand::KiExtensions.find(hash_prefix).map { |k, v| k[hash_prefix.size+1..-1] }
    opts.on("--hashes HASHES", "Calculate checksums using defined hash algos. Default: sha1. Available: #{hashes.join(", ")}") do |v|
      default_parameters["hashes"]= v.split(",").sort
    end
    opts.on("-d", "--dependency DEPENDENCY", "Dependency definition my/component/123[,name=AA][,path=aa][,internal]") do |v|
      previous_dep(.add_dependency(v))
    end
    opts.on("-o", "--operation OP", "Add operation to previous dependency") do |v|
      previous_dep.add_operation(v.split(" "))
    end
    opts.on("-O", "--version-operation OP", "Add operation to version") do |v|
      .add_operation(v.split(" "))
    end
  end
end

#summaryObject



80
81
82
# File 'lib/cmd/version_cmd.rb', line 80

def summary
  "Create version metadata file"
end