Skip to content

Commit

Permalink
yank ig loading code
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaumik-Ashraf committed Nov 30, 2023
1 parent c41d874 commit c7ba319
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 56 deletions.
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ PATH
pry-byebug
puma (~> 5.6.7)
rake (~> 13.0)
rubyzip (= 2.3.2)
sequel (~> 5.42.0)
sidekiq (~> 6.5.6)
sqlite3 (~> 1.4)
Expand Down Expand Up @@ -270,7 +269,6 @@ GEM
rubocop (~> 1.0)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
sequel (5.42.0)
sidekiq (6.5.12)
connection_pool (>= 2.2.5, < 3)
Expand Down
1 change: 0 additions & 1 deletion inferno_core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'pry-byebug'
spec.add_runtime_dependency 'puma', '~> 5.6.7'
spec.add_runtime_dependency 'rake', '~> 13.0'
spec.add_runtime_dependency 'rubyzip', '2.3.2'
spec.add_runtime_dependency 'sequel', '~> 5.42.0'
spec.add_runtime_dependency 'sidekiq', '~> 6.5.6'
spec.add_runtime_dependency 'sqlite3', '~> 1.4'
Expand Down
2 changes: 1 addition & 1 deletion lib/inferno/apps/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def suites
desc 'suite SUBCOMMAND ...ARGS', 'Perform suite-based operations'
subcommand 'suite', Suite

register(New, 'new', 'new TEST_KIT_NAME [-i IG_URL]', 'Run `inferno new --help` for full help')
register(New, 'new', 'new TEST_KIT_NAME', 'Run `inferno new --help` for full help')
end
end
end
43 changes: 3 additions & 40 deletions lib/inferno/apps/cli/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ class New < Thor::Group
`inferno new test_fhir_app`
=> generates an Inferno app
`inferno new test_us_core -i https://build.fhir.org/ig/HL7/US-Core/`
=> generates Inferno app and loads US Core implementation guide
`inferno new test_my_ig -i /absolute/path/to/ig/package.tgz -a Name`
=> generates Inferno app, loads a local implementation guide, and specifies Name as author
`inferno new test_my_ig -a MyName`
=> generates Inferno app and specifies MyName as gemspec author
https://inferno-framework.github.io/index.html
HELP

def self.banner
'inferno new TEST_KIT_NAME [-i IG_URL]'
'inferno new TEST_KIT_NAME'
end

def self.source_root
Expand All @@ -36,12 +33,6 @@ def self.source_root
type: :string,
required: true,
desc: 'name for new Inferno project'
class_option :implementation_guide,
type: :string,
aliases: '-i',
default: nil,
banner: 'IG_URL',
desc: 'URL to an implementation guide or absolute path to a package.tgz'
class_option :author,
type: :string,
aliases: '-a',
Expand All @@ -53,7 +44,6 @@ def self.source_root

def create_app
directory('.', root_name, { mode: :preserve, recursive: true, verbose: !options['quiet'] })
load_ig
say_unless_quiet "Created #{root_name} Inferno test kit!", :green

return unless options['pretend']
Expand All @@ -64,37 +54,10 @@ def create_app

private

def load_ig
return unless normalized_ig_uri

begin
get(normalized_ig_uri, ig_file, verbose: !options['quiet'])
rescue StandardError => e
say_error e.message, :red
say_error "Failed to load #{normalized_ig_uri}", :red
say_error "Please add the implementation guide package.tgz file into #{ig_path}", :red
else
say_unless_quiet "Loaded implementation guide #{normalized_ig_uri}", :green
end
end

def normalized_ig_uri
uri = options['implementation_guide']
return if uri.nil?

uri = uri.gsub(%r{[^/]*\.html\s*$}, 'package.tgz')
uri = File.join(uri, 'package.tgz') unless uri.ends_with? 'package.tgz'
uri
end

def ig_path
File.join('lib', library_name, 'igs')
end

def ig_file
File.join(root_name, ig_path, 'package.tgz')
end

def authors
options['author'].empty? ? options['author'].append(default_author) : options['author']
end
Expand Down
15 changes: 3 additions & 12 deletions spec/inferno/apps/cli/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
ABSOLUTE_PATH_TO_IG = File.expand_path('../../../fixtures/small_package.tgz', __dir__)

RSpec.describe Inferno::CLI::New do # rubocop:disable RSpec/FilePath
before do |_test|
stub_request(:get, %r{https?://.*package.tgz})
.to_return(status: 200, body: File.read(ABSOLUTE_PATH_TO_IG), headers: { 'Content-Type' => 'application/gzip' })
end

around do |test|
Dir.mktmpdir do |tmpdir|
FileUtils.chdir(tmpdir) do
Expand All @@ -19,10 +14,6 @@

[
%w[test-fhir-app],
%w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/fhir-udap-security-ig/],
%w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/fhir-udap-security-ig/index.html],
%w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/fhir-udap-security-ig/package.tgz],
%W[test-fhir-app --implementation-guide #{ABSOLUTE_PATH_TO_IG}],
%w[test-fhir-app --author ABC --author DEF]
].each do |cli_args|
cli_args.append('--quiet')
Expand All @@ -35,11 +26,11 @@
expect(File).to exist('test-fhir-app/test_fhir_app.gemspec')
expect(File).to exist('test-fhir-app/lib/test_fhir_app.rb')

if cli_args.include? '--implementation-guide'
expect(File).to exist('test-fhir-app/lib/test_fhir_app/igs/package.tgz')
if cli_args.include? '--author'
expect(File.read('test-fhir-app/test_fhir_app.gemspec')).to match(/authors\s*=.*ABC/)
end

if cli_args.include? '--author'
if cli_args.count('--author') == 2
expect(File.read('test-fhir-app/test_fhir_app.gemspec')).to match(/authors\s*=.*ABC.*DEF/)
end
end
Expand Down

0 comments on commit c7ba319

Please sign in to comment.