gloo 0.3.0 → 0.5.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/.DS_Store +0 -0
- data/.rubocop.yml +73 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +86 -83
- data/Rakefile +7 -6
- data/bin/console +4 -4
- data/gloo.gemspec +22 -18
- data/lib/gloo.rb +6 -6
- data/lib/gloo/app/args.rb +30 -31
- data/lib/gloo/app/engine.rb +80 -30
- data/lib/gloo/app/help.rb +17 -11
- data/lib/gloo/app/info.rb +3 -3
- data/lib/gloo/app/log.rb +17 -17
- data/lib/gloo/app/mode.rb +4 -4
- data/lib/gloo/app/settings.rb +51 -41
- data/lib/gloo/convert/string_to_datetime.rb +21 -0
- data/lib/gloo/convert/string_to_decimal.rb +20 -0
- data/lib/gloo/convert/string_to_integer.rb +20 -0
- data/lib/gloo/core/baseo.rb +7 -7
- data/lib/gloo/core/dictionary.rb +30 -27
- data/lib/gloo/core/error.rb +50 -0
- data/lib/gloo/core/event_manager.rb +17 -23
- data/lib/gloo/core/factory.rb +149 -39
- data/lib/gloo/core/gloo_system.rb +121 -54
- data/lib/gloo/core/heap.rb +15 -13
- data/lib/gloo/core/it.rb +5 -5
- data/lib/gloo/core/literal.rb +7 -7
- data/lib/gloo/core/obj.rb +138 -79
- data/lib/gloo/core/obj_finder.rb +9 -14
- data/lib/gloo/core/op.rb +8 -8
- data/lib/gloo/core/parser.rb +27 -26
- data/lib/gloo/core/pn.rb +68 -52
- data/lib/gloo/core/script.rb +7 -7
- data/lib/gloo/core/tokens.rb +39 -41
- data/lib/gloo/core/verb.rb +30 -19
- data/lib/gloo/exec/dispatch.rb +30 -0
- data/lib/gloo/exec/runner.rb +43 -0
- data/lib/gloo/expr/expression.rb +36 -43
- data/lib/gloo/expr/l_boolean.rb +7 -6
- data/lib/gloo/expr/l_decimal.rb +34 -0
- data/lib/gloo/expr/l_integer.rb +5 -4
- data/lib/gloo/expr/l_string.rb +13 -15
- data/lib/gloo/expr/op_div.rb +5 -5
- data/lib/gloo/expr/op_minus.rb +5 -5
- data/lib/gloo/expr/op_mult.rb +5 -5
- data/lib/gloo/expr/op_plus.rb +7 -7
- data/lib/gloo/objs/basic/alias.rb +111 -0
- data/lib/gloo/objs/basic/boolean.rb +63 -38
- data/lib/gloo/objs/basic/container.rb +71 -12
- data/lib/gloo/objs/basic/decimal.rb +96 -0
- data/lib/gloo/objs/basic/integer.rb +45 -16
- data/lib/gloo/objs/basic/script.rb +62 -38
- data/lib/gloo/objs/basic/string.rb +47 -15
- data/lib/gloo/objs/basic/text.rb +69 -21
- data/lib/gloo/objs/basic/untyped.rb +35 -10
- data/lib/gloo/objs/cli/banner.rb +137 -0
- data/lib/gloo/objs/cli/bar.rb +141 -0
- data/lib/gloo/objs/cli/colorize.rb +54 -24
- data/lib/gloo/objs/cli/confirm.rb +63 -29
- data/lib/gloo/objs/cli/menu.rb +236 -0
- data/lib/gloo/objs/cli/menu_item.rb +128 -0
- data/lib/gloo/objs/cli/pastel.rb +120 -0
- data/lib/gloo/objs/cli/prompt.rb +73 -31
- data/lib/gloo/objs/cli/select.rb +153 -0
- data/lib/gloo/objs/ctrl/each.rb +128 -61
- data/lib/gloo/objs/ctrl/repeat.rb +129 -0
- data/lib/gloo/objs/data/markdown.rb +109 -0
- data/lib/gloo/objs/data/table.rb +168 -0
- data/lib/gloo/objs/dev/git.rb +98 -64
- data/lib/gloo/objs/dt/date.rb +72 -0
- data/lib/gloo/objs/dt/datetime.rb +84 -0
- data/lib/gloo/objs/dt/time.rb +72 -0
- data/lib/gloo/objs/ror/erb.rb +82 -41
- data/lib/gloo/objs/ror/eval.rb +73 -31
- data/lib/gloo/objs/snd/play.rb +71 -0
- data/lib/gloo/objs/snd/say.rb +120 -0
- data/lib/gloo/objs/system/file_handle.rb +129 -48
- data/lib/gloo/objs/system/system.rb +84 -38
- data/lib/gloo/objs/web/http_get.rb +103 -46
- data/lib/gloo/objs/web/http_post.rb +70 -44
- data/lib/gloo/objs/web/json.rb +155 -0
- data/lib/gloo/objs/web/slack.rb +89 -58
- data/lib/gloo/objs/web/teams.rb +88 -53
- data/lib/gloo/objs/web/uri.rb +160 -0
- data/lib/gloo/persist/file_loader.rb +95 -85
- data/lib/gloo/persist/file_saver.rb +12 -12
- data/lib/gloo/persist/file_storage.rb +15 -15
- data/lib/gloo/persist/line_splitter.rb +79 -0
- data/lib/gloo/persist/persist_man.rb +63 -39
- data/lib/gloo/utils/words.rb +2 -2
- data/lib/gloo/verbs/alert.rb +67 -16
- data/lib/gloo/verbs/beep.rb +70 -0
- data/lib/gloo/verbs/cls.rb +67 -0
- data/lib/gloo/verbs/context.rb +61 -21
- data/lib/gloo/verbs/create.rb +52 -21
- data/lib/gloo/verbs/help.rb +186 -27
- data/lib/gloo/verbs/if.rb +55 -21
- data/lib/gloo/verbs/list.rb +55 -24
- data/lib/gloo/verbs/load.rb +47 -12
- data/lib/gloo/verbs/move.rb +128 -0
- data/lib/gloo/verbs/put.rb +90 -34
- data/lib/gloo/verbs/quit.rb +43 -12
- data/lib/gloo/verbs/run.rb +63 -18
- data/lib/gloo/verbs/save.rb +45 -10
- data/lib/gloo/verbs/show.rb +56 -22
- data/lib/gloo/verbs/tell.rb +45 -13
- data/lib/gloo/verbs/unless.rb +56 -21
- data/lib/gloo/verbs/version.rb +42 -12
- data/lib/gloo/verbs/wait.rb +73 -0
- data/lib/run.rb +5 -5
- metadata +90 -12
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# A looping construct...do something x times.
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
module Gloo
|
|
8
|
+
module Objs
|
|
9
|
+
class Repeat < Gloo::Core::Obj
|
|
10
|
+
|
|
11
|
+
KEYWORD = 'repeat'.freeze
|
|
12
|
+
KEYWORD_SHORT = 'repeat'.freeze
|
|
13
|
+
TIMES = 'times'.freeze
|
|
14
|
+
INDEX = 'index'.freeze
|
|
15
|
+
DO = 'do'.freeze
|
|
16
|
+
|
|
17
|
+
#
|
|
18
|
+
# The name of the object type.
|
|
19
|
+
#
|
|
20
|
+
def self.typename
|
|
21
|
+
return KEYWORD
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#
|
|
25
|
+
# The short name of the object type.
|
|
26
|
+
#
|
|
27
|
+
def self.short_typename
|
|
28
|
+
return KEYWORD_SHORT
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
#
|
|
32
|
+
# Get the URI from the child object.
|
|
33
|
+
# Returns nil if there is none.
|
|
34
|
+
#
|
|
35
|
+
def times
|
|
36
|
+
o = find_child TIMES
|
|
37
|
+
return o ? o.value : 0
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Run the do script once.
|
|
41
|
+
def run_do
|
|
42
|
+
o = find_child DO
|
|
43
|
+
return unless o
|
|
44
|
+
|
|
45
|
+
Gloo::Exec::Dispatch.message 'run', o
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Set the index of the current iteration.
|
|
49
|
+
def set_index( index )
|
|
50
|
+
o = find_child INDEX
|
|
51
|
+
return unless o
|
|
52
|
+
|
|
53
|
+
o.set_value index
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# ---------------------------------------------------------------------
|
|
57
|
+
# Children
|
|
58
|
+
# ---------------------------------------------------------------------
|
|
59
|
+
|
|
60
|
+
# Does this object have children to add when an object
|
|
61
|
+
# is created in interactive mode?
|
|
62
|
+
# This does not apply during obj load, etc.
|
|
63
|
+
def add_children_on_create?
|
|
64
|
+
return true
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Add children to this object.
|
|
68
|
+
# This is used by containers to add children needed
|
|
69
|
+
# for default configurations.
|
|
70
|
+
def add_default_children
|
|
71
|
+
fac = $engine.factory
|
|
72
|
+
fac.create_int TIMES, 0, self
|
|
73
|
+
fac.create_int INDEX, 0, self
|
|
74
|
+
fac.create_script DO, '', self
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# ---------------------------------------------------------------------
|
|
78
|
+
# Messages
|
|
79
|
+
# ---------------------------------------------------------------------
|
|
80
|
+
|
|
81
|
+
#
|
|
82
|
+
# Get a list of message names that this object receives.
|
|
83
|
+
#
|
|
84
|
+
def self.messages
|
|
85
|
+
return super + [ 'run' ]
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
#
|
|
89
|
+
# Run the repeat loop.
|
|
90
|
+
#
|
|
91
|
+
def msg_run
|
|
92
|
+
times.times do |index|
|
|
93
|
+
set_index index
|
|
94
|
+
run_do
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# ---------------------------------------------------------------------
|
|
99
|
+
# Help
|
|
100
|
+
# ---------------------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
#
|
|
103
|
+
# Get help for this object type.
|
|
104
|
+
#
|
|
105
|
+
def self.help
|
|
106
|
+
return <<~TEXT
|
|
107
|
+
REPEAT OBJECT TYPE
|
|
108
|
+
NAME: repeat
|
|
109
|
+
SHORTCUT: repeat
|
|
110
|
+
|
|
111
|
+
DESCRIPTION
|
|
112
|
+
Run a script a given number of times.
|
|
113
|
+
|
|
114
|
+
CHILDREN
|
|
115
|
+
times integer - 0
|
|
116
|
+
The number of times to run the script.
|
|
117
|
+
index integer - 0
|
|
118
|
+
The current iteration when the repeat loop is running.
|
|
119
|
+
do - script - none
|
|
120
|
+
The action we want to perform for iteration of the loop.
|
|
121
|
+
|
|
122
|
+
MESSAGES
|
|
123
|
+
run - Run the script for the given number of times.
|
|
124
|
+
TEXT
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Markdown data.
|
|
5
|
+
#
|
|
6
|
+
require 'tty-markdown'
|
|
7
|
+
require 'tty-pager'
|
|
8
|
+
|
|
9
|
+
module Gloo
|
|
10
|
+
module Objs
|
|
11
|
+
class Markdown < Gloo::Core::Obj
|
|
12
|
+
|
|
13
|
+
KEYWORD = 'markdown'.freeze
|
|
14
|
+
KEYWORD_SHORT = 'md'.freeze
|
|
15
|
+
|
|
16
|
+
#
|
|
17
|
+
# The name of the object type.
|
|
18
|
+
#
|
|
19
|
+
def self.typename
|
|
20
|
+
return KEYWORD
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
# The short name of the object type.
|
|
25
|
+
#
|
|
26
|
+
def self.short_typename
|
|
27
|
+
return KEYWORD_SHORT
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
#
|
|
31
|
+
# Set the value with any necessary type conversions.
|
|
32
|
+
#
|
|
33
|
+
def set_value( new_value )
|
|
34
|
+
self.value = new_value.to_s
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
#
|
|
38
|
+
# Does this object support multi-line values?
|
|
39
|
+
# Initially only true for scripts.
|
|
40
|
+
#
|
|
41
|
+
def multiline_value?
|
|
42
|
+
return false
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
#
|
|
46
|
+
# Get the number of lines of text.
|
|
47
|
+
#
|
|
48
|
+
def line_count
|
|
49
|
+
return value.split( "\n" ).count
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# ---------------------------------------------------------------------
|
|
53
|
+
# Messages
|
|
54
|
+
# ---------------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
#
|
|
57
|
+
# Get a list of message names that this object receives.
|
|
58
|
+
#
|
|
59
|
+
def self.messages
|
|
60
|
+
return super + %w[show page]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
#
|
|
64
|
+
# Show the markdown data in the terminal.
|
|
65
|
+
#
|
|
66
|
+
def msg_show
|
|
67
|
+
puts TTY::Markdown.parse self.value
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
#
|
|
71
|
+
# Show the markdown data in the terminal, paginated.
|
|
72
|
+
#
|
|
73
|
+
def msg_page
|
|
74
|
+
return unless self.value
|
|
75
|
+
|
|
76
|
+
md = TTY::Markdown.parse self.value
|
|
77
|
+
# pager = TTY::Pager::SystemPager.new command: 'less -R'
|
|
78
|
+
pager = TTY::Pager.new
|
|
79
|
+
pager.page( md )
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# ---------------------------------------------------------------------
|
|
83
|
+
# Help
|
|
84
|
+
# ---------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
#
|
|
87
|
+
# Get help for this object type.
|
|
88
|
+
#
|
|
89
|
+
def self.help
|
|
90
|
+
return <<~TEXT
|
|
91
|
+
MARKDOWN OBJECT TYPE
|
|
92
|
+
NAME: markdown
|
|
93
|
+
SHORTCUT: md
|
|
94
|
+
|
|
95
|
+
DESCRIPTION
|
|
96
|
+
Markdown data in a text string.
|
|
97
|
+
|
|
98
|
+
CHILDREN
|
|
99
|
+
None
|
|
100
|
+
|
|
101
|
+
MESSAGES
|
|
102
|
+
show - Show the markdown data in the terminal.
|
|
103
|
+
page - Show the markdown data in the terminal, paginated.
|
|
104
|
+
TEXT
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# A data table.
|
|
5
|
+
# The table container headers and data.
|
|
6
|
+
#
|
|
7
|
+
require 'tty-table'
|
|
8
|
+
require 'pastel'
|
|
9
|
+
|
|
10
|
+
module Gloo
|
|
11
|
+
module Objs
|
|
12
|
+
class Table < Gloo::Core::Obj
|
|
13
|
+
|
|
14
|
+
KEYWORD = 'table'.freeze
|
|
15
|
+
KEYWORD_SHORT = 'tbl'.freeze
|
|
16
|
+
HEADERS = 'headers'.freeze
|
|
17
|
+
DATA = 'data'.freeze
|
|
18
|
+
|
|
19
|
+
#
|
|
20
|
+
# The name of the object type.
|
|
21
|
+
#
|
|
22
|
+
def self.typename
|
|
23
|
+
return KEYWORD
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#
|
|
27
|
+
# The short name of the object type.
|
|
28
|
+
#
|
|
29
|
+
def self.short_typename
|
|
30
|
+
return KEYWORD_SHORT
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
#
|
|
34
|
+
# Get the list of headers.
|
|
35
|
+
# Returns nil if there is none.
|
|
36
|
+
#
|
|
37
|
+
def headers
|
|
38
|
+
o = find_child HEADERS
|
|
39
|
+
return [] unless o
|
|
40
|
+
|
|
41
|
+
return o.children.map( &:value )
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
#
|
|
45
|
+
# Get the list of column names.
|
|
46
|
+
# Returns nil if there is none.
|
|
47
|
+
#
|
|
48
|
+
def columns
|
|
49
|
+
o = find_child HEADERS
|
|
50
|
+
return [] unless o
|
|
51
|
+
|
|
52
|
+
return o.children.map( &:name )
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
#
|
|
56
|
+
# Get the list of data elements.
|
|
57
|
+
#
|
|
58
|
+
def data
|
|
59
|
+
o = find_child DATA
|
|
60
|
+
return [] unless o
|
|
61
|
+
|
|
62
|
+
o = Gloo::Objs::Alias.resolve_alias( o )
|
|
63
|
+
cols = self.columns
|
|
64
|
+
return o.children.map do |e|
|
|
65
|
+
cols.map { |h| e.find_child( h ).value }
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# ---------------------------------------------------------------------
|
|
70
|
+
# Children
|
|
71
|
+
# ---------------------------------------------------------------------
|
|
72
|
+
|
|
73
|
+
# Does this object have children to add when an object
|
|
74
|
+
# is created in interactive mode?
|
|
75
|
+
# This does not apply during obj load, etc.
|
|
76
|
+
def add_children_on_create?
|
|
77
|
+
return true
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Add children to this object.
|
|
81
|
+
# This is used by containers to add children needed
|
|
82
|
+
# for default configurations.
|
|
83
|
+
def add_default_children
|
|
84
|
+
fac = $engine.factory
|
|
85
|
+
fac.create_can HEADERS, self
|
|
86
|
+
fac.create_can DATA, self
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# ---------------------------------------------------------------------
|
|
90
|
+
# Messages
|
|
91
|
+
# ---------------------------------------------------------------------
|
|
92
|
+
|
|
93
|
+
#
|
|
94
|
+
# Get a list of message names that this object receives.
|
|
95
|
+
#
|
|
96
|
+
def self.messages
|
|
97
|
+
return super + %w[show]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
#
|
|
101
|
+
# Show the table in the CLI.
|
|
102
|
+
#
|
|
103
|
+
def msg_show
|
|
104
|
+
title = self.value
|
|
105
|
+
Gloo::Objs::Table.show headers, data, title
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# ---------------------------------------------------------------------
|
|
109
|
+
# Static table helper
|
|
110
|
+
# ---------------------------------------------------------------------
|
|
111
|
+
|
|
112
|
+
#
|
|
113
|
+
# Show the given table data.
|
|
114
|
+
#
|
|
115
|
+
def self.show( headers, data, title = nil )
|
|
116
|
+
pastel = ::Pastel.new
|
|
117
|
+
table = TTY::Table.new headers, data
|
|
118
|
+
pad = [ 0, 1, 0, 1 ]
|
|
119
|
+
rendered = table.render( :ascii, indent: 2, padding: pad ) do |r|
|
|
120
|
+
r.border.style = :blue
|
|
121
|
+
r.filter = proc do |val, row_index, _col_index|
|
|
122
|
+
# col_index % 2 == 1 ? pastel.red.on_green(val) : val
|
|
123
|
+
if row_index.zero?
|
|
124
|
+
pastel.blue( val )
|
|
125
|
+
else
|
|
126
|
+
row_index.odd? ? pastel.white( val ) : pastel.yellow( val )
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
puts "\n#{title.white}"
|
|
131
|
+
puts "#{rendered}\n\n"
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# ---------------------------------------------------------------------
|
|
135
|
+
# Help
|
|
136
|
+
# ---------------------------------------------------------------------
|
|
137
|
+
|
|
138
|
+
#
|
|
139
|
+
# Get help for this object type.
|
|
140
|
+
#
|
|
141
|
+
def self.help
|
|
142
|
+
return <<~TEXT
|
|
143
|
+
TABLE OBJECT TYPE
|
|
144
|
+
NAME: table
|
|
145
|
+
SHORTCUT: tbl
|
|
146
|
+
|
|
147
|
+
DESCRIPTION
|
|
148
|
+
A data table.
|
|
149
|
+
|
|
150
|
+
CHILDREN
|
|
151
|
+
headers - container
|
|
152
|
+
A list of headers.
|
|
153
|
+
The name of the header object needs to be the same as the
|
|
154
|
+
name of the object in the data container.
|
|
155
|
+
The value of the header is what will be displayed.
|
|
156
|
+
data - container
|
|
157
|
+
The table's data.
|
|
158
|
+
The data container will have one or more containers, each
|
|
159
|
+
of which represents one row of data.
|
|
160
|
+
|
|
161
|
+
MESSAGES
|
|
162
|
+
show - Show the contents of the table in the CLI.
|
|
163
|
+
TEXT
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
data/lib/gloo/objs/dev/git.rb
CHANGED
|
@@ -7,106 +7,140 @@
|
|
|
7
7
|
module Gloo
|
|
8
8
|
module Objs
|
|
9
9
|
class Git < Gloo::Core::Obj
|
|
10
|
-
|
|
11
|
-
KEYWORD = 'git_repo'
|
|
12
|
-
KEYWORD_SHORT = 'git'
|
|
13
10
|
|
|
14
|
-
|
|
11
|
+
KEYWORD = 'git_repo'.freeze
|
|
12
|
+
KEYWORD_SHORT = 'git'.freeze
|
|
13
|
+
|
|
14
|
+
#
|
|
15
15
|
# The name of the object type.
|
|
16
|
-
#
|
|
16
|
+
#
|
|
17
17
|
def self.typename
|
|
18
18
|
return KEYWORD
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
#
|
|
21
|
+
#
|
|
22
22
|
# The short name of the object type.
|
|
23
|
-
#
|
|
23
|
+
#
|
|
24
24
|
def self.short_typename
|
|
25
25
|
return KEYWORD_SHORT
|
|
26
26
|
end
|
|
27
|
-
|
|
28
|
-
#
|
|
27
|
+
|
|
28
|
+
#
|
|
29
29
|
# Get the path to the git repo (locally).
|
|
30
|
-
#
|
|
31
|
-
def
|
|
30
|
+
#
|
|
31
|
+
def path_value
|
|
32
32
|
return value
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
|
|
36
35
|
# ---------------------------------------------------------------------
|
|
37
36
|
# Messages
|
|
38
37
|
# ---------------------------------------------------------------------
|
|
39
38
|
|
|
40
|
-
#
|
|
39
|
+
#
|
|
41
40
|
# Get a list of message names that this object receives.
|
|
42
|
-
#
|
|
41
|
+
#
|
|
43
42
|
def self.messages
|
|
44
|
-
return super + [
|
|
45
|
-
"commit", "get_branch" ]
|
|
43
|
+
return super + %w[validate check_changes get_changes commit get_branch]
|
|
46
44
|
end
|
|
47
|
-
|
|
48
|
-
# Get the current working branch.
|
|
49
|
-
def msg_get_branch
|
|
50
|
-
branch = ""
|
|
51
|
-
path = get_path
|
|
52
|
-
if path and File.directory?( path )
|
|
53
|
-
branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
|
|
54
|
-
branch = branch.strip
|
|
55
|
-
end
|
|
56
45
|
|
|
57
|
-
|
|
58
|
-
|
|
46
|
+
# Get the current working branch.
|
|
47
|
+
def msg_get_branch
|
|
48
|
+
branch = ''
|
|
49
|
+
path = path_value
|
|
50
|
+
if path_is_dir?( path )
|
|
51
|
+
branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
|
|
52
|
+
branch = branch.strip
|
|
53
|
+
end
|
|
59
54
|
|
|
55
|
+
$engine.heap.it.set_to branch
|
|
56
|
+
end
|
|
60
57
|
|
|
61
|
-
|
|
58
|
+
# Commit pending changes.
|
|
62
59
|
def msg_commit
|
|
63
|
-
|
|
64
|
-
path =
|
|
65
|
-
if
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
60
|
+
msg = 'Commit'
|
|
61
|
+
path = path_value
|
|
62
|
+
if path_is_dir?( path )
|
|
63
|
+
if @params&.token_count&.positive?
|
|
64
|
+
expr = Gloo::Expr::Expression.new( @params.tokens )
|
|
65
|
+
msg = expr.evaluate
|
|
66
|
+
end
|
|
67
|
+
branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
|
|
68
|
+
branch = branch.strip
|
|
69
|
+
add = 'git add .'
|
|
70
|
+
cmt = 'git commit -m '
|
|
71
|
+
psh = 'git push origin '
|
|
72
|
+
`cd #{path};#{add};#{cmt}"#{msg}";#{psh}#{branch}`
|
|
73
|
+
end
|
|
74
|
+
$engine.heap.it.set_to msg
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
# Get the pending changes.
|
|
78
78
|
def msg_get_changes
|
|
79
|
-
path =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
path = path_value
|
|
80
|
+
result = `cd #{path}; git status -s` if path_is_dir?( path )
|
|
81
|
+
result ||= ''
|
|
82
|
+
$engine.heap.it.set_to result
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Is the given path non nil and is it a directory?
|
|
86
|
+
def path_is_dir?( path )
|
|
87
|
+
return path && File.directory?( path )
|
|
85
88
|
end
|
|
86
89
|
|
|
87
|
-
|
|
90
|
+
# Check to see if the repo has changes.
|
|
88
91
|
def msg_check_changes
|
|
89
|
-
|
|
90
|
-
path =
|
|
91
|
-
if
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
result = false
|
|
93
|
+
path = path_value
|
|
94
|
+
if path_is_dir?( path )
|
|
95
|
+
data = `cd #{path}; git status -s`
|
|
96
|
+
result = true unless data.strip.empty?
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
$engine.heap.it.set_to result
|
|
97
100
|
end
|
|
98
|
-
|
|
101
|
+
|
|
99
102
|
# Check to make sure this is a valide git repo.
|
|
100
103
|
def msg_validate
|
|
101
|
-
|
|
102
|
-
path =
|
|
103
|
-
if
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
result = false
|
|
105
|
+
path = path_value
|
|
106
|
+
if path_is_dir?( path )
|
|
107
|
+
pn = File.join( path, '.git' )
|
|
108
|
+
result = File.exist? pn
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
$engine.heap.it.set_to result
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# ---------------------------------------------------------------------
|
|
115
|
+
# Help
|
|
116
|
+
# ---------------------------------------------------------------------
|
|
106
117
|
|
|
107
|
-
|
|
118
|
+
#
|
|
119
|
+
# Get help for this object type.
|
|
120
|
+
#
|
|
121
|
+
def self.help
|
|
122
|
+
return <<~TEXT
|
|
123
|
+
GIT OBJECT TYPE
|
|
124
|
+
NAME: git_repo
|
|
125
|
+
SHORTCUT: git
|
|
126
|
+
|
|
127
|
+
DESCRIPTION
|
|
128
|
+
Reference to a git repository in the file system.
|
|
129
|
+
The value of the git_repo objectd is a string.
|
|
130
|
+
There are no children needed.
|
|
131
|
+
|
|
132
|
+
CHILDREN
|
|
133
|
+
None
|
|
134
|
+
|
|
135
|
+
MESSAGES
|
|
136
|
+
validate - Validate that this is a git repo.
|
|
137
|
+
check_changes - Check to see if there are any pending changes.
|
|
138
|
+
get_changes - Get the list of pending changes.
|
|
139
|
+
commit - Commit changes.
|
|
140
|
+
get_branch - Get the current branch.
|
|
141
|
+
TEXT
|
|
108
142
|
end
|
|
109
|
-
|
|
143
|
+
|
|
110
144
|
end
|
|
111
145
|
end
|
|
112
146
|
end
|