Module: Dply::Helper
- Included in:
- Build, Bundle, Cli::Depcheck, Cli::InstallPkgs, CodeArchive, Curl, Deplist, Elf, Git, Jenkins, Linker, Lock, MetaConfig, Pkgs, Release, RemoteArchive, Rpm, Setup, Strategy::Archive, Strategy::Base, Strategy::Git, TaskDsl, Util, Venv, Yum, Dplyr::Stage, Dplyr::StagesConfig, Dplyr::TasksConfig
- Defined in:
- lib/dply/helper.rb
Instance Method Summary collapse
- #cmd(command, env: {}, bundled_env: false, return_output: false, display: :bullet) ⇒ Object
- #error(msg) ⇒ Object
- #git ⇒ Object
- #logger ⇒ Object
- #sh(command, env: {}, bundled_env: false, return_output: false, display: :bullet) ⇒ Object
- #symlink(src, dst) ⇒ Object
Instance Method Details
#cmd(command, env: {}, bundled_env: false, return_output: false, display: :bullet) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/dply/helper.rb', line 11 def cmd(command, env: {}, bundled_env: false, return_output: false, display: :bullet) logger.command command, mode: display new_env = Env.build_env(env, bundled_env: bundled_env) cmd = Command.new command, env: new_env, shell: false return_output ? cmd.capture : cmd.run end |
#error(msg) ⇒ Object
52 53 54 |
# File 'lib/dply/helper.rb', line 52 def error(msg) raise ::Dply::Error, msg end |
#git ⇒ Object
48 49 50 |
# File 'lib/dply/helper.rb', line 48 def git Git end |
#logger ⇒ Object
44 45 46 |
# File 'lib/dply/helper.rb', line 44 def logger Logger.logger end |
#sh(command, env: {}, bundled_env: false, return_output: false, display: :bullet) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/dply/helper.rb', line 18 def sh(command, env: {}, bundled_env: false, return_output: false, display: :bullet) logger.command command, mode: display new_env = Env.build_env(env, bundled_env: bundled_env) cmd = Command.new command, env: new_env, shell: true return_output ? cmd.capture : cmd.run end |
#symlink(src, dst) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dply/helper.rb', line 25 def symlink(src, dst) if File.symlink? dst # to_s to handle pathnames return true if File.readlink(dst) == src.to_s Dir.mktmpdir("sym-", "./") do |d| dst_tmp = "#{d}/#{File.basename dst}" FileUtils.ln_s src, dst_tmp # using 'mv' here as FileUtils.mv doesn't replace a symlink which points # to a directory cmd ["mv", dst_tmp, File.dirname(dst)], display: false end elsif File.exist? dst error "cannot create symlink #{dst} => #{src}" else FileUtils.ln_s src, dst end end |