aro 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/aro +7 -32
- data/bin/cli/config.rb +71 -0
- data/bin/cli/constants.rb +4 -2
- data/bin/cli/create.rb +8 -3
- data/bin/cli/deck.rb +58 -42
- data/bin/cli.rb +36 -0
- data/lib/aro/create.rb +18 -19
- data/lib/aro/{database.rb → db.rb} +22 -28
- data/lib/aro/i18n.rb +8 -8
- data/lib/aro/prompt.rb +4 -0
- data/lib/aro/version.rb +2 -2
- data/lib/aro.rb +8 -7
- data/lib/models/deck.rb +39 -14
- data/lib/models/log.rb +8 -1
- data/locale/en.usage.yml +30 -10
- data/locale/en.yml +28 -13
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 112a9db053a27471ff5444243b12bd55426a81491695134c269c5bb4f3513cac
|
|
4
|
+
data.tar.gz: c6d23c2cb1f9ab42d45711e9f42d91f32aa1f01d0d56896fe73751814eaa8d35
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7b6c85313304ddb52defa7c17b32bbab9bd90fbb79a77235bd065ca67fb88b94a9a5005092599f85d31363cf7a922f5e625c15ced470ac49a1d9aa8b9ea04543
|
|
7
|
+
data.tar.gz: '06156495bdd7718b9655b1dc56337ba42231d3cd15a6f971a025b3941f2eaa819a2fe65d0e33890669f8b0b302a4b30eead4a50687632230b0ce220df3f49e57'
|
data/bin/aro
CHANGED
|
@@ -10,22 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
=end
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
[
|
|
15
|
-
:cli,
|
|
16
|
-
].each do |dir|
|
|
17
|
-
Dir[
|
|
18
|
-
File.join(
|
|
19
|
-
__dir__,
|
|
20
|
-
dir.to_s,
|
|
21
|
-
:"**/*.rb".to_s
|
|
22
|
-
)
|
|
23
|
-
].each { |file| require file}
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# set environment variable
|
|
27
|
-
ENV[:ARO_ENV.to_s] = :production.to_s
|
|
28
|
-
# ENV[:ARO_ENV.to_s] = :development.to_s
|
|
13
|
+
require_relative :cli.to_s
|
|
29
14
|
|
|
30
15
|
# todo: add tab completion using abbrev gem
|
|
31
16
|
# https://stackoverflow.com/a/11627931
|
|
@@ -36,24 +21,14 @@ ENV[:ARO_ENV.to_s] = :production.to_s
|
|
|
36
21
|
#
|
|
37
22
|
|
|
38
23
|
module CLI
|
|
39
|
-
|
|
40
|
-
if CLI::LOAD_DECK_ACTIONS.keys.map{|k| k.downcase.to_sym}.include?(ARGV[0]&.to_sym)
|
|
41
|
-
# enable deck shortcut (skip typing deck while in-game)
|
|
42
|
-
ARGV0 = :deck
|
|
43
|
-
ARGV1 = ARGV[0]&.to_sym
|
|
44
|
-
ARGV2 = ARGV[1]&.to_sym
|
|
45
|
-
else
|
|
46
|
-
# default
|
|
47
|
-
ARGV0 = ARGV[0]&.to_sym
|
|
48
|
-
ARGV1 = ARGV[1]&.to_sym
|
|
49
|
-
ARGV2 = ARGV[2]&.to_sym
|
|
50
|
-
end
|
|
51
|
-
|
|
52
24
|
if CLI::FLAGS[:VERSION].include?(CLI::ARGV0)
|
|
53
|
-
Aro::P.
|
|
25
|
+
Aro::P.say(Aro::VERSION)
|
|
54
26
|
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
55
27
|
end
|
|
56
28
|
|
|
29
|
+
# initialize config
|
|
30
|
+
CLI::Config.instance
|
|
31
|
+
|
|
57
32
|
# cli parser
|
|
58
33
|
case CLI::ARGV0
|
|
59
34
|
when :create
|
|
@@ -62,7 +37,7 @@ module CLI
|
|
|
62
37
|
CLI::deck
|
|
63
38
|
else
|
|
64
39
|
unless Aro::Mancy.game.nil? || CLI::FLAGS[:HELP].include?(CLI::ARGV0)
|
|
65
|
-
Aro::P.
|
|
40
|
+
Aro::P.say(I18n.t("cli.messages.welcome", name: "#{Aro::Mancy.name}.game.show"))
|
|
66
41
|
Aro::Mancy.game.show
|
|
67
42
|
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
68
43
|
end
|
|
@@ -70,5 +45,5 @@ module CLI
|
|
|
70
45
|
CLI::usage
|
|
71
46
|
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
72
47
|
end
|
|
73
|
-
|
|
48
|
+
|
|
74
49
|
end
|
data/bin/cli/config.rb
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
module CLI
|
|
2
|
+
class Config
|
|
3
|
+
include Singleton
|
|
4
|
+
|
|
5
|
+
VAR_PREFIX = :ARO_CONFIG_
|
|
6
|
+
|
|
7
|
+
CONFIG_FILE = :".config".to_s
|
|
8
|
+
CONFIG_FILE_PATH = "#{Aro::Db.base_aro_dir(Aro::Db.get_name_from_namefile)}/#{CLI::Config::CONFIG_FILE}"
|
|
9
|
+
|
|
10
|
+
DEFAULT_CONFIG = {
|
|
11
|
+
FORMAT: {
|
|
12
|
+
value: :text,
|
|
13
|
+
possible_values: [
|
|
14
|
+
{name: :text, description: I18n.t("cli.config.text_format_description")},
|
|
15
|
+
{name: :json, description: I18n.t("cli.config.json_format_description")},
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
# ...
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
def initialize
|
|
22
|
+
return unless Aro::Mancy.is_aro_dir?
|
|
23
|
+
unless File.exist?(CLI::Config::CONFIG_FILE_PATH)
|
|
24
|
+
generate_config
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
source_config
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.format
|
|
31
|
+
CLI::Config.var_value_with_suffix(:FORMAT)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.var_value_with_suffix(suffix)
|
|
35
|
+
ENV[CLI::Config.var_key_with_suffix(suffix)]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.var_key_with_suffix(suffix)
|
|
39
|
+
"#{CLI::Config::VAR_PREFIX}#{suffix}"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def generate_config
|
|
43
|
+
Aro::P.say(I18n.t("cli.config.generating_default_config", name: CLI::Config::CONFIG_FILE_PATH))
|
|
44
|
+
File.open(CLI::Config::CONFIG_FILE_PATH, "w+") do |file|
|
|
45
|
+
file.write("# #{Aro::Mancy::PS1} configuration file.\n")
|
|
46
|
+
file.write("# this file is auto generated by the aro cli.\n")
|
|
47
|
+
2.times do
|
|
48
|
+
file.write("#\n")
|
|
49
|
+
end
|
|
50
|
+
DEFAULT_CONFIG.each{|k, v|
|
|
51
|
+
var_name = CLI::Config.var_key_with_suffix(k)
|
|
52
|
+
file.write("# [#{var_name}]\n")
|
|
53
|
+
file.write("# => #{I18n.t("cli.config.possible_values")}:\n")
|
|
54
|
+
v[:possible_values].each{|pv|
|
|
55
|
+
file.write("# => #{pv[:name]} - #{pv[:description]}\n")
|
|
56
|
+
}
|
|
57
|
+
file.write("export #{var_name}=#{v[:value]}")
|
|
58
|
+
}
|
|
59
|
+
file.write("\n")
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def source_config
|
|
64
|
+
Aro::P.say(I18n.t("cli.config.sourcing_config", name: CLI::Config::CONFIG_FILE_PATH))
|
|
65
|
+
system("source #{CLI::Config::CONFIG_FILE_PATH}")
|
|
66
|
+
DEFAULT_CONFIG.keys.each{|dfk|
|
|
67
|
+
Aro::P.say("$#{CLI::Config.var_key_with_suffix(dfk)}=#{CLI::Config.var_value_with_suffix(dfk)}")
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
data/bin/cli/constants.rb
CHANGED
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
module CLI
|
|
12
12
|
|
|
13
13
|
FLAGS = {
|
|
14
|
-
HELP:
|
|
15
|
-
|
|
14
|
+
HELP: [:"-h", :"--help"],
|
|
15
|
+
SHOW_COUNT: [:"-n", :"--count"],
|
|
16
|
+
SHOW_ORDER: [:"-o", :"--order"],
|
|
17
|
+
VERSION: [:"-v", :"--version"],
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
EXIT_CODES = {
|
data/bin/cli/create.rb
CHANGED
|
@@ -10,8 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
module CLI
|
|
12
12
|
def self.create
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Aro::
|
|
13
|
+
CLI.exit_error_missing_args! if CLI::ARGV1.nil?
|
|
14
|
+
name = CLI::ARGV1&.to_s
|
|
15
|
+
Aro::P.say(I18n.t("cli.messages.creation_attempt", name: name))
|
|
16
|
+
if Aro::Create.new(name).initialized
|
|
17
|
+
Aro::P.say(I18n.t("cli.messages.creation_success", name: name))
|
|
18
|
+
else
|
|
19
|
+
Aro::P.say(I18n.t("cli.messages.creation_failure", name: name))
|
|
20
|
+
end
|
|
16
21
|
end
|
|
17
22
|
end
|
data/bin/cli/deck.rb
CHANGED
|
@@ -17,63 +17,79 @@ module CLI
|
|
|
17
17
|
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
18
18
|
elsif CLI::ARGV1.nil?
|
|
19
19
|
# no args, open deck menu
|
|
20
|
-
Aro::Create.new(Aro::
|
|
20
|
+
Aro::Create.new(Aro::Db.get_name_from_namefile)
|
|
21
21
|
Aro::Deck.display_selection_menu
|
|
22
22
|
elsif action == CLI::CREATE_DECK_ACTIONS[:CREATE]
|
|
23
|
-
|
|
23
|
+
CLI.exit_error_missing_args! if CLI::ARGV2.nil?
|
|
24
24
|
deck = Aro::Deck.make(CLI::ARGV2.to_s)
|
|
25
|
-
Aro::P.
|
|
25
|
+
Aro::P.say(I18n.t("cli.messages.deck_created_sucessfully", name: Aro::Mancy.game.name))
|
|
26
26
|
Aro::Deck.display_selection_menu
|
|
27
|
-
elsif CLI::LOAD_DECK_ACTIONS.include?(action)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
else
|
|
33
|
-
# assume shuffle or show, in which case show is always called
|
|
34
|
-
if action == CLI::LOAD_DECK_ACTIONS[:SHUFFLE]
|
|
35
|
-
Aro::P.p.say(I18n.t("cli.messages.shuffling", name: deck.name))
|
|
36
|
-
deck.shuffle
|
|
37
|
-
elsif action == CLI::LOAD_DECK_ACTIONS[:DRAW]
|
|
38
|
-
Aro::P.p.say(I18n.t("cli.messages.drawing", name: deck.name))
|
|
39
|
-
deck.draw
|
|
40
|
-
elsif action == CLI::LOAD_DECK_ACTIONS[:REPLACE]
|
|
41
|
-
Aro::P.p.say(I18n.t("cli.messages.replacing_drawn", name: deck.name))
|
|
42
|
-
deck.replace
|
|
43
|
-
elsif action == CLI::LOAD_DECK_ACTIONS[:RESET]
|
|
44
|
-
if Aro::AROYES != Aro::P.p.ask(I18n.t("cli.messages.confirmation_prompt", name: deck.name))
|
|
45
|
-
Aro::P.p.say(I18n.t("cli.messages.understood", name: deck.name))
|
|
46
|
-
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
47
|
-
end
|
|
27
|
+
elsif CLI::LOAD_DECK_ACTIONS.include?(action)
|
|
28
|
+
if Aro::Mancy.game.nil?
|
|
29
|
+
Aro::P.say(I18n.t("cli.errors.missing_deck"))
|
|
30
|
+
exit(CLI::EXIT_CODES[:GENERAL_ERROR])
|
|
31
|
+
end
|
|
48
32
|
|
|
49
|
-
|
|
50
|
-
|
|
33
|
+
case action
|
|
34
|
+
when CLI::LOAD_DECK_ACTIONS[:EXPLORE]
|
|
35
|
+
Aro::Mancy.game.explore
|
|
36
|
+
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
37
|
+
when CLI::LOAD_DECK_ACTIONS[:SHUFFLE]
|
|
38
|
+
Aro::P.say(I18n.t("cli.messages.shuffling", name: Aro::Mancy.game.name))
|
|
39
|
+
Aro::Mancy.game.shuffle
|
|
40
|
+
when CLI::LOAD_DECK_ACTIONS[:DRAW]
|
|
41
|
+
Aro::P.say(I18n.t("cli.messages.drawing", name: Aro::Mancy.game.name))
|
|
42
|
+
Aro::Mancy.game.draw
|
|
43
|
+
when CLI::LOAD_DECK_ACTIONS[:REPLACE]
|
|
44
|
+
Aro::P.say(I18n.t("cli.messages.replacing_drawn", name: Aro::Mancy.game.name))
|
|
45
|
+
Aro::Mancy.game.replace
|
|
46
|
+
when CLI::LOAD_DECK_ACTIONS[:RESET]
|
|
47
|
+
if Aro::AROYES != Aro::P.p.ask(I18n.t("cli.messages.confirmation_prompt", name: Aro::Mancy.game.name))
|
|
48
|
+
Aro::P.say(I18n.t("cli.messages.understood", name: Aro::Mancy.game.name))
|
|
49
|
+
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
51
50
|
end
|
|
52
51
|
|
|
53
|
-
Aro::P.
|
|
54
|
-
|
|
52
|
+
Aro::P.say(I18n.t("cli.messages.resetting", name: Aro::Mancy.game.name))
|
|
53
|
+
Aro::Mancy.game.reset
|
|
55
54
|
end
|
|
55
|
+
|
|
56
|
+
Aro::Mancy.game.show(**CLI::Deck.shoptions)
|
|
56
57
|
else
|
|
57
58
|
CLI::usage
|
|
58
59
|
end
|
|
59
60
|
end
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
module Deck
|
|
63
|
+
|
|
64
|
+
# parse show options
|
|
65
|
+
def self.shoptions
|
|
66
|
+
show_options_count = Aro::Log::DEFAULT_COUNT
|
|
67
|
+
show_options_order = Aro::Log::ORDERING[:DESC]
|
|
68
|
+
|
|
69
|
+
# Aro::P.say("ARGV.map{|a| a.to_sym} => #{ARGV.map{|a| a.to_sym}}")
|
|
70
|
+
|
|
71
|
+
count_option_flags = ARGV.map{|a| a.to_sym} & CLI::FLAGS[:SHOW_COUNT]
|
|
72
|
+
# Aro::P.say("count_option_flags: #{count_option_flags}")
|
|
73
|
+
if count_option_flags.any?
|
|
74
|
+
# get the ARGV index element after flag index
|
|
75
|
+
show_options_count = ARGV[ARGV.index(count_option_flags.first.to_s) + 1]
|
|
76
|
+
show_options_count = show_options_count.to_i unless [0, nil].include?(show_options_count&.to_i)
|
|
77
|
+
# Aro::P.say("show_options_count: #{show_options_count}")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
order_option_flags = ARGV.map{|a| a.to_sym} & CLI::FLAGS[:SHOW_ORDER]
|
|
81
|
+
# Aro::P.say("count_option_flags: #{order_option_flags}")
|
|
82
|
+
if order_option_flags.any?
|
|
83
|
+
# get the ARGV index element after flag index
|
|
84
|
+
show_options_order = ARGV[ARGV.index(order_option_flags.first.to_s) + 1].upcase.to_sym
|
|
85
|
+
Aro::P.say("show_options_order: #{show_options_order}")
|
|
86
|
+
end
|
|
71
87
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
{
|
|
89
|
+
count_n: show_options_count,
|
|
90
|
+
order_o: show_options_order
|
|
91
|
+
}
|
|
75
92
|
end
|
|
76
93
|
|
|
77
|
-
deck
|
|
78
94
|
end
|
|
79
95
|
end
|
data/bin/cli.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require :aro.to_s
|
|
2
|
+
[:cli].each do |dir|
|
|
3
|
+
Dir[
|
|
4
|
+
File.join(
|
|
5
|
+
__dir__,
|
|
6
|
+
dir.to_s,
|
|
7
|
+
:"**/*.rb".to_s
|
|
8
|
+
)
|
|
9
|
+
].each { |file| require file}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# set environment variable
|
|
13
|
+
ENV[:ARO_ENV.to_s] = :production.to_s
|
|
14
|
+
# ENV[:ARO_ENV.to_s] = :development.to_s
|
|
15
|
+
|
|
16
|
+
module CLI
|
|
17
|
+
|
|
18
|
+
if CLI::LOAD_DECK_ACTIONS.keys.map{|k| k.downcase.to_sym}.include?(ARGV[0]&.to_sym)
|
|
19
|
+
# enable deck shortcut (skip typing deck while in-game)
|
|
20
|
+
ARGV0 = :deck
|
|
21
|
+
ARGV1 = ARGV[0]&.to_sym
|
|
22
|
+
ARGV2 = ARGV[1]&.to_sym
|
|
23
|
+
else
|
|
24
|
+
# default
|
|
25
|
+
ARGV0 = ARGV[0]&.to_sym
|
|
26
|
+
ARGV1 = ARGV[1]&.to_sym
|
|
27
|
+
ARGV2 = ARGV[2]&.to_sym
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.exit_error_missing_args!
|
|
31
|
+
Aro::P.say(I18n.t("cli.errors.header"))
|
|
32
|
+
Aro::P.say(I18n.t("cli.errors.missing_args", cmd: "#{CLI::ARGV0} #{CLI::ARGV1} #{CLI::ARGV2}".strip))
|
|
33
|
+
exit(CLI::EXIT_CODES[:INVALID_ARG])
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
data/lib/aro/create.rb
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
module Aro
|
|
2
2
|
class Create
|
|
3
|
-
|
|
4
|
-
name = name&.strip
|
|
3
|
+
attr_accessor :initialized
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
def initialize(name)
|
|
6
|
+
self.initialized = false
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
if !name.nil? && (
|
|
9
|
+
name.kind_of?(String) ||
|
|
10
|
+
name.kind_of?(Symbol)
|
|
11
|
+
)
|
|
12
|
+
# explicitly only allow String/Symbol types for name
|
|
13
|
+
name = name.to_s.strip
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
# create the new aro directory and database
|
|
16
|
+
if Aro::Db.get_name_from_namefile.nil? && !Dir.exist?(name)
|
|
17
|
+
Aro::P.say(I18n.t("cli.messages.no_decks"))
|
|
18
|
+
create_cmd = "mkdir #{name}"
|
|
19
|
+
Aro::P.say("#{create_cmd} (result: #{system(create_cmd)})")
|
|
20
|
+
end
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
create_cmd = "mkdir #{name}"
|
|
21
|
-
Aro::P.p.say(create_cmd)
|
|
22
|
-
system(create_cmd)
|
|
22
|
+
# create database
|
|
23
|
+
Aro::Db.new(name)
|
|
24
|
+
self.initialized = true
|
|
23
25
|
end
|
|
24
|
-
|
|
25
|
-
# create database
|
|
26
|
-
Aro::Database.new(name)
|
|
27
26
|
end
|
|
28
27
|
|
|
29
28
|
end
|
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
require :active_record.to_s
|
|
2
2
|
require :base64.to_s
|
|
3
3
|
require :yaml.to_s
|
|
4
|
+
require :fileutils.to_s
|
|
4
5
|
|
|
5
6
|
module Aro
|
|
6
|
-
class
|
|
7
|
+
class Db
|
|
7
8
|
CONFIG_FILE = "database.yml"
|
|
8
9
|
SQL_FILE = "database.sql"
|
|
9
10
|
SCHEMA_FILE = "schema.rb"
|
|
10
11
|
MIGRATIONS_DIR = "db/migrate"
|
|
11
|
-
NAME_FILE = ".name"
|
|
12
12
|
|
|
13
13
|
def initialize(name = nil)
|
|
14
14
|
# show queries in stout
|
|
15
15
|
ActiveRecord::Base.logger = Logger.new(STDOUT) if ENV[:ARO_ENV.to_s] == :development.to_s
|
|
16
16
|
|
|
17
17
|
# generate .name file
|
|
18
|
-
if name.nil? && Aro::
|
|
18
|
+
if name.nil? && Aro::Mancy.is_aro_dir?
|
|
19
19
|
# pwd is in aro directory, use name file
|
|
20
20
|
name = get_name_from_namefile
|
|
21
|
-
elsif !name.nil? && !Aro::
|
|
21
|
+
elsif !name.nil? && !Aro::Mancy.is_aro_dir?
|
|
22
22
|
# first use, pwd is not in aro directory yet
|
|
23
|
-
echo_cmd = "echo #{name} >> #{name}/#{NAME_FILE}"
|
|
24
|
-
Aro::P.
|
|
25
|
-
system(echo_cmd)
|
|
23
|
+
echo_cmd = "echo #{name} >> #{name}/#{Aro::Mancy::NAME_FILE}"
|
|
24
|
+
Aro::P.say("#{echo_cmd} (result: #{system(echo_cmd)})")
|
|
26
25
|
end
|
|
27
26
|
|
|
28
27
|
if name.nil?
|
|
@@ -41,44 +40,39 @@ module Aro
|
|
|
41
40
|
@config ||= YAML.load_file(db_config_filepath(name))
|
|
42
41
|
end
|
|
43
42
|
|
|
44
|
-
def base_aro_dir(name)
|
|
45
|
-
"#{Aro::
|
|
43
|
+
def self.base_aro_dir(name)
|
|
44
|
+
"#{Aro::Mancy.is_aro_dir? ? "." : name}/#{Aro::DIRS[:ARO].call}"
|
|
46
45
|
end
|
|
47
46
|
|
|
48
47
|
def db_config_filepath(name)
|
|
49
|
-
"#{base_aro_dir(name)}/#{CONFIG_FILE}"
|
|
48
|
+
"#{Aro::Db.base_aro_dir(name)}/#{CONFIG_FILE}"
|
|
50
49
|
end
|
|
51
50
|
|
|
52
51
|
def db_filepath(name)
|
|
53
|
-
"#{base_aro_dir(name)}/#{SQL_FILE}"
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def self.is_aro_dir?
|
|
57
|
-
File.exist?(NAME_FILE)
|
|
52
|
+
"#{Aro::Db.base_aro_dir(name)}/#{SQL_FILE}"
|
|
58
53
|
end
|
|
59
54
|
|
|
60
55
|
def self.get_name_from_namefile
|
|
61
|
-
Aro::
|
|
56
|
+
Aro::Mancy.is_aro_dir? ? File.read(Aro::Mancy::NAME_FILE).strip : nil
|
|
62
57
|
end
|
|
63
58
|
|
|
64
59
|
def setup_local_aro(name = nil, force = false)
|
|
65
60
|
# create local .aro/ directory
|
|
66
|
-
unless File.exist?(base_aro_dir(name)) || force
|
|
67
|
-
if File.exist?(base_aro_dir(name)) && force
|
|
68
|
-
rm_cmd = "rm -rf #{base_aro_dir(name)}"
|
|
69
|
-
Aro::P.
|
|
61
|
+
unless File.exist?(Aro::Db.base_aro_dir(name)) || force
|
|
62
|
+
if File.exist?(Aro::Db.base_aro_dir(name)) && force
|
|
63
|
+
rm_cmd = "rm -rf #{Aro::Db.base_aro_dir(name)}"
|
|
64
|
+
Aro::P.say(rm_cmd)
|
|
70
65
|
system(rm_cmd)
|
|
71
66
|
end
|
|
72
67
|
|
|
73
|
-
mk_cmd = "mkdir #{base_aro_dir(name)}"
|
|
74
|
-
Aro::P.
|
|
75
|
-
system(mk_cmd)
|
|
68
|
+
mk_cmd = "mkdir #{Aro::Db.base_aro_dir(name)}"
|
|
69
|
+
Aro::P.say("#{mk_cmd} (result: #{system(mk_cmd)})")
|
|
76
70
|
end
|
|
77
71
|
|
|
78
72
|
# create database config yaml file
|
|
79
73
|
c = {
|
|
80
74
|
adapter: :sqlite3.to_s,
|
|
81
|
-
database: "#{Aro::
|
|
75
|
+
database: "#{Aro::Db.base_aro_dir(name)}/#{SQL_FILE}",
|
|
82
76
|
username: name,
|
|
83
77
|
password: name
|
|
84
78
|
}.to_yaml
|
|
@@ -91,11 +85,11 @@ module Aro
|
|
|
91
85
|
end
|
|
92
86
|
|
|
93
87
|
def setup(name)
|
|
94
|
-
local_migrate_dir = "#{base_aro_dir(name)}/#{MIGRATIONS_DIR}"
|
|
88
|
+
local_migrate_dir = "#{Aro::Db.base_aro_dir(name)}/#{MIGRATIONS_DIR}"
|
|
95
89
|
unless Dir.exist?(local_migrate_dir)
|
|
96
90
|
gem_dir = Dir[Gem.loaded_specs[:aro.to_s]&.full_gem_path || '.'].first
|
|
97
|
-
cp_cmd = "cp -R #{gem_dir}/db #{base_aro_dir(name)}"
|
|
98
|
-
Aro::P.
|
|
91
|
+
cp_cmd = "cp -R #{gem_dir}/db #{Aro::Db.base_aro_dir(name)}"
|
|
92
|
+
Aro::P.say(cp_cmd)
|
|
99
93
|
system(cp_cmd)
|
|
100
94
|
end
|
|
101
95
|
|
|
@@ -104,7 +98,7 @@ module Aro
|
|
|
104
98
|
}.max
|
|
105
99
|
ActiveRecord::MigrationContext.new(local_migrate_dir).migrate(migration_version)
|
|
106
100
|
require 'active_record/schema_dumper'
|
|
107
|
-
filename = "#{base_aro_dir(name)}/#{SCHEMA_FILE}"
|
|
101
|
+
filename = "#{Aro::Db.base_aro_dir(name)}/#{SCHEMA_FILE}"
|
|
108
102
|
File.open(filename, "w+") do |f|
|
|
109
103
|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection_pool, f)
|
|
110
104
|
end
|
data/lib/aro/i18n.rb
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
require :i18n.to_s
|
|
4
4
|
|
|
5
5
|
module Aro
|
|
6
|
-
|
|
7
|
-
end
|
|
6
|
+
LOCALE_DIR = :locale
|
|
8
7
|
|
|
9
|
-
locale_path = Gem.loaded_specs[:aro.to_s]&.full_gem_path
|
|
10
|
-
if Aro::IS_TEST.call
|
|
11
|
-
|
|
12
|
-
end
|
|
13
|
-
I18n.load_path += Dir["#{locale_path}
|
|
14
|
-
I18n.default_locale = :en
|
|
8
|
+
locale_path = Gem.loaded_specs[:aro.to_s]&.full_gem_path
|
|
9
|
+
if Aro::IS_TEST.call
|
|
10
|
+
locale_path = Dir.pwd
|
|
11
|
+
end
|
|
12
|
+
I18n.load_path += Dir["#{locale_path}/#{LOCALE_DIR}/*.yml"]
|
|
13
|
+
I18n.default_locale = :en
|
|
14
|
+
end
|
data/lib/aro/prompt.rb
CHANGED
data/lib/aro/version.rb
CHANGED
data/lib/aro.rb
CHANGED
|
@@ -16,20 +16,21 @@ module Aro
|
|
|
16
16
|
|
|
17
17
|
attr_accessor :game
|
|
18
18
|
|
|
19
|
+
PS1 = Aro::Mancy.name
|
|
20
|
+
NAME_FILE = ".name"
|
|
21
|
+
|
|
19
22
|
def initialize
|
|
20
|
-
Aro::Create.new(Aro::
|
|
23
|
+
Aro::Create.new(Aro::Db.get_name_from_namefile)
|
|
21
24
|
self.game = Aro::Deck.current_deck
|
|
22
25
|
end
|
|
23
26
|
|
|
24
|
-
def self.exit_error_missing_args!
|
|
25
|
-
Aro::P.p.say(I18n.t("cli.errors.header"))
|
|
26
|
-
Aro::P.p.say(I18n.t("cli.errors.missing_args", cmd: "#{CLI::ARGV0} #{CLI::ARGV1} #{CLI::ARGV2}"))
|
|
27
|
-
exit(CLI::EXIT_CODES[:INVALID_ARG])
|
|
28
|
-
end
|
|
29
|
-
|
|
30
27
|
def self.game
|
|
31
28
|
Mancy.instance.game
|
|
32
29
|
end
|
|
30
|
+
|
|
31
|
+
def self.is_aro_dir?
|
|
32
|
+
File.exist?(Aro::Mancy::NAME_FILE)
|
|
33
|
+
end
|
|
33
34
|
end
|
|
34
35
|
end
|
|
35
36
|
|
data/lib/models/deck.rb
CHANGED
|
@@ -9,7 +9,7 @@ class Aro::Deck < ActiveRecord::Base
|
|
|
9
9
|
DEV_TAROT_FILE = "/dev/tarot"
|
|
10
10
|
|
|
11
11
|
# update this for # of cards you will draw
|
|
12
|
-
DRAW_COUNT =
|
|
12
|
+
DRAW_COUNT = 7
|
|
13
13
|
|
|
14
14
|
# do not modify
|
|
15
15
|
DISPLAY_WIDTH = Aro::Deck::DRAW_COUNT*Aro::Deck::DRAW_COUNT
|
|
@@ -52,7 +52,7 @@ class Aro::Deck < ActiveRecord::Base
|
|
|
52
52
|
|
|
53
53
|
def self.display_selection_menu
|
|
54
54
|
unless Aro::Deck.any?
|
|
55
|
-
Aro::P.
|
|
55
|
+
Aro::P.say(I18n.t("cli.messages.no_decks"))
|
|
56
56
|
exit(CLI::EXIT_CODES[:SUCCESS])
|
|
57
57
|
end
|
|
58
58
|
|
|
@@ -87,16 +87,36 @@ class Aro::Deck < ActiveRecord::Base
|
|
|
87
87
|
card.gsub(/[+-]/, "").strip
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
def show
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
def show(count_n: Aro::Log::DEFAULT_COUNT, order_o: Aro::Log::ORDERING[:DESC])
|
|
91
|
+
unless count_n.kind_of?(Numeric) && count_n > 0
|
|
92
|
+
if count_n&.to_s&.downcase&.to_sym == Aro::Log::ALL
|
|
93
|
+
count_n = logs.count
|
|
94
|
+
else
|
|
95
|
+
count_n = Aro::Log::DEFAULT_COUNT
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
count_n = [count_n.to_i, logs.count].min
|
|
99
|
+
|
|
100
|
+
unless Aro::Log::ORDERING.include?(order_o&.to_s&.upcase&.to_sym)
|
|
101
|
+
Aro::P.say(I18n.t("cli.warnings.invalid_order"))
|
|
102
|
+
order_o = Aro::Log::ORDERING[:DESC]
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# perform query
|
|
106
|
+
h_logs = logs.order(created_at: order_o.to_s.downcase).first(count_n)
|
|
107
|
+
|
|
108
|
+
# for now tests just expect text output
|
|
109
|
+
return h_logs if Aro::IS_TEST.call
|
|
110
|
+
|
|
111
|
+
Aro::P.say(I18n.t("cli.messages.showing", name: name, count: count_n, order: order_o))
|
|
112
|
+
|
|
113
|
+
h_text = "\n"
|
|
94
114
|
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n\n"
|
|
95
115
|
h_text += "#{name.upcase.center(Aro::Deck::DISPLAY_WIDTH)}\n\n"
|
|
96
|
-
|
|
116
|
+
h_logs.each_with_index{|l, i|
|
|
97
117
|
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n"
|
|
98
118
|
h_text += l.created_at.strftime(Aro::Deck::DATE_FORMAT).center(Aro::Deck::DISPLAY_WIDTH) + "\n"
|
|
99
|
-
h_text += "#{logs.count - i} of #{logs.count}".rjust(Aro::Deck::DISPLAY_WIDTH) + "\n"
|
|
119
|
+
h_text += "#{order_o.to_sym == Aro::Log::ORDERING[:DESC] ? logs.count - i : 1 + i} of #{logs.count}".rjust(Aro::Deck::DISPLAY_WIDTH) + "\n"
|
|
100
120
|
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n\n"
|
|
101
121
|
h_text += get_display_for_cards(
|
|
102
122
|
Base64::decode64(l.card_data).split(Aro::Deck::CARD_DELIM)
|
|
@@ -112,13 +132,19 @@ class Aro::Deck < ActiveRecord::Base
|
|
|
112
132
|
drawn_cards
|
|
113
133
|
)
|
|
114
134
|
h_text += "\n"
|
|
135
|
+
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n"
|
|
115
136
|
end
|
|
116
|
-
}
|
|
117
137
|
|
|
118
|
-
|
|
119
|
-
|
|
138
|
+
3.times do
|
|
139
|
+
h_text += Aro::Deck::HISTORY_SEPARATOR + "\n"
|
|
140
|
+
end
|
|
141
|
+
}
|
|
120
142
|
|
|
121
|
-
Aro::
|
|
143
|
+
if count_n == Aro::Log::DEFAULT_COUNT
|
|
144
|
+
Aro::P.say(h_text)
|
|
145
|
+
else
|
|
146
|
+
Aro::P.less(h_text)
|
|
147
|
+
end
|
|
122
148
|
end
|
|
123
149
|
|
|
124
150
|
def get_display_for_cards(input = []) # todo:, print_nums: false)
|
|
@@ -145,8 +171,7 @@ class Aro::Deck < ActiveRecord::Base
|
|
|
145
171
|
default: 1
|
|
146
172
|
)
|
|
147
173
|
|
|
148
|
-
|
|
149
|
-
Aro::P.p.say(I18n.t("cards.#{Aro::Deck.card_strip(answer)}"))
|
|
174
|
+
Aro::P.say(I18n.t("cards.#{Aro::Deck.card_strip(answer)}"))
|
|
150
175
|
end
|
|
151
176
|
|
|
152
177
|
def shuffle
|
data/lib/models/log.rb
CHANGED
data/locale/en.usage.yml
CHANGED
|
@@ -21,7 +21,7 @@ en:
|
|
|
21
21
|
create
|
|
22
22
|
create an aro directory named <name>. if directory already exists, abort.
|
|
23
23
|
|
|
24
|
-
aro create
|
|
24
|
+
aro create <name>
|
|
25
25
|
|
|
26
26
|
examples:
|
|
27
27
|
|
|
@@ -36,9 +36,9 @@ en:
|
|
|
36
36
|
|
|
37
37
|
$ aro deck
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
COMMANDS
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
create
|
|
42
42
|
|
|
43
43
|
creates a new deck with the specified name.
|
|
44
44
|
|
|
@@ -46,28 +46,48 @@ en:
|
|
|
46
46
|
|
|
47
47
|
$ aro deck create <name_of_new_deck>
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
show
|
|
50
50
|
|
|
51
|
-
displays the current deck's
|
|
51
|
+
displays the current deck's log record(s).
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
the default behavior is to display only the most recent log record.
|
|
54
|
+
|
|
55
|
+
note:
|
|
56
|
+
|
|
57
|
+
'less' is automatically used to display records if --count > 1
|
|
58
|
+
|
|
59
|
+
OPTIONS
|
|
60
|
+
|
|
61
|
+
[-n | --count] specify number of deck logs to show.
|
|
62
|
+
|
|
63
|
+
default is 1 (latest/current state)
|
|
64
|
+
|
|
65
|
+
passing 'all' display all logs
|
|
66
|
+
|
|
67
|
+
[-o | --order] specify the output order of the log records.
|
|
68
|
+
|
|
69
|
+
default is 'desc'
|
|
70
|
+
|
|
71
|
+
possible values: ['asc', 'desc']
|
|
72
|
+
|
|
73
|
+
shuffle
|
|
54
74
|
|
|
55
75
|
shuffles the current deck and generates a log record.
|
|
56
76
|
|
|
57
|
-
|
|
77
|
+
explore
|
|
58
78
|
|
|
59
79
|
allows user to browse each card in the current deck.
|
|
60
80
|
|
|
61
|
-
|
|
81
|
+
draw
|
|
62
82
|
|
|
63
83
|
draw a random card from the current deck.
|
|
64
84
|
|
|
65
|
-
|
|
85
|
+
replace
|
|
66
86
|
|
|
67
87
|
replaces all drawn cards FIFO and puts them on the bottom of
|
|
68
88
|
the deck. this will preserve all card orientations.
|
|
69
89
|
|
|
70
|
-
|
|
90
|
+
reset
|
|
71
91
|
|
|
72
92
|
completely reset the deck. replace all drawn and reset order.
|
|
73
93
|
all orientations will be set to upright.
|
data/locale/en.yml
CHANGED
|
@@ -1,30 +1,45 @@
|
|
|
1
1
|
en:
|
|
2
2
|
cli:
|
|
3
|
+
config:
|
|
4
|
+
generating_default_config: "missing config. generating default config file at %{name}."
|
|
5
|
+
json_format_description: "show aro responses in json format."
|
|
6
|
+
possible_values: "possible values"
|
|
7
|
+
text_format_description: "show aro responses in text format (default)"
|
|
8
|
+
sourcing_config: "loading configuration from %{name}..."
|
|
3
9
|
errors:
|
|
4
10
|
header: "error! something is out of place."
|
|
5
11
|
missing_args: "the command you entered, '%{cmd}', is missing required argument(s)"
|
|
12
|
+
missing_deck: "no deck selected. use 'aro deck' to select one or 'aro deck create deck_name' to create one."
|
|
13
|
+
warnings:
|
|
14
|
+
invalid_order: "the order specified for displaying logs in invalid. using default (desc)."
|
|
6
15
|
messages:
|
|
7
16
|
choose_card: "choose a card."
|
|
8
17
|
confirmation_prompt: "input 'aroyes' to reset %{name}, or enter to cancel (cancel): "
|
|
9
18
|
creating: "creating %{name}..."
|
|
10
|
-
creation_attempt: "
|
|
11
|
-
|
|
19
|
+
creation_attempt: "attempting to create aro table named %{name}..."
|
|
20
|
+
creation_failure: "%{name} creation failed!"
|
|
21
|
+
creation_success: |
|
|
22
|
+
%{name} created successfully!
|
|
23
|
+
|
|
24
|
+
to get started navigate to the %{name} directory:
|
|
25
|
+
|
|
26
|
+
$ cd %{name}
|
|
27
|
+
|
|
28
|
+
see aro --help for usage.
|
|
29
|
+
deck_created_sucessfully: "%{name} deck created successfully"
|
|
12
30
|
drawing: "drawing a card from %{name}..."
|
|
13
|
-
history_title: "%{deck} deck stream (desc.):$"
|
|
14
31
|
history_drawn: "drawn cards"
|
|
15
|
-
invalid_name: "-TO"
|
|
16
|
-
showing: "showing %{name}..."
|
|
17
|
-
shuffling: "shuffling %{name}'s cards..."
|
|
18
|
-
replacing_drawn: "all drawn cards to %{name}..."
|
|
19
|
-
resetting: "resetting %{name}'s cards..."
|
|
20
|
-
understood: "%{name} says: 'understood.'"
|
|
21
|
-
welcome: "welcome.to.the.%{name}."
|
|
22
|
-
|
|
23
32
|
no_decks: |
|
|
24
|
-
|
|
25
33
|
no decks created yet.
|
|
26
34
|
|
|
27
35
|
use the following command to create one:
|
|
36
|
+
|
|
28
37
|
$ aro deck create <deck_name>
|
|
29
38
|
|
|
30
|
-
see aro --help for usage.
|
|
39
|
+
see aro --help for usage.
|
|
40
|
+
showing: "%{name}: (count: [%{count}], order: [%{order}])..."
|
|
41
|
+
shuffling: "shuffling %{name}'s cards..."
|
|
42
|
+
replacing_drawn: "all drawn cards to %{name}..."
|
|
43
|
+
resetting: "resetting %{name}'s cards..."
|
|
44
|
+
understood: "%{name} says: 'understood.'"
|
|
45
|
+
welcome: "welcome.to.the.%{name}."
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aro
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- i2097i
|
|
@@ -178,6 +178,8 @@ extensions: []
|
|
|
178
178
|
extra_rdoc_files: []
|
|
179
179
|
files:
|
|
180
180
|
- bin/aro
|
|
181
|
+
- bin/cli.rb
|
|
182
|
+
- bin/cli/config.rb
|
|
181
183
|
- bin/cli/constants.rb
|
|
182
184
|
- bin/cli/create.rb
|
|
183
185
|
- bin/cli/deck.rb
|
|
@@ -187,7 +189,7 @@ files:
|
|
|
187
189
|
- lib/aro.rb
|
|
188
190
|
- lib/aro/c.rb
|
|
189
191
|
- lib/aro/create.rb
|
|
190
|
-
- lib/aro/
|
|
192
|
+
- lib/aro/db.rb
|
|
191
193
|
- lib/aro/environment.rb
|
|
192
194
|
- lib/aro/i18n.rb
|
|
193
195
|
- lib/aro/prompt.rb
|