Skip to content

Commit

Permalink
Merge pull request jordansissel#110 from fidothe/files-on-stdin
Browse files Browse the repository at this point in the history
Allow taking a list of paths to package from a file or stdin
  • Loading branch information
jordansissel committed Oct 11, 2011
2 parents 1211333 + 10c5102 commit 29e140c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ fpm.wiki

# python
*.pyc

# RVM
.rvmrc
50 changes: 49 additions & 1 deletion lib/fpm/program.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def initialize
@settings.source = {} # source settings
@settings.target = {} # target settings
@settings.config_files ||= []
@settings.inputs_path = nil # file path to read a list of paths from
@settings.paths = [] # Paths to include in the package

# Maintainer scripts - https://github.com/jordansissel/fpm/issues/18
@settings.scripts ||= {}
Expand All @@ -27,7 +29,7 @@ def initialize

def run(args)
$: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
paths = options(args)
extracted_args = options(args)

ok = true
if @settings.package_type.nil?
Expand All @@ -40,6 +42,9 @@ def run(args)
ok = false
end

paths = process_paths(extracted_args)
ok = false if paths == :errors

if !ok
$stderr.puts "There were errors; see above."
$stderr.puts
Expand All @@ -53,6 +58,39 @@ def run(args)
return 0
end # def run

def process_paths(args)
paths_iolike = args
read_from_stdin = args.length == 1 && args.first == '-'

ok = true
if @settings.inputs_path
if read_from_stdin
$stderr.puts "Error: setting --inputs conflicts with passing '-' as the only argument"
ok = false
end
unless File.file?(@settings.inputs_path)
$stderr.puts "Error: '#{@settings.inputs_path}' does not exist"
ok = false
end
end

return :errors if !ok

if read_from_stdin
paths_iolike = $stdin
end
if @settings.inputs_path
paths_iolike = File.open(@settings.inputs_path, 'r')
end

paths = []
paths_iolike.each do |entry|
paths << entry.strip
end
paths_iolike.close if paths_iolike.respond_to?(:close)
paths
end # def process_paths

def options(args)
opts = OptionParser.new
default_options(opts)
Expand Down Expand Up @@ -221,5 +259,15 @@ def default_options(opts)
@settings.url = url
end # --url

opts.on("--inputs FILEPATH",
"The path to a file containing a newline-separated list of " \
"files and dirs to package.") do |path|
settings.source[:inputs] = path
end

opts.separator "Pass - as the only argument to have the list of " \
"files and dirs read from STDIN " \
"(e.g. fpm -s dir -t deb - < FILELIST)"

end # def default_options
end # class FPM::Program

0 comments on commit 29e140c

Please sign in to comment.