[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [websites/inqlude] /: Move version output to CliController
From:       Cornelius Schumacher <schumacher () kde ! org>
Date:       2016-10-15 22:49:43
Message-ID: E1bvXlv-0003rJ-Ir () code ! kde ! org
[Download RAW message or body]

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/dd0fa0dfe41f1b86dea411daf53247f06078b37f

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 = s
   end
 
-  def self.distro
-    @@distro if @@distro
-
-    @@distro = Distro.detect
-    if !@@distro
-      STDERR.puts "Warning: unable to detect distro."
-    end
-  end
-
   desc "global", "Global options", :hide => true
   def global
     if options[:version]
-      puts "Inqlude: #{@@settings.version}"
-
-      qmake_out = `qmake -v`
-      qmake_out =~ /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 = self.distro.installed handler
+      manifests = 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 => options[:dry_run]
+      Distro.detect.install manifest, :dry_run => 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 = `qmake -v`
+    qmake_out =~ /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_spec.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
+    "<unknown distro>"
+  end
+
+  def version
+    "<unknown version>"
+  end
+end
+
+describe CliController do
+  let(:distro) {DistroUnknown.new}
+
+  describe ".print_versions" do
+    it "prints versions" do
+      expected_output = <<EOT
+Inqlude: #{Inqlude::VERSION}
+Qt: 4.8.6
+OS: <unknown distro> <unknown version>
+EOT
+      expect {
+        CliController.print_versions(distro)
+      }.to output(expected_output).to_stdout
+    end
+  end
+end

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic