Skip to content

Commit

Permalink
Add --install-actions and --install-prefix
Browse files Browse the repository at this point in the history
These flags are used when --install is given.

--install-actions is boolean and determines whether or not to run
the installation actions (notify launchd, etc).
--install-prefix is a string letting you tell pleaserun
where to write files to. This is intended to help packagers.

This should satisfy #43
  • Loading branch information
jordansissel committed Feb 10, 2015
1 parent 2773b82 commit cba0c1d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/pleaserun/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class PleaseRun::CLI < Clamp::Command # rubocop:disable ClassLength
option "--json", :flag, "Output a result in JSON. Intended to be consumed by other programs. This will emit the file contents and install actions as a JSON object."

option "--install", :flag, "Install the program on this system. This will write files to the correct location and execute any actions to make the program available to the system."
option "--[no-]install-actions", :flag, "Run installation actions after writing files", :default => true
option "--install-prefix", "DIRECTORY", "The path to prefix file paths with. This flag is generally intended for packagers, not for users installing directly on systems.", :default => "/"

option "--verbose", :flag, "More verbose logging"
option "--debug", :flag, "Debug-level logging"
Expand Down Expand Up @@ -167,8 +169,8 @@ def run_json(runner)

def run_human(runner)
if install?
PleaseRun::Installer.install_files(runner, "/", overwrite?)
PleaseRun::Installer.install_actions(runner)
PleaseRun::Installer.install_files(runner, install_prefix, overwrite?)
PleaseRun::Installer.install_actions(runner) if install_actions?
else
tmp = Stud::Temporary.directory
actions_script = File.join(tmp, "install_actions.sh")
Expand Down
23 changes: 23 additions & 0 deletions spec/pleaserun/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "pleaserun/cli"

describe PleaseRun::CLI do
subject { PleaseRun::CLI.new("pleaserun") }

context "when setting --install-prefix" do
let(:output) { Stud::Temporary.directory }
let(:name) { rand(10).times.collect { (rand(26) + 97).chr }.join }
let(:args) { [ "--install", "--install-prefix", output, "--no-install-actions", "-p", "sysv", "-v", "lsb-3.1", "--name", name, "/some/example" ] }

before do
subject.run(args)
end
after do
FileUtils.rm_r(output) if File.directory?(output)
end
it "should write files there" do
[ "/etc", "/etc/init.d", "/etc/init.d/#{name}" ].each do |path|
expect(File).to be_exists(File.join(output, path))
end
end
end
end

0 comments on commit cba0c1d

Please sign in to comment.