fig 0.1.2 → 0.1.3

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.
data/README.md CHANGED
@@ -71,7 +71,7 @@ Fig lets you modify environment variables three ways:
71
71
 
72
72
  ### Command Line ###
73
73
 
74
- So to get started, let's trying defining an environment variable via the command line and executing a command in the newly created environment. We'll set the "PLANET" variable to "NEPTUNE", then run "echo $PLANET" to ensure that the variable was updated:
74
+ So to get started, let's trying defining an environment variable via the command line and executing a command in the newly created environment. We'll set the "GREETING" variable to "Hello", then run "echo $GREETING, World" to ensure that the variable was updated:
75
75
 
76
76
  $ fig -s GREETING=Hello -- echo "\$GREETING, World"
77
77
  Hello, World
@@ -126,9 +126,21 @@ Configurations other than "default" can be specified using the "-c" option:
126
126
 
127
127
  Now let's say we want to share our little script with the rest of the team by bundling it into a package. The first thing you'll need to do is specify the location of your remote repository by defining the FIG_REMOTE_URL environment variable. If you just want to play around with fig, you can have it point to localhost:
128
128
 
129
- $ export FIG_REMOTE_URL=ssh://localhost/<path to home dir>/figremote
129
+ $ export FIG_REMOTE_URL=ssh://localhost`pwd`/remote
130
130
 
131
- ...TODO...
131
+ Before we publish our package, we'll need to tell fig which files we want to include. We do this by using the "resource" statement in our ".fig" file:
132
+
133
+ resource bin/hello
134
+
135
+ config default...
136
+
137
+ Now we can share the package with the rest of the team by using the "--publish" option:
138
+
139
+ $ fig --publish hello/1.0.0
140
+
141
+ The "hello/1.0.0" string represents the name of the package and the version number. Once the package has been published, we can include it in other environments by using the "-i" option (we'll use the "--no-file" option here, to tell fig not to parse the ".fig" file in the current directory):
142
+
143
+ $ fig --no-file -i hello/1.0.0 -- hello
132
144
 
133
145
  Community
134
146
  =========
data/bin/fig CHANGED
@@ -73,7 +73,9 @@ end
73
73
  DEFAULT_FIG_FILE = '.fig'
74
74
 
75
75
  input = nil
76
- if options[:input] == '-'
76
+ if options[:input] == :none
77
+ # ignore
78
+ elsif options[:input] == '-'
77
79
  input = $stdin.read
78
80
  elsif options[:input].nil?
79
81
  input = os.read(DEFAULT_FIG_FILE) if os.exist?(DEFAULT_FIG_FILE)
@@ -138,7 +138,7 @@ grammar Fig
138
138
  end
139
139
 
140
140
  rule url
141
- '"' value:[a-zA-Z0-9:/\-\\._]+ '"' ws
141
+ (value:[a-zA-Z0-9:/\-\\._]+ ws) / ('"' value:[a-zA-Z0-9:/\-\\._]+ '"' ws)
142
142
  end
143
143
 
144
144
  rule ws
@@ -41,6 +41,7 @@ module Fig
41
41
 
42
42
  options[:input] = nil
43
43
  opts.on('--input FILE', 'fig file to read (use - for stdin)') { |path| options[:input] = path }
44
+ opts.on('--no-file', 'fig file to read (use - for stdin)') { |path| options[:input] = :none }
44
45
 
45
46
  options[:home] = ENV['FIG_HOME'] || File.expand_path("~/.fighome")
46
47
  end
@@ -48,8 +48,15 @@ module Fig
48
48
  end
49
49
  end
50
50
  when "ssh"
51
- puts "downloading #{url}"
52
- fail unless system "ssh #{uri.user + '@' if uri.user}#{uri.host} cat #{uri.path} > #{path}"
51
+ # TODO need better way to do conditional download
52
+ timestamp = `ssh #{uri.user + '@' if uri.user}#{uri.host} "ruby -e 'puts File.mtime(\\"#{uri.path}\\").to_i'"`.to_i
53
+ if File.exist?(path) && File.mtime(path).to_i > timestamp
54
+ return false
55
+ else
56
+ $stderr.puts "downloading #{url}"
57
+ fail unless system "ssh #{uri.user + '@' if uri.user}#{uri.host} cat #{uri.path} > #{path}"
58
+ return true
59
+ end
53
60
  else
54
61
  raise "Unknown protocol: #{url}"
55
62
  end
@@ -30,9 +30,10 @@ module Fig
30
30
  end
31
31
 
32
32
  def publish_statements
33
- statements = []
34
- @statements.each{ |s| statements += s.statements if s.is_a?(Publish) }
35
33
  statements
34
+ # statements = []
35
+ # @statements.each{ |s| statements += s.statements if s.is_a?(Publish) }
36
+ # statements
36
37
  end
37
38
 
38
39
  def unparse
@@ -64,7 +65,7 @@ module Fig
64
65
  end
65
66
 
66
67
  def unparse(indent)
67
- "#{indent}resource \"#{url}\""
68
+ "#{indent}resource #{url}"
68
69
  end
69
70
  end
70
71
 
@@ -24,10 +24,15 @@ module Fig
24
24
  temp_dir = temp_dir_for_package(package_name, version_name)
25
25
  @os.clear_directory(temp_dir)
26
26
  fig_file = File.join(temp_dir, ".fig")
27
- content = package_statements.map do |statement|
27
+ content = bundle_resources(package_statements).map do |statement|
28
28
  if statement.is_a?(Archive) || statement.is_a?(Resource)
29
- archive_name = statement.url.split("/").last
30
- archive_remote = "#{remote_dir_for_package(package_name, version_name)}/#{archive_name}"
29
+ if statement.is_a?(Resource) && !is_url?(statement.url)
30
+ archive_name = statement.url
31
+ archive_remote = "#{remote_dir_for_package(package_name, version_name)}/#{statement.url}"
32
+ else
33
+ archive_name = statement.url.split("/").last
34
+ archive_remote = "#{remote_dir_for_package(package_name, version_name)}/#{archive_name}"
35
+ end
31
36
  if is_url?(statement.url)
32
37
  archive_local = File.join(temp_dir, archive_name)
33
38
  @os.download(statement.url, archive_local)
@@ -45,6 +50,24 @@ module Fig
45
50
  update_package(package_name, version_name)
46
51
  end
47
52
 
53
+ def bundle_resources(package_statements)
54
+ resources = []
55
+ new_package_statements = package_statements.reject do |statement|
56
+ if statement.is_a?(Resource) && !is_url?(statement.url)
57
+ resources << statement.url
58
+ true
59
+ else
60
+ false
61
+ end
62
+ end
63
+ if resources.size > 0
64
+ file = "resources.tar.gz"
65
+ file unless system "tar -zcf #{file} #{resources.join(' ')}"
66
+ new_package_statements.unshift(Archive.new(file))
67
+ end
68
+ new_package_statements
69
+ end
70
+
48
71
  def load_package(package_name, version_name)
49
72
  update_package(package_name, version_name) if @remote_repository_url
50
73
  read_local_package(package_name, version_name)
@@ -57,14 +57,30 @@ describe "Fig" do
57
57
  end
58
58
 
59
59
  it "publish to remote repository" do
60
+ FileUtils.rm_rf(FIG_HOME)
61
+ FileUtils.rm_rf(FIG_REMOTE_DIR)
60
62
  input = <<-END
61
- publish
62
- config default
63
- set FOO=BAR
64
- end
63
+ config default
64
+ set FOO=BAR
65
65
  end
66
66
  END
67
67
  puts fig('--publish foo/1.2.3', input)
68
68
  fig('-i foo/1.2.3 -g FOO').should == ['BAR','']
69
69
  end
70
+
71
+ it "publish resource to remote repository" do
72
+ FileUtils.rm_rf(FIG_HOME)
73
+ FileUtils.rm_rf(FIG_REMOTE_DIR)
74
+ FileUtils.mkdir_p("bin")
75
+ File.open("bin/hello", "w") { |f| f << "echo bar" }
76
+ fail unless system "chmod +x bin/hello"
77
+ input = <<-END
78
+ resource bin/hello
79
+ config default
80
+ append PATH=@/bin
81
+ end
82
+ END
83
+ puts fig('--publish foo/1.2.3', input)
84
+ fig('-u -i foo/1.2.3 -- hello')[0].should == 'bar'
85
+ end
70
86
  end
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.2
4
+ version: 0.1.3
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: 2009-12-30 00:00:00 -06:00
12
+ date: 2010-01-02 00:00:00 -06:00
13
13
  default_executable: fig
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency