fig 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/bin/fig CHANGED
@@ -21,12 +21,15 @@ def parse_descriptor(descriptor)
21
21
  return package_name, config_name, version_name
22
22
  end
23
23
 
24
+ shell_command = nil
24
25
  ARGV.each_with_index do |arg, i|
25
26
  if arg == "-"
26
27
  # $stderr.puts "Use of single dash (-) is deprecated. Use double dash (--) instead"
27
28
  # exit 1
28
29
  elsif arg == "--"
29
- ARGV[i] = "-"
30
+ shell_command = ARGV[(i+1)..-1]
31
+ ARGV.slice!(i..-1)
32
+ break
30
33
  end
31
34
  end
32
35
 
@@ -122,17 +125,18 @@ if options[:publish]
122
125
  end
123
126
  if not options[:modifiers].empty?
124
127
  publish_statements = options[:resources] + options[:archives] + [Configuration.new("default", options[:modifiers])]
125
- elsif not package.publish_statements.empty?
126
- publish_statements = package.publish_statements
128
+ publish_statements << Publish.new("default","default")
129
+ elsif not package.statements.empty?
130
+ publish_statements = package.statements
127
131
  else
128
132
  fail "Nothing to publish"
129
133
  end
130
134
  repos.publish_package(publish_statements, package_name, version_name)
131
135
  elsif options[:echo]
132
136
  puts env[options[:echo]]
133
- elsif argv[0] == "-"
137
+ elsif shell_command
134
138
  argv.shift
135
- env.execute_shell(argv) { |cmd| shell_exec cmd }
139
+ env.execute_shell(shell_command) { |cmd| shell_exec cmd }
136
140
  elsif argv[0]
137
141
  package_name, config_name, version_name = parse_descriptor(argv.shift)
138
142
  env.include_config(package, package_name, config_name, version_name)
@@ -69,13 +69,13 @@ module Fig
69
69
  end
70
70
  end
71
71
 
72
- private
73
-
74
72
  def include_config(base_package, package_name, config_name, version_name)
75
73
  package = lookup_package(package_name || base_package.package_name, version_name)
76
74
  apply_config(package, config_name || "default")
77
75
  end
78
76
 
77
+ private
78
+
79
79
  def set_variable(base_package, name, value)
80
80
  @variables[name] = expand_value(base_package, name, value)
81
81
  end
@@ -40,9 +40,18 @@ grammar Fig
40
40
  end
41
41
 
42
42
  rule publish
43
- "publish" ws statements:(package_statement / install)* "end" ws {
43
+ "publish" ws local_name:config_name ("->" remote_name:config_name)? ws {
44
44
  def to_package_statement
45
- Publish.new(statements.elements.map { |statement| statement.to_package_statement })
45
+ Publish.new(local_name.text_value, get_remote_name)
46
+ end
47
+
48
+ def get_remote_name
49
+ elements.each do |element|
50
+ if element.respond_to?(:remote_name)
51
+ return element.remote_name.text_value
52
+ end
53
+ end
54
+ local_name.text_value
46
55
  end
47
56
  }
48
57
  end
@@ -130,7 +139,7 @@ grammar Fig
130
139
  end
131
140
 
132
141
  rule config_name
133
- [a-zA-Z0-9\\-]+
142
+ [a-zA-Z0-9_]+
134
143
  end
135
144
 
136
145
  rule name
@@ -14,7 +14,7 @@ module Fig
14
14
  options = {}
15
15
 
16
16
  parser = OptionParser.new do |opts|
17
- opts.banner = "Usage: fig [--debug] [--update] [--config <config>] [-echo <var> | --list | <package> | - <command>]"
17
+ opts.banner = "Usage: fig [--debug] [--update] [--config <config>] [--get <var> | --list | <package> | - <command>]"
18
18
 
19
19
  opts.on('-?', '-h','--help','display this help text') do
20
20
  puts opts
@@ -1,5 +1,4 @@
1
1
  require 'fileutils'
2
- require 'ftools'
3
2
  require 'uri'
4
3
  require 'net/http'
5
4
  require 'tempfile'
@@ -136,7 +135,7 @@ module Fig
136
135
 
137
136
  def copy(source, target)
138
137
  FileUtils.mkdir_p(File.dirname(target))
139
- File.copy(source, target)
138
+ FileUtils.copy_file(source, target)
140
139
  target
141
140
  end
142
141
 
@@ -29,13 +29,6 @@ module Fig
29
29
  @statements.select{|s| s.is_a?(Resource)}.map{|s|s.url}
30
30
  end
31
31
 
32
- def publish_statements
33
- statements
34
- # statements = []
35
- # @statements.each{ |s| statements += s.statements if s.is_a?(Publish) }
36
- # statements
37
- end
38
-
39
32
  def unparse
40
33
  @statements.map { |statement| statement.unparse('') }.join("\n")
41
34
  end
@@ -83,17 +76,15 @@ module Fig
83
76
  end
84
77
 
85
78
  class Publish
86
- attr_reader :statements
79
+ attr_reader :local_name, :remote_name
87
80
 
88
- def initialize(statements)
89
- @statements = statements
81
+ def initialize(local_name, remote_name)
82
+ @local_name = local_name
83
+ @remote_name = remote_name
90
84
  end
91
85
 
92
86
  def unparse(indent)
93
- prefix = "\n#{indent}publish"
94
- body = @statements.map { |statement| statement.unparse(indent+' ') }.join("\n")
95
- suffix = "#{indent}end"
96
- return [prefix, body, suffix].join("\n")
87
+ "#{indent}publish #{@local_name}->#{@remote_name}"
97
88
  end
98
89
  end
99
90
 
@@ -118,6 +109,10 @@ module Fig
118
109
  @statements = statements
119
110
  end
120
111
 
112
+ def with_name(name)
113
+ Configuration.new(name, statements)
114
+ end
115
+
121
116
  def commands
122
117
  result = statements.select { |statement| statement.is_a?(Command) }
123
118
  # if result.empty?
@@ -10,6 +10,7 @@ module Fig
10
10
  end
11
11
 
12
12
  def parse_package(package_name, version_name, directory, input)
13
+ input = input.gsub(/#.*$/, '')
13
14
  result = @parser.parse(" #{input} ")
14
15
  if result.nil?
15
16
  raise "#{directory}: #{@parser.failure_reason}"
@@ -30,8 +30,11 @@ module Fig
30
30
  temp_dir = temp_dir_for_package(package_name, version_name)
31
31
  @os.clear_directory(temp_dir)
32
32
  fig_file = File.join(temp_dir, ".fig")
33
+ config_mapping = get_config_mapping(package_statements)
33
34
  content = bundle_resources(package_statements).map do |statement|
34
- if statement.is_a?(Archive) || statement.is_a?(Resource)
35
+ if statement.is_a?(Publish)
36
+ nil
37
+ elsif statement.is_a?(Archive) || statement.is_a?(Resource)
35
38
  if statement.is_a?(Resource) && !is_url?(statement.url)
36
39
  archive_name = statement.url
37
40
  archive_remote = "#{remote_dir_for_package(package_name, version_name)}/#{statement.url}"
@@ -47,15 +50,29 @@ module Fig
47
50
  end
48
51
  @os.upload(archive_local, archive_remote, @remote_repository_user)
49
52
  statement.class.new(archive_name).unparse('')
53
+ elsif statement.is_a?(Configuration)
54
+ remote_name = config_mapping[statement.name]
55
+ if remote_name
56
+ statement.with_name(remote_name).unparse('')
57
+ else
58
+ nil
59
+ end
50
60
  else
51
61
  statement.unparse('')
52
62
  end
53
- end
54
- @os.write(fig_file, content.join("\n"))
63
+ end.select {|s|not s.nil?}
64
+ @os.write(fig_file, content.join("\n").strip)
55
65
  @os.upload(fig_file, remote_fig_file_for_package(package_name, version_name), @remote_repository_user)
56
66
  # update_package(package_name, version_name)
57
67
  end
58
68
 
69
+ def get_config_mapping(package_statements)
70
+ publish_mappings = {}
71
+ package_statements.each{|s| publish_mappings[s.local_name] = s.remote_name if s.is_a?(Publish) }
72
+ publish_mappings
73
+ end
74
+
75
+
59
76
  def bundle_resources(package_statements)
60
77
  resources = []
61
78
  new_package_statements = package_statements.reject do |statement|
@@ -68,10 +68,23 @@ describe "Fig" do
68
68
  fig('-p XYZZY=foo -g XYZZY').should == ["foo",""]
69
69
  end
70
70
 
71
+ it "should ignore comments" do
72
+ input = <<-END
73
+ #/usr/bin/env fig
74
+
75
+ # Some comment
76
+ config default
77
+ set FOO=BAR # Another comment
78
+ end
79
+ END
80
+ fig('-g FOO', input)[0].should == 'BAR'
81
+ end
82
+
71
83
  it "publish to remote repository" do
72
84
  FileUtils.rm_rf(FIG_HOME)
73
85
  FileUtils.rm_rf(FIG_REMOTE_DIR)
74
86
  input = <<-END
87
+ publish default
75
88
  config default
76
89
  set FOO=BAR
77
90
  end
@@ -87,8 +100,9 @@ describe "Fig" do
87
100
  File.open("tmp/bin/hello", "w") { |f| f << "echo bar" }
88
101
  fail unless system "chmod +x tmp/bin/hello"
89
102
  input = <<-END
103
+ publish test->default
90
104
  resource tmp/bin/hello
91
- config default
105
+ config test
92
106
  append PATH=@/tmp/bin
93
107
  end
94
108
  END
@@ -113,6 +127,7 @@ describe "Fig" do
113
127
  FileUtils.mkdir_p("tmp/lib")
114
128
  File.open("tmp/lib/hello", "w") { |f| f << "some library" }
115
129
  input = <<-END
130
+ publish default
116
131
  resource tmp/lib/hello
117
132
  config default
118
133
  append FOOPATH=@/tmp/lib/hello
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Foemmel
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-08 00:00:00 -06:00
12
+ date: 2010-01-19 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency