Skip to content
This repository was archived by the owner on Aug 10, 2025. It is now read-only.

Commit 5fca938

Browse files
authored
Merge pull request #31 from hidakatsuya/reinstall-command
Reinstall command
2 parents 25af5e8 + 43c8823 commit 5fca938

File tree

5 files changed

+103
-11
lines changed

5 files changed

+103
-11
lines changed

README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ Rexer is a command-line tool for managing Redmine Extension (Plugin and Theme).
1616

1717
It is mainly aimed at helping with the development of Redmine and its plugins, allowing you to define extensions in a Ruby DSL and install, uninstall, update, and switch between different sets of the extensions.
1818

19-
[![demo](docs/demo-v0.8.0.gif)](https://asciinema.org/a/672754)
20-
2119
## What is Redmine Extension?
2220

2321
Redmine [Plugin](https://www.redmine.org/projects/redmine/wiki/Plugins) and [Theme](https://www.redmine.org/projects/redmine/wiki/Themes) are called Redmine Extension in this tool.
@@ -80,15 +78,16 @@ This command uninstalls the extensions and deletes the `.extensions.lock`.
8078
```
8179
$ rex
8280
Commands:
83-
rex envs # Show the list of environments and their extensions defined in .extensions.rb
84-
rex help [COMMAND] # Describe available commands or one specific command
85-
rex init # Create a new .extensions.rb file
86-
rex install [ENV] # Install the definitions in .extensions.rb for the specified environment
87-
rex state # Show the current state of the installed extensions
88-
rex switch [ENV] # Uninstall extensions for the currently installed environment and install extensions for the specified environment
89-
rex uninstall # Uninstall extensions for the currently installed environment based on the state in .extensions.lock and remove the lock file
90-
rex update # Update extensions for the currently installed environment to the latest version
91-
rex version # Show Rexer version
81+
rex envs # Show the list of environments and their extensions defined in .extensions.rb
82+
rex help [COMMAND] # Describe available commands or one specific command
83+
rex init # Create a new .extensions.rb file
84+
rex install [ENV] # Install the definitions in .extensions.rb for the specified environment
85+
rex reinstall [PLUGIN or THEME] # Uninstall extensions for the currently installed environment and install them again
86+
rex state # Show the current state of the installed extensions
87+
rex switch [ENV] # Uninstall extensions for the currently installed environment and install extensions for the specified environment
88+
rex uninstall # Uninstall extensions for the currently installed environment based on the state in .extensions.lock and remove the lock file
89+
rex update # Update extensions for the currently installed environment to the latest version
90+
rex version # Show Rexer version
9291
9392
Options:
9493
-v, [--verbose], [--no-verbose], [--skip-verbose] # Detailed output

docs/demo-v0.8.0.gif

-1.06 MB
Binary file not shown.

lib/rexer/cli.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ def uninstall
2424
Commands::Uninstall.new.call
2525
end
2626

27+
desc "reinstall [PLUGIN or THEME]", "Uninstall extensions for the currently installed environment and install them again"
28+
def reinstall(extension_name)
29+
Commands::Reinstall.new.call(extension_name)
30+
end
31+
2732
desc "switch [ENV]", "Uninstall extensions for the currently installed environment and install extensions for the specified environment"
2833
def switch(env = "default")
2934
Commands::Switch.new.call(env&.to_sym)

lib/rexer/commands/reinstall.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module Rexer
2+
module Commands
3+
class Reinstall
4+
include ActionCallable
5+
6+
Action = Data.define(:install, :uninstall)
7+
8+
def initialize
9+
@lock_definition = Definition::Lock.load_data
10+
end
11+
12+
def call(extension_name)
13+
return if no_lock_file_found
14+
15+
extension, action = find_extension_with_action(extension_name.to_sym)
16+
17+
if extension.nil?
18+
puts "#{extension_name} is not installed"
19+
return
20+
end
21+
22+
reinstall(extension, action)
23+
end
24+
25+
private
26+
27+
attr_reader :lock_definition
28+
29+
def find_extension_with_action(name)
30+
lock_definition.plugins.find { _1.name == name }&.then do |plugin|
31+
action = Action.new(Extension::Plugin::Install, Extension::Plugin::Uninstall)
32+
return [plugin, action]
33+
end
34+
35+
lock_definition.themes.find { _1.name == name }&.then do |theme|
36+
action = Action.new(Extension::Theme::Install, Extension::Theme::Uninstall)
37+
return [theme, action]
38+
end
39+
end
40+
41+
def reinstall(extension, action)
42+
call_action action.uninstall, extension
43+
call_action action.install, extension
44+
end
45+
46+
def no_lock_file_found
47+
lock_definition.nil?.tap { |result|
48+
puts "No lock file found" if result
49+
}
50+
end
51+
end
52+
end
53+
end

test/integration/integration_test.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,39 @@ class IntegrationTest < Test::Unit::TestCase
258258
assert_includes result.output_str, "Define themes and plugins you want to use in your Redmine here"
259259
end
260260
end
261+
262+
test "rex reinstall" do
263+
docker_exec("rex reinstall plugin_a").then do |result|
264+
assert_true result.success?
265+
assert_equal "No lock file found", result.output_str
266+
end
267+
268+
docker_exec("rex install env2").then do |result|
269+
assert_true result.success?
270+
end
271+
272+
docker_exec("rex reinstall plugin_x").then do |result|
273+
assert_true result.success?
274+
assert_equal "plugin_x is not installed", result.output_str
275+
end
276+
277+
docker_exec("rex reinstall plugin_a").then do |result|
278+
assert_true result.success?
279+
assert_includes result.output_str, "Uninstall plugin_a"
280+
assert_includes result.output_str, "Install plugin_a"
281+
end
282+
283+
docker_exec("rex state").then do |result|
284+
assert_equal [
285+
"Rexer: #{Rexer::VERSION}",
286+
"Env: env2",
287+
"",
288+
"Themes:",
289+
" * theme_a (master)",
290+
"",
291+
"Plugins:",
292+
" * plugin_a (master)"
293+
], result.output
294+
end
295+
end
261296
end

0 commit comments

Comments
 (0)