Class: Pirka::App::Update
Constant Summary collapse
- PROGRAM_NAME =
"update"
- DESCRIPTION =
_("Update library files by remote files")
- URI =
::URI.parse("https://gitlab.com/KitaitiMakoto/pirka-library.git")
Instance Method Summary collapse
- #clone_repository(uri, dir) ⇒ Object
- #determine_directory(uri) ⇒ Object
- #run(argv) ⇒ Object
- #run_command(command) ⇒ Object
- #update_repository(uri, dir) ⇒ Object
Methods included from Subcommand
Instance Method Details
#clone_repository(uri, dir) ⇒ Object
43 44 45 |
# File 'app/update.rb', line 43 def clone_repository(uri, dir) run_command "git clone #{uri} #{dir}" end |
#determine_directory(uri) ⇒ Object
TODO:
Make more generic
39 40 41 |
# File 'app/update.rb', line 39 def determine_directory(uri) (Pathname.new(Dir.home)/".local/share/pirka"/uri.host/uri.path[1..-1]).sub_ext("") end |
#run(argv) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/update.rb', line 17 def run(argv) argv dir = determine_directory(URI) if dir.directory? update_repository(URI, dir) else clone_repository(URI, dir) $stderr.puts _("Library was cloned to:") $stdout.puts dir @config.additional_directories << dir @config.library_repositories << URI begin @config.save $stderr.puts _("and added to config file %{config_file}") % {config_file: @config.filepath.to_s.dump} rescue Errno::EACCESS => error $stderr.puts _("Couldn't save config file to %{config_file}") % {config_file: @config.filepath.to_s.dump} $stderr.puts error end end end |
#run_command(command) ⇒ Object
54 55 56 57 58 59 |
# File 'app/update.rb', line 54 def run_command(command) $stderr.puts _("Executing `%{command}`") % {command: command} output = `#{command}` raise _("Failed to execute `%{command}`") % {command: command} unless $CHILD_STATUS.success? output end |
#update_repository(uri, dir) ⇒ Object
TODO:
Make more generic
48 49 50 51 52 |
# File 'app/update.rb', line 48 def update_repository(uri, dir) Dir.chdir dir do run_command "git fetch origin master && git checkout origin/master" end end |