Module: Legion::Extensions::Exec::Runners::Filesystem

Extended by:
Definitions
Defined in:
lib/legion/extensions/exec/runners/filesystem.rb

Overview

rubocop:disable Legion/Extension/RunnerIncludeHelpers

Constant Summary

Constants included from Definitions

Definitions::DEFAULTS

Class Method Summary collapse

Methods included from Definitions

definition, definition_for, definitions

Class Method Details

.cat(path:) ⇒ Object



89
90
91
# File 'lib/legion/extensions/exec/runners/filesystem.rb', line 89

def cat(path:, **)
  Runners::Shell.execute(command: "cat #{Shellwords.shellescape(path)}", cwd: Dir.pwd)
end

.cp(source:, destination:, recursive: false) ⇒ Object



147
148
149
150
151
152
153
# File 'lib/legion/extensions/exec/runners/filesystem.rb', line 147

def cp(source:, destination:, recursive: false, **)
  flag = recursive ? ' -R' : ''
  Runners::Shell.execute(
    command: "cp#{flag} #{Shellwords.shellescape(source)} #{Shellwords.shellescape(destination)}",
    cwd:     Dir.pwd
  )
end

.head(path:, lines: 20) ⇒ Object



104
105
106
# File 'lib/legion/extensions/exec/runners/filesystem.rb', line 104

def head(path:, lines: 20, **)
  Runners::Shell.execute(command: "head -n #{Integer(lines)} #{Shellwords.shellescape(path)}", cwd: Dir.pwd)
end

.ls(path: Dir.pwd, all: false, long: false) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/legion/extensions/exec/runners/filesystem.rb', line 42

def ls(path: Dir.pwd, all: false, long: false, **)
  flags = []
  flags << 'a' if all
  flags << 'l' if long

  command = ['ls']
  command << "-#{flags.join}" unless flags.empty?
  command << Shellwords.shellescape(path)
  Runners::Shell.execute(command: command.join(' '), cwd: Dir.pwd)
end

.mkdir(path:, parents: true) ⇒ Object



63
64
65
66
# File 'lib/legion/extensions/exec/runners/filesystem.rb', line 63

def mkdir(path:, parents: true, **)
  flag = parents ? ' -p' : ''
  Runners::Shell.execute(command: "mkdir#{flag} #{Shellwords.shellescape(path)}", cwd: Dir.pwd)
end

.mv(source:, destination:) ⇒ Object



165
166
167
168
169
170
# File 'lib/legion/extensions/exec/runners/filesystem.rb', line 165

def mv(source:, destination:, **)
  Runners::Shell.execute(
    command: "mv #{Shellwords.shellescape(source)} #{Shellwords.shellescape(destination)}",
    cwd:     Dir.pwd
  )
end

.pwd(path: Dir.pwd) ⇒ Object



27
28
29
# File 'lib/legion/extensions/exec/runners/filesystem.rb', line 27

def pwd(path: Dir.pwd, **)
  Runners::Shell.execute(command: 'pwd', cwd: path)
end

.rm(path:, recursive: false, force: false) ⇒ Object



183
184
185
186
187
188
189
# File 'lib/legion/extensions/exec/runners/filesystem.rb', line 183

def rm(path:, recursive: false, force: false, **)
  flags = []
  flags << 'r' if recursive
  flags << 'f' if force
  flag = flags.empty? ? '' : " -#{flags.join}"
  Runners::Shell.execute(command: "rm#{flag} #{Shellwords.shellescape(path)}", cwd: Dir.pwd)
end

.tail(path:, lines: 20) ⇒ Object



119
120
121
# File 'lib/legion/extensions/exec/runners/filesystem.rb', line 119

def tail(path:, lines: 20, **)
  Runners::Shell.execute(command: "tail -n #{Integer(lines)} #{Shellwords.shellescape(path)}", cwd: Dir.pwd)
end

.touch(path:) ⇒ Object



76
77
78
# File 'lib/legion/extensions/exec/runners/filesystem.rb', line 76

def touch(path:, **)
  Runners::Shell.execute(command: "touch #{Shellwords.shellescape(path)}", cwd: Dir.pwd)
end

.trigger_wordsObject



14
15
16
# File 'lib/legion/extensions/exec/runners/filesystem.rb', line 14

def self.trigger_words
  %w[file files filesystem directory directories ls list mkdir touch cat head tail wc cp mv rm]
end

.wc(path:) ⇒ Object



132
133
134
# File 'lib/legion/extensions/exec/runners/filesystem.rb', line 132

def wc(path:, **)
  Runners::Shell.execute(command: "wc #{Shellwords.shellescape(path)}", cwd: Dir.pwd)
end