gazer 0.3.2 → 0.3.4
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/CHANGELOG.md +23 -0
- data/Gemfile.lock +1 -1
- data/lib/gzr/cli.rb +8 -0
- data/lib/gzr/command.rb +9 -0
- data/lib/gzr/commands/connection/cat.rb +66 -0
- data/lib/gzr/commands/connection/import.rb +78 -0
- data/lib/gzr/commands/connection/rm.rb +50 -0
- data/lib/gzr/commands/connection/test.rb +69 -0
- data/lib/gzr/commands/connection.rb +67 -1
- data/lib/gzr/commands/model/cat.rb +58 -0
- data/lib/gzr/commands/model/import.rb +57 -0
- data/lib/gzr/commands/model.rb +29 -0
- data/lib/gzr/commands/project/branch.rb +96 -0
- data/lib/gzr/commands/project/cat.rb +58 -0
- data/lib/gzr/commands/project/checkout.rb +65 -0
- data/lib/gzr/commands/project/deploy.rb +65 -0
- data/lib/gzr/commands/project/deploy_key.rb +60 -0
- data/lib/gzr/commands/project/import.rb +68 -0
- data/lib/gzr/commands/project/ls.rb +73 -0
- data/lib/gzr/commands/project/update.rb +69 -0
- data/lib/gzr/commands/project.rb +151 -0
- data/lib/gzr/commands/session/get.rb +47 -0
- data/lib/gzr/commands/session/login.rb +50 -0
- data/lib/gzr/commands/session/logout.rb +47 -0
- data/lib/gzr/commands/session/update.rb +51 -0
- data/lib/gzr/commands/session.rb +76 -0
- data/lib/gzr/modules/connection.rb +80 -0
- data/lib/gzr/modules/model.rb +29 -0
- data/lib/gzr/modules/project.rb +155 -0
- data/lib/gzr/modules/session.rb +81 -7
- data/lib/gzr/version.rb +1 -1
- metadata +23 -2
@@ -0,0 +1,96 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2018 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# subject to the following conditions:
|
11
|
+
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
require_relative '../../command'
|
25
|
+
require_relative '../../modules/project'
|
26
|
+
require 'tty-table'
|
27
|
+
|
28
|
+
module Gzr
|
29
|
+
module Commands
|
30
|
+
class Project
|
31
|
+
class Branch < Gzr::Command
|
32
|
+
include Gzr::Project
|
33
|
+
def initialize(project_id,options)
|
34
|
+
super()
|
35
|
+
@project_id = project_id
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(input: $stdin, output: $stdout)
|
40
|
+
say_warning(@options) if @options[:debug]
|
41
|
+
with_session do
|
42
|
+
if get_auth()[:workspace_id] == 'production'
|
43
|
+
say_warning %Q(
|
44
|
+
This command only works in dev mode. Use persistent sessions and
|
45
|
+
change to dev mode before running this command.
|
46
|
+
|
47
|
+
$ gzr session login --host looker.example.com
|
48
|
+
$ gzr session update dev --token_file --host looker.example.com
|
49
|
+
$ # run the command requiring dev mode here with the --token_file switch
|
50
|
+
$ gzr session logout --token_file --host looker.example.com
|
51
|
+
)
|
52
|
+
return
|
53
|
+
end
|
54
|
+
|
55
|
+
say_warning "querying git_branch(#{@project_id})" if @options[:debug]
|
56
|
+
data = [git_branch(@project_id)]
|
57
|
+
begin
|
58
|
+
say_ok "No active branch found"
|
59
|
+
return nil
|
60
|
+
end unless data && data.length > 0
|
61
|
+
|
62
|
+
if @options[:all]
|
63
|
+
say_warning "querying all_git_branches(#{@project_id})" if @options[:debug]
|
64
|
+
data += all_git_branches(@project_id).select{ |e| e.name != data[0].name }
|
65
|
+
end
|
66
|
+
begin
|
67
|
+
say_ok "No branches found"
|
68
|
+
return nil
|
69
|
+
end unless data && data.length > 0
|
70
|
+
|
71
|
+
table_hash = Hash.new
|
72
|
+
fields = field_names(@options[:fields])
|
73
|
+
table_hash[:header] = fields unless @options[:plain]
|
74
|
+
expressions = fields.collect { |fn| field_expression(fn) }
|
75
|
+
table_hash[:rows] = data.map do |row|
|
76
|
+
expressions.collect do |e|
|
77
|
+
eval "row.#{e}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
table = TTY::Table.new(table_hash)
|
81
|
+
alignments = fields.collect do |k|
|
82
|
+
(k =~ /id$/) ? :right : :left
|
83
|
+
end
|
84
|
+
begin
|
85
|
+
if @options[:csv] then
|
86
|
+
output.puts render_csv(table)
|
87
|
+
else
|
88
|
+
output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width)
|
89
|
+
end
|
90
|
+
end if table
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# subject to the following conditions:
|
11
|
+
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
require_relative '../../command'
|
25
|
+
require_relative '../../modules/project'
|
26
|
+
require_relative '../../modules/filehelper'
|
27
|
+
|
28
|
+
module Gzr
|
29
|
+
module Commands
|
30
|
+
class Project
|
31
|
+
class Cat < Gzr::Command
|
32
|
+
include Gzr::Project
|
33
|
+
include Gzr::FileHelper
|
34
|
+
def initialize(project_id,options)
|
35
|
+
super()
|
36
|
+
@project_id = project_id
|
37
|
+
@options = options
|
38
|
+
end
|
39
|
+
|
40
|
+
def execute(input: $stdin, output: $stdout)
|
41
|
+
say_warning(@options) if @options[:debug]
|
42
|
+
with_session do
|
43
|
+
data = cat_project(@project_id)
|
44
|
+
if data.nil?
|
45
|
+
say_warning "Project #{@project_id} not found"
|
46
|
+
return
|
47
|
+
end
|
48
|
+
data = trim_project(data) if @options[:trim]
|
49
|
+
|
50
|
+
write_file(@options[:dir] ? "Project_#{data[:id]}.json" : nil, @options[:dir],nil, output) do |f|
|
51
|
+
f.puts JSON.pretty_generate(data)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# subject to the following conditions:
|
11
|
+
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
require_relative '../../command'
|
25
|
+
require_relative '../../modules/project'
|
26
|
+
|
27
|
+
module Gzr
|
28
|
+
module Commands
|
29
|
+
class Project
|
30
|
+
class Checkout < Gzr::Command
|
31
|
+
include Gzr::Project
|
32
|
+
def initialize(project_id,name,options)
|
33
|
+
super()
|
34
|
+
@project_id = project_id
|
35
|
+
@name = name
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(input: $stdin, output: $stdout)
|
40
|
+
say_warning(@options) if @options[:debug]
|
41
|
+
with_session do
|
42
|
+
if get_auth()[:workspace_id] == 'production'
|
43
|
+
say_warning %Q(
|
44
|
+
This command only works in dev mode. Use persistent sessions and
|
45
|
+
change to dev mode before running this command.
|
46
|
+
|
47
|
+
$ gzr session login --host looker.example.com
|
48
|
+
$ gzr session update dev --token_file --host looker.example.com
|
49
|
+
$ # run the command requiring dev mode here with the --token_file switch
|
50
|
+
$ gzr session logout --token_file --host looker.example.com
|
51
|
+
)
|
52
|
+
return
|
53
|
+
end
|
54
|
+
data = update_git_branch(@project_id, @name )
|
55
|
+
if data.nil?
|
56
|
+
say_warning "Project #{@project_id} not found"
|
57
|
+
return
|
58
|
+
end
|
59
|
+
output.puts data
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
# The MIT License (MIT)
|
3
|
+
|
4
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
5
|
+
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
7
|
+
# this software and associated documentation files (the "Software"), to deal in
|
8
|
+
# the Software without restriction, including without limitation the rights to
|
9
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
10
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
11
|
+
# subject to the following conditions:
|
12
|
+
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
18
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
19
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
20
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
21
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
# frozen_string_literal: true
|
24
|
+
|
25
|
+
require_relative '../../command'
|
26
|
+
require_relative '../../modules/project'
|
27
|
+
|
28
|
+
module Gzr
|
29
|
+
module Commands
|
30
|
+
class Project
|
31
|
+
class Deploy < Gzr::Command
|
32
|
+
include Gzr::Project
|
33
|
+
def initialize(project_id,options)
|
34
|
+
super()
|
35
|
+
@project_id = project_id
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(input: $stdin, output: $stdout)
|
40
|
+
say_warning(@options) if @options[:debug]
|
41
|
+
with_session do
|
42
|
+
if get_auth()[:workspace_id] == 'production'
|
43
|
+
say_warning %Q(
|
44
|
+
This command only works in dev mode. Use persistent sessions and
|
45
|
+
change to dev mode before running this command.
|
46
|
+
|
47
|
+
$ gzr session login --host looker.example.com
|
48
|
+
$ gzr session update dev --token_file --host looker.example.com
|
49
|
+
$ # run the command requiring dev mode here with the --token_file switch
|
50
|
+
$ gzr session logout --token_file --host looker.example.com
|
51
|
+
)
|
52
|
+
return
|
53
|
+
end
|
54
|
+
data = deploy_to_production(@project_id)
|
55
|
+
if data.nil?
|
56
|
+
say_warning "Project #{@project_id} not found"
|
57
|
+
return
|
58
|
+
end
|
59
|
+
output.puts data
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# subject to the following conditions:
|
11
|
+
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
require_relative '../../../gzr'
|
25
|
+
require_relative '../../command'
|
26
|
+
require_relative '../../modules/project'
|
27
|
+
|
28
|
+
module Gzr
|
29
|
+
module Commands
|
30
|
+
class Project
|
31
|
+
class DeployKey < Gzr::Command
|
32
|
+
include Gzr::Project
|
33
|
+
def initialize(id,options)
|
34
|
+
super()
|
35
|
+
@id = id
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(input: $stdin, output: $stdout)
|
40
|
+
say_warning("options: #{@options.inspect}", output: output) if @options[:debug]
|
41
|
+
with_session do
|
42
|
+
if get_auth()[:workspace_id] == 'production'
|
43
|
+
say_warning %Q(
|
44
|
+
This command only works in dev mode. Use persistent sessions and
|
45
|
+
change to dev mode before running this command.
|
46
|
+
|
47
|
+
$ gzr session login --host looker.example.com
|
48
|
+
$ gzr session update dev --token_file --host looker.example.com
|
49
|
+
$ # run the command requiring dev mode here with the --token_file switch
|
50
|
+
$ gzr session logout --token_file --host looker.example.com
|
51
|
+
)
|
52
|
+
end
|
53
|
+
key = git_deploy_key(@id) || create_git_deploy_key(@id)
|
54
|
+
output.puts key
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# subject to the following conditions:
|
11
|
+
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
require_relative '../../../gzr'
|
25
|
+
require_relative '../../command'
|
26
|
+
require_relative '../../modules/project'
|
27
|
+
require_relative '../../modules/filehelper'
|
28
|
+
|
29
|
+
module Gzr
|
30
|
+
module Commands
|
31
|
+
class Project
|
32
|
+
class Import < Gzr::Command
|
33
|
+
include Gzr::Project
|
34
|
+
include Gzr::FileHelper
|
35
|
+
def initialize(file, options)
|
36
|
+
super()
|
37
|
+
@file = file
|
38
|
+
@options = options
|
39
|
+
end
|
40
|
+
|
41
|
+
def execute(input: $stdin, output: $stdout)
|
42
|
+
say_warning("options: #{@options.inspect}", output: output) if @options[:debug]
|
43
|
+
with_session do
|
44
|
+
if get_auth()[:workspace_id] == 'production'
|
45
|
+
say_warning %Q(
|
46
|
+
This command only works in dev mode. Use persistent sessions and
|
47
|
+
change to dev mode before running this command.
|
48
|
+
|
49
|
+
$ gzr session login --host looker.example.com
|
50
|
+
$ gzr session update dev --token_file --host looker.example.com
|
51
|
+
$ # run the command requiring dev mode here with the --token_file switch
|
52
|
+
$ gzr session logout --token_file --host looker.example.com
|
53
|
+
)
|
54
|
+
end
|
55
|
+
read_file(@file) do |data|
|
56
|
+
data.select! do |k,v|
|
57
|
+
(keys_to_keep('create_project') - [:git_remote_url]).include? k
|
58
|
+
end
|
59
|
+
project = create_project(data)
|
60
|
+
output.puts "Created project #{project[:id]}" unless @options[:plain]
|
61
|
+
output.puts project[:id] if @options[:plain]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2018 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# subject to the following conditions:
|
11
|
+
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
require_relative '../../command'
|
25
|
+
require_relative '../../modules/project'
|
26
|
+
require 'tty-table'
|
27
|
+
|
28
|
+
module Gzr
|
29
|
+
module Commands
|
30
|
+
class Project
|
31
|
+
class Ls < Gzr::Command
|
32
|
+
include Gzr::Project
|
33
|
+
def initialize(options)
|
34
|
+
super()
|
35
|
+
@options = options
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute(input: $stdin, output: $stdout)
|
39
|
+
say_warning(@options) if @options[:debug]
|
40
|
+
with_session do
|
41
|
+
say_warning "querying all_projects({ fields: '#{@options[:fields]}' })" if @options[:debug]
|
42
|
+
data = all_projects(fields: @options[:fields])
|
43
|
+
begin
|
44
|
+
say_ok "No projects found"
|
45
|
+
return nil
|
46
|
+
end unless data && data.length > 0
|
47
|
+
|
48
|
+
table_hash = Hash.new
|
49
|
+
fields = field_names(@options[:fields])
|
50
|
+
table_hash[:header] = fields unless @options[:plain]
|
51
|
+
expressions = fields.collect { |fn| field_expression(fn) }
|
52
|
+
table_hash[:rows] = data.map do |row|
|
53
|
+
expressions.collect do |e|
|
54
|
+
eval "row.#{e}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
table = TTY::Table.new(table_hash)
|
58
|
+
alignments = fields.collect do |k|
|
59
|
+
(k =~ /id$/) ? :right : :left
|
60
|
+
end
|
61
|
+
begin
|
62
|
+
if @options[:csv] then
|
63
|
+
output.puts render_csv(table)
|
64
|
+
else
|
65
|
+
output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width)
|
66
|
+
end
|
67
|
+
end if table
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# subject to the following conditions:
|
11
|
+
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
require_relative '../../../gzr'
|
25
|
+
require_relative '../../command'
|
26
|
+
require_relative '../../modules/project'
|
27
|
+
require_relative '../../modules/filehelper'
|
28
|
+
|
29
|
+
module Gzr
|
30
|
+
module Commands
|
31
|
+
class Project
|
32
|
+
class Update < Gzr::Command
|
33
|
+
include Gzr::Project
|
34
|
+
include Gzr::FileHelper
|
35
|
+
def initialize(id,file, options)
|
36
|
+
super()
|
37
|
+
@id = id
|
38
|
+
@file = file
|
39
|
+
@options = options
|
40
|
+
end
|
41
|
+
|
42
|
+
def execute(input: $stdin, output: $stdout)
|
43
|
+
say_warning("options: #{@options.inspect}", output: output) if @options[:debug]
|
44
|
+
with_session do
|
45
|
+
if get_auth()[:workspace_id] == 'production'
|
46
|
+
say_warning %Q(
|
47
|
+
This command only works in dev mode. Use persistent sessions and
|
48
|
+
change to dev mode before running this command.
|
49
|
+
|
50
|
+
$ gzr session login --host looker.example.com
|
51
|
+
$ gzr session update dev --token_file --host looker.example.com
|
52
|
+
$ # run the command requiring dev mode here with the --token_file switch
|
53
|
+
$ gzr session logout --token_file --host looker.example.com
|
54
|
+
)
|
55
|
+
end
|
56
|
+
read_file(@file) do |data|
|
57
|
+
data.select! do |k,v|
|
58
|
+
keys_to_keep('update_project').include? k
|
59
|
+
end
|
60
|
+
project = update_project(@id, data)
|
61
|
+
output.puts "Updated project #{project[:id]}" unless @options[:plain]
|
62
|
+
output.puts project[:id] if @options[:plain]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|