Git commit dd0fa0dfe41f1b86dea411daf53247f06078b37f by Cornelius Schumacher. Committed on 15/10/2016 at 09:33. Pushed by cschumac into branch 'master'. Move version output to CliController The CliController is supposed to hold the logic for the command line parsing. Only the pure parsing itself should stay in Cli. This is a first step to get there. Other code will be moved later. M +4 -23 lib/cli.rb A +15 -0 lib/cli_controller.rb M +1 -0 lib/inqlude.rb A +28 -0 spec/unit/cli_controller_spec.rb http://commits.kde.org/websites/inqlude/dd0fa0dfe41f1b86dea411daf53247f0607= 8b37f diff --git a/lib/cli.rb b/lib/cli.rb index f1502c4..a98a6a8 100644 --- a/lib/cli.rb +++ b/lib/cli.rb @@ -26,29 +26,10 @@ class Cli < Thor @@settings =3D s end = - def self.distro - @@distro if @@distro - - @@distro =3D Distro.detect - if !@@distro - STDERR.puts "Warning: unable to detect distro." - end - end - desc "global", "Global options", :hide =3D> true def global if options[:version] - puts "Inqlude: #{@@settings.version}" - - qmake_out =3D `qmake -v` - qmake_out =3D~ /Qt version (.*) in/ - puts "Qt: #{$1}" - - if self.distro - puts "OS: #{self.distro.name} #{self.distro.version}" - else - puts "OS: unknown" - end + CliController.print_versions(Distro.detect) else Cli.help shell end @@ -68,7 +49,7 @@ class Cli < Thor puts library.name + " (" + library.versions.join(", ") + ")" end else - manifests =3D self.distro.installed handler + manifests =3D Distro.detect.installed handler manifests.each do |manifest| puts manifest["name"] end @@ -290,7 +271,7 @@ actual domain." if !manifest STDERR.puts "Manifest for '#{name}' not found" else - self.distro.uninstall manifest + Distro.detect.uninstall manifest end end = @@ -303,7 +284,7 @@ actual domain." if !manifest STDERR.puts "Manifest for '#{name}' not found" else - self.distro.install manifest, :dry_run =3D> options[:dry_run] + Distro.detect.install manifest, :dry_run =3D> options[:dry_run] end end = diff --git a/lib/cli_controller.rb b/lib/cli_controller.rb new file mode 100644 index 0000000..86c8a92 --- /dev/null +++ b/lib/cli_controller.rb @@ -0,0 +1,15 @@ +class CliController + def self.print_versions(distro) + puts "Inqlude: #{Inqlude::VERSION}" + + qmake_out =3D `qmake -v` + qmake_out =3D~ /Qt version (.*) in/ + puts "Qt: #{$1}" + + if distro + puts "OS: #{distro.name} #{distro.version}" + else + puts "OS: unknown" + end + end = +end diff --git a/lib/inqlude.rb b/lib/inqlude.rb index 377be3e..a05de79 100644 --- a/lib/inqlude.rb +++ b/lib/inqlude.rb @@ -29,3 +29,4 @@ require_relative("manifest") require_relative("kde_frameworks_creator") require_relative("kde_frameworks_release") require_relative("downloader") +require_relative("cli_controller") \ No newline at end of file diff --git a/spec/unit/cli_controller_spec.rb b/spec/unit/cli_controller_sp= ec.rb new file mode 100644 index 0000000..94a882e --- /dev/null +++ b/spec/unit/cli_controller_spec.rb @@ -0,0 +1,28 @@ +require_relative "spec_helper" + +class DistroUnknown + def name + "" + end + + def version + "" + end +end + +describe CliController do + let(:distro) {DistroUnknown.new} + + describe ".print_versions" do + it "prints versions" do + expected_output =3D < +EOT + expect { + CliController.print_versions(distro) + }.to output(expected_output).to_stdout + end + end +end