Skip to content

Commit 1e835bf

Browse files
committed
Setup pyxis for chatops usage
1 parent f8f5291 commit 1e835bf

File tree

5 files changed

+61
-8
lines changed

5 files changed

+61
-8
lines changed

bin/chatops

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require 'stringio'
5+
require_relative '../lib/pyxis'
6+
7+
original_stdout = $stdout
8+
stringio = StringIO.new
9+
$stdout = stringio
10+
11+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
12+
config = { debug: true } # we want the error to be raised
13+
14+
begin
15+
result = Pyxis::Cli.start(ARGV, config)
16+
successful = true
17+
rescue Thor::Error, Pyxis::Error => e
18+
result = "#{e.class}\n#{e.message}"
19+
successful = false
20+
end
21+
22+
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
23+
24+
SemanticLogger.flush
25+
26+
$stdout = original_stdout
27+
28+
SECTION = 'chat_reply'
29+
30+
puts "section_start:#{Time.now.to_i}:#{SECTION}\r\033[0K"
31+
32+
puts "$ pyxis #{ARGV.join(' ')}"
33+
puts '```'
34+
puts
35+
36+
puts result || stringio.string
37+
38+
puts
39+
puts '```'
40+
puts "#{successful ? 'Finished' : 'Failed'} in #{(end_time - start_time).round(2)} seconds"
41+
42+
puts "section_end:#{Time.now.to_i}:#{SECTION}\r\033[0K"
43+
44+
exit(successful)

bin/pyxis

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33

44
require_relative '../lib/pyxis'
55

6-
Pyxis::Cli.start(ARGV)
6+
result = Pyxis::Cli.start(ARGV)
7+
SemanticLogger.flush
8+
9+
puts result

lib/pyxis.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
Bundler.require
55

66
module Pyxis
7+
Error = Class.new(StandardError)
78
end
89

910
loader = Zeitwerk::Loader.for_gem
1011
loader.setup
1112
loader.eager_load_namespace(Pyxis::Logger)
1213
loader.eager_load_namespace(Pyxis::DryRunEnforcer)
14+
loader.eager_load_namespace(Pyxis::Project::Base)

lib/pyxis/commands/components.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,33 @@
33
module Pyxis
44
module Commands
55
class Components < Thor
6+
include PermissionHelper
7+
68
desc 'info [BUILD_ID]', 'Get the component versions for a reticulum build'
79
def info(build_id)
810
component_versions = ManagedVersioning::ComponentInfo.new(build_id).execute
911

10-
SemanticLogger.flush
11-
12-
puts 'Versions of each component'
12+
result = 'Versions of each component'
1313
component_versions.each do |component, version|
14-
puts "#{component}: #{version}"
14+
result += "\n#{component}: #{version}"
1515
end
16+
result
1617
end
1718

1819
desc 'update [COMPONENT]', 'Update a component in reticulum'
1920
def update(component)
21+
assert_executed_by_schedule!
22+
2023
updater(component).execute
2124
end
2225

2326
desc 'list', 'List all available components'
2427
def list
25-
puts 'Available components:'
28+
result = 'Available components:'
2629
Pyxis::Project.components.each do |project|
27-
puts "- #{project.downcase}"
30+
result += "\n- #{project.downcase}"
2831
end
32+
result
2933
end
3034

3135
desc 'get_version COMPONENT', 'Get the current version of a component in reticulum'

lib/pyxis/logger.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def call(env)
4545

4646
SemanticLogger.application = 'pyxis'
4747
SemanticLogger.default_level = ENV.fetch('LOG_LEVEL', 'debug').to_sym
48-
SemanticLogger.add_appender(io: $stdout, level: SemanticLogger.default_level,
48+
SemanticLogger.add_appender(io: $stderr, level: SemanticLogger.default_level,
4949
formatter: Pyxis::Logger::NoProcessColorFormatter.new)
5050

5151
SemanticLogger.push_tags('dry-run') if Pyxis::GlobalStatus.dry_run?

0 commit comments

Comments
 (0)