1#!/usr/bin/env ruby 2# Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15# Huawei Technologies Co.,Ltd. 16 17require 'optparse' 18require 'ostruct' 19require 'yaml' 20 21options = OpenStruct.new 22optparser = OptionParser.new do |opts| 23 opts.banner = 'Usage: gen_ruby.rb [options]' 24 25 opts.on('-d', '--data FILE', 'Logger data file in YAML format') 26 opts.on('-p', '--plugins FILE', 'Plugins data file in YAML format') 27 opts.on('-o', '--output FILE', 'Output file (default is stdout)') 28 29 opts.on('-h', '--help', 'Prints this help') do 30 puts opts 31 exit 32 end 33end 34optparser.parse!(into: options) 35 36exit unless options.data 37exit unless options.plugins 38 39data = YAML.load_file(File.expand_path(options.data)) 40plugins_data = YAML.load_file(File.expand_path(options.plugins)) 41 42if plugins_data['plugins'] 43 plugins_data['plugins'].each do |plugins| 44 name = plugins.keys.first 45 plugin_data = plugins[name]['logger'] 46 data['components'] += plugin_data['components'] if plugin_data 47 end 48end 49 50output = options.output ? File.open(File.expand_path(options.output), 'w') : $stdout 51output.write(data.to_yaml) 52output.close 53