fig 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,66 @@
1
+ Description
2
+ ===========
3
+
4
+ Fig is a utility for dynamically assembling an environment from a set of packages. Shell commands can then be executed in that package, after which the environment goes away. The caller's environment is never affected.
5
+
6
+ If fig, an "environment" is just a set of environment variables. A "package" is a collection of files, plus some metadata describing how the environment should be modified when the package is included. For example, a package containing an executable might specify that its "bin" directory be appended to the PATH environment variable. A package containing a Java library might specify that its jar files should be added to the CLASSPATH. Etc.
7
+
8
+ Packages exist in two places: a "local" repository in the user's home directory, and a "remote" repository that is shared by a team. Fig will automatically download packages from the remote repository and install them in the local repository, when needed. In this sense, fig is a lot like other dependency management tools such as Apache Ivy and Debian APT. Unlike those tools, however, fig is meant to be lightweight, platform agnostic, and language agnostic.
9
+
10
+ Installation
11
+ ============
12
+
13
+ Fig can be installed via rubygems. The gems are hosted at [Gemcutter](http://gemcutter.org), so you'll need to set that up first:
14
+
15
+ $ gem install gemcutter
16
+ $ gem tumble
17
+
18
+ Then you can install fig:
19
+
20
+ $ gem install fig
21
+
22
+ Usage
23
+ =====
24
+
25
+ Fig recognizes the following options:
26
+
27
+ ### Flags ###
28
+
29
+ -d, --debug Print debug info
30
+ --force Download/install packages from remote repository, even if up-to-date
31
+ -u, --update Download/install packages from remote repository, if out-of-date
32
+ -n, --no Automatically answer "n" for any prompt (batch mode)
33
+ -y, --yes Automatically answer "y" for any prompt (batch mode)
34
+
35
+
36
+ ### Environment Modifiers ###
37
+
38
+ The following otpions modify the environment generated by fig:
39
+
40
+ -i, --include DESCRIPTOR Include package in environment (recursive)
41
+ -p, --append VAR=VALUE Append value to environment variable using platform-specific separator
42
+ -s, --set VAR=VALUE Set environment variable
43
+
44
+ ### Environment Commands ###
45
+
46
+ The following commands will be run in the environment created by fig:
47
+
48
+ -b, --bash Print bash commands so user's environment can be updated (usually used with 'eval')
49
+ -g, --get VARIABLE Get value of environment variable
50
+ -x, --execute DESCRIPTOR Execute command associated with specified configuration
51
+
52
+ -- COMMAND [ARGS...] Execute arbitrary shell command
53
+
54
+ ### Other Commands ###
55
+
56
+ Fig also supports the following options, which don't require a fig environment. Any modifiers will be ignored:
57
+
58
+ -?, -h, --help Display this help text
59
+ --publish Upload package to the remote repository (also installs in local repository)
60
+ --publish-local Install package in local repository only
61
+ --list List the packages installed in local repository
62
+
63
+ Copyright
64
+ =========
65
+
66
+ Copyright (c) 2009 Matthew Foemmel. See LICENSE for details.
data/bin/fig CHANGED
@@ -23,8 +23,8 @@ end
23
23
 
24
24
  ARGV.each_with_index do |arg, i|
25
25
  if arg == "-"
26
- $stderr.puts "Use of single dash (-) is deprecated. Use double dash (--) instead"
27
- exit 1
26
+ # $stderr.puts "Use of single dash (-) is deprecated. Use double dash (--) instead"
27
+ # exit 1
28
28
  elsif arg == "--"
29
29
  ARGV[i] = "-"
30
30
  end
@@ -54,12 +54,11 @@ if options[:publish]
54
54
  end
55
55
 
56
56
  os = OS.new
57
- repos = Repository.new(os, File.expand_path("~/.fighome/repos"), remote_url, remote_user)
57
+ repos = Repository.new(os, File.expand_path(File.join(options[:home], 'repos')), remote_url, remote_user)
58
58
  env = Environment.new(os, repos, vars)
59
59
 
60
60
  options[:includes].each do |descriptor|
61
61
  package_name, config_name, version_name = parse_descriptor(descriptor)
62
- puts "Package: #{package_name}, config_name: #{config_name}, Version: #{version_name}"
63
62
  env.include_config(nil, package_name, config_name, version_name)
64
63
  end
65
64
 
@@ -71,8 +70,24 @@ options[:appends].each do |name_val|
71
70
  env.append_variable(nil, name_val[0], name_val[1])
72
71
  end
73
72
 
74
- if os.exist?("./.fig")
75
- package = Parser.new.parse_package(nil, nil, ".", os.read("./.fig"))
73
+ DEFAULT_FIG_FILE = '.fig'
74
+
75
+ input = nil
76
+ if options[:input] == '-'
77
+ input = $stdin.read
78
+ elsif options[:input].nil?
79
+ input = os.read(DEFAULT_FIG_FILE) if os.exist?(DEFAULT_FIG_FILE)
80
+ else
81
+ if os.exist?(options[:input])
82
+ input = os.read(options[:input])
83
+ else
84
+ $stderr.puts "File not found: #{options[:input]}"
85
+ exit 1
86
+ end
87
+ end
88
+
89
+ if input
90
+ package = Parser.new.parse_package(nil, nil, ".", input)
76
91
  if options[:retrieve]
77
92
  package.retrieves.each do |var, path|
78
93
  env.add_retrieve(var, path)
@@ -86,10 +101,6 @@ else
86
101
  package = Package.new(nil, nil, ".", [])
87
102
  end
88
103
 
89
- if options[:echo]
90
- puts env[options[:echo]]
91
- end
92
-
93
104
  if options[:list]
94
105
  repos.list_packages.sort.each do |item|
95
106
  puts item
@@ -102,7 +113,10 @@ if options[:publish]
102
113
  if package_name.nil? || version_name.nil?
103
114
  raise "Please specify a package name and a version name"
104
115
  end
116
+ fail if package.publish_statements.empty?
105
117
  repos.publish_package(package.publish_statements, package_name, version_name)
118
+ elsif options[:echo]
119
+ puts env[options[:echo]]
106
120
  elsif argv[0] == "-"
107
121
  argv.shift
108
122
  env.execute_shell(argv) { |cmd| exec cmd.join(' ') }
@@ -39,6 +39,9 @@ module Fig
39
39
  options[:appends] = []
40
40
  opts.on('-p', '--append VAR=VAL', 'append environment variable') { |var_val| options[:appends] << var_val.split('=') }
41
41
 
42
+ options[:input] = nil
43
+ opts.on('--input FILE', 'fig file to read (use - for stdin)') { |path| options[:input] = path }
44
+
42
45
  options[:home] = ENV['FIG_HOME'] || File.expand_path("~/.fighome")
43
46
  end
44
47
 
@@ -47,6 +47,9 @@ module Fig
47
47
  file.write(block)
48
48
  end
49
49
  end
50
+ when "ssh"
51
+ puts "downloading #{url}"
52
+ fail unless system "ssh #{uri.user + '@' if uri.user}#{uri.host} cat #{uri.path} > #{path}"
50
53
  else
51
54
  raise "Unknown protocol: #{url}"
52
55
  end
@@ -77,8 +80,16 @@ module Fig
77
80
  end
78
81
 
79
82
  def upload(local_file, remote_file, user)
80
- puts "uploading #{remote_file}"
83
+ puts "uploading #{local_file} to #{remote_file}"
84
+ uri = URI.parse(remote_file)
85
+ if uri.scheme == "ssh"
86
+ dir = uri.path[0, uri.path.rindex('/')]
87
+ cmd = "mkdir -p #{dir} && cat > #{uri.path}"
88
+ puts local_file
89
+ fail unless system "cat #{local_file} | ssh #{uri.user + '@' if uri.user}#{uri.host} '#{cmd}'"
90
+ else
81
91
  fail unless system "curl -p -T #{local_file} --create-dirs --ftp-create-dirs #{remote_file}"
92
+ end
82
93
  end
83
94
 
84
95
  def clear_directory(dir)
@@ -17,9 +17,9 @@ module Fig
17
17
  result.to_package(package_name, version_name, directory)
18
18
  end
19
19
 
20
- def parse_descriptor(descriptor)
21
- puts @parser.methods.sort
22
- end
20
+ # def parse_descriptor(descriptor)
21
+ # puts @parser.methods.sort
22
+ # end
23
23
  end
24
24
 
25
25
  end
@@ -1,7 +1,67 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
+ require 'open3'
4
+ require 'fileutils'
5
+
6
+ FIG_HOME = File.expand_path(File.dirname(__FILE__) + '/../tmp/fighome')
7
+ FileUtils.mkdir_p(FIG_HOME)
8
+ ENV['FIG_HOME'] = FIG_HOME
9
+
10
+ FIG_REMOTE_DIR = File.expand_path(File.dirname(__FILE__) + '/../tmp/remote')
11
+ FileUtils.mkdir_p(FIG_REMOTE_DIR)
12
+ ENV['FIG_REMOTE_URL'] = "ssh://localhost#{FIG_REMOTE_DIR}"
13
+ puts ENV['FIG_REMOTE_URL']
14
+
15
+ def fig(args, input=nil)
16
+ stdin, stdout, stderr = Open3.popen3("fig #{args}")
17
+ if input
18
+ stdin.puts input
19
+ stdin.close
20
+ end
21
+ return stdout.read.strip, stderr.read.strip
22
+ end
23
+
3
24
  describe "Fig" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
25
+ it "set environment variable from command line" do
26
+ fig('-s FOO=BAR -g FOO')[0].should == 'BAR'
27
+ fig('--set FOO=BAR -g FOO')[0].should == 'BAR'
28
+ end
29
+
30
+ it "set environment variable from fig file" do
31
+ input = <<-END
32
+ config default
33
+ set FOO=BAR
34
+ end
35
+ END
36
+ fig('--input - -g FOO', input)[0].should == 'BAR'
37
+ end
38
+
39
+ it "append environment variable from command line" do
40
+ fig('-p PATH=foo -g PATH').should == ["#{ENV['PATH']}#{File::PATH_SEPARATOR}foo",""]
41
+ end
42
+
43
+ it "append environment variable from fig file" do
44
+ input = <<-END
45
+ config default
46
+ append PATH=foo
47
+ end
48
+ END
49
+ fig('--input - -g PATH', input).should == ["#{ENV['PATH']}#{File::PATH_SEPARATOR}foo",""]
50
+ end
51
+
52
+ it "append empty environment variable" do
53
+ fig('-p XYZZY=foo -g XYZZY').should == ["foo",""]
54
+ end
55
+
56
+ it "publish to remote repository" do
57
+ input = <<-END
58
+ publish
59
+ config default
60
+ set FOO=BAR
61
+ end
62
+ end
63
+ END
64
+ puts fig('--input - --publish foo/1.2.3', input)
65
+ fig('-i foo/1.2.3 -g FOO').should == ['BAR','']
6
66
  end
7
67
  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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Foemmel
@@ -54,7 +54,7 @@ extensions: []
54
54
 
55
55
  extra_rdoc_files:
56
56
  - LICENSE
57
- - README.rdoc
57
+ - README.md
58
58
  files:
59
59
  - bin/fig
60
60
  - lib/fig.rb
@@ -66,7 +66,7 @@ files:
66
66
  - lib/fig/parser.rb
67
67
  - lib/fig/repository.rb
68
68
  - LICENSE
69
- - README.rdoc
69
+ - README.md
70
70
  has_rdoc: true
71
71
  homepage: http://github.com/mfoemmel/fig
72
72
  licenses: []
@@ -1,17 +0,0 @@
1
- = fig
2
-
3
- Description goes here.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2009 Matthew Foemmel. See LICENSE for details.