arli 0.8.3 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,27 @@
1
+ require_relative 'library/single_version'
2
+ require_relative 'library/multi_version'
3
+ require 'arduino/library/model'
4
+ require 'arli/errors'
5
+
1
6
  module Arli
2
7
  module Library
8
+ def library_model(lib)
9
+ return lib if lib.is_a?(::Arduino::Library::Model)
10
+ ::Arduino::Library::Model.from(lib).tap do |model|
11
+ if model.nil?
12
+ lib_output = (lib && lib['name']) ? lib['name'] : lib.to_s
13
+ raise Arli::Errors::LibraryNotFound, 'Error: '.bold.red +
14
+ "Library #{lib_output.yellow} ".red + "was not found.\n\n".red +
15
+ %Q[ HINT: run #{"arli search 'name: /#{lib_output}/'".green}\n] +
16
+ %Q[ to find the exact name of the library you are trying\n] +
17
+ %Q[ to install. Alternatively, provide a url: field.\n]
18
+ end
19
+ end
20
+ end
3
21
 
22
+ def make_lib(lib)
23
+ ::Arli::Library::SingleVersion.new(library_model(lib))
24
+ end
4
25
  end
5
26
  end
6
27
 
7
- require_relative 'library/proxy'
8
- require_relative 'library/installer'
@@ -1,12 +1,12 @@
1
1
  require 'forwardable'
2
2
  require 'arli'
3
3
  require 'arli/actions'
4
- require_relative 'proxy'
4
+ require_relative 'single_version'
5
5
 
6
6
  module Arli
7
7
  module Library
8
8
  class Installer
9
- include ::Arli::Output
9
+ include ::Arli::Helpers::Output
10
10
 
11
11
  extend Forwardable
12
12
  def_delegators :@library, :exists?
@@ -0,0 +1,153 @@
1
+ require 'forwardable'
2
+ require 'arli'
3
+ require 'arli/actions'
4
+ require_relative 'single_version'
5
+
6
+ module Arli
7
+ module Library
8
+ class MultiVersion
9
+ class << self
10
+ def format_methods
11
+ new({}).methods.grep(/^to_s_/).map { |m| m.to_s.gsub(/^to_s_/, '') }.map(&:to_sym)
12
+ end
13
+ end
14
+
15
+ attr_accessor :latest_version_library, :versions
16
+
17
+ include ::Arli::Helpers::Output
18
+
19
+ def ==(other)
20
+ other.instance_of?(self.class) && self.name == other.name
21
+ end
22
+
23
+ alias_method :eql?, :==
24
+ alias_method :lib, :latest_version_library
25
+ alias_method :lib=, :latest_version_library=
26
+
27
+ def initialize(a_lib = nil, versions = [])
28
+ Colored2.disable! if Arli.config.no_color
29
+ self.latest_version_library = a_lib if a_lib
30
+ self.versions = versions || []
31
+ self.versions << a_lib.version if (a_lib && a_lib.respond_to?(:version) && self.versions.empty?)
32
+ end
33
+
34
+ def add_version(library: nil)
35
+ if library
36
+ if lib.nil? || library.version_to_i > lib.version_to_i
37
+ self.latest_version_library = library
38
+ end
39
+ self.versions << library.version
40
+ elsif version
41
+ self.versions << library.version
42
+ end
43
+ normalize_version_array!
44
+ end
45
+
46
+ def name
47
+ latest_version_library.name
48
+ end
49
+
50
+ def hash
51
+ lib.name.hash
52
+ end
53
+
54
+ # Various print formats
55
+ # --format <ARG> is inserted after "to_s_<format>"
56
+ def to_s_with_versions(limit = 4)
57
+ append do |out|
58
+ out << library_name
59
+ out << append_truncated_version_list(limit)
60
+ end
61
+ end
62
+
63
+ def to_s_long
64
+ lib_versions = versions.clone
65
+ latest = lib_versions.pop
66
+ append do
67
+ "\n"
68
+ "Name: #{lib.name.bold.yellow}\n" +
69
+ "Versions: #{latest.bold.yellow}, #{lib_versions.reverse.join(', ').green}\n" +
70
+ (lib.author ? "Author(s): #{lib.author.red}\n" : '') +
71
+ (lib.website ? "Website: #{lib.website.cyan}\n" : '') +
72
+ "Sentence: #{(lib.sentence).blue}\n" +
73
+ ((lib.paragraph && (lib.paragraph != lib.sentence)) ?
74
+ "Description: #{reformat_wrapped(lib.paragraph).magenta}\n" : "\n")
75
+ end
76
+ end
77
+
78
+ def to_s_short
79
+ append do
80
+ printf append_name[0..45]
81
+ indent_cursor 48
82
+ printf append_latest_version
83
+ indent_cursor 60
84
+ printf append_total_versions
85
+ end
86
+ end
87
+
88
+ def to_s_json
89
+ append do
90
+ JSON.pretty_generate(lib.to_hash) + ","
91
+ end
92
+ end
93
+
94
+ def to_s_yaml
95
+ append do
96
+ YAML.dump(lib.to_hash)
97
+ end
98
+ end
99
+
100
+ private
101
+
102
+ def stream
103
+ @stream = StringIO.new
104
+ end
105
+
106
+ def append
107
+ stream.tap do |out|
108
+ out << yield if block_given?
109
+ end.string
110
+ end
111
+
112
+ def append_architecture
113
+ unless lib.architectures.empty? || lib.architectures.include?('*')
114
+ append { "supports: #{lib.architectures.join(', ').bold.green}" }
115
+ end
116
+ end
117
+
118
+ def append_name
119
+ append { "#{lib.name.magenta}" }
120
+ end
121
+
122
+ def append_author
123
+ append { "by #{lib.author.blue}" }
124
+ end
125
+
126
+ def append_latest_version
127
+ latest = versions.clone.pop
128
+ append { " (#{latest.cyan})" }
129
+ end
130
+
131
+ def append_total_versions
132
+ append { "(#{sprintf("%2d", versions.size)} total versions )".green}
133
+ end
134
+
135
+ def append_truncated_version_list(limit)
136
+ append { truncate_version_list(limit) }
137
+ end
138
+
139
+ def normalize_version_array!
140
+ self.versions = versions.flatten.compact.uniq.sort
141
+ end
142
+
143
+ def reformat_wrapped(s, width=70)
144
+ s.gsub(/\s+/, ' ').gsub(/(.{1,#{width}})( |\Z)/, "\\1\n ")
145
+ end
146
+
147
+ def truncate_version_list(limit)
148
+ suffix = lib.versions.size >= limit ? '...' : ''
149
+ "(#{lib.versions.size} versions: #{lib.versions.reverse[0..limit].join(', ').blue}#{suffix})"
150
+ end
151
+ end
152
+ end
153
+ end
@@ -1,11 +1,14 @@
1
- require_relative 'installer'
1
+ require 'awesome_print'
2
2
  require 'arli/errors'
3
3
 
4
+ require_relative 'installer'
5
+ require_relative 'multi_version'
6
+
4
7
  module Arli
5
8
  module Library
6
9
  # Represents a wrapper around Arduino::Library::Model instance
7
10
  # and decorates with a few additional helpers.
8
- class Proxy
11
+ class SingleVersion
9
12
  attr_accessor :lib,
10
13
  :lib_dir,
11
14
  :canonical_dir,
@@ -49,23 +52,6 @@ module Arli
49
52
  Dir.exist?(path)
50
53
  end
51
54
 
52
- # Formats
53
- def to_s_short
54
- "#{lib.name.bold.blue} (#{lib.version.yellow}), by #{lib.author.magenta}"
55
- end
56
-
57
- def to_s_json
58
- puts lib.to_json
59
- end
60
-
61
- def to_s_long
62
- "#{lib.name.bold.blue} (#{lib.version.yellow}), by #{lib.author.magenta}}\n\t#{lib.description}"
63
- end
64
-
65
- def to_s_pretty(lib, **options)
66
- "#{lib.name.bold.blue} (#{lib.version.yellow}), by #{lib.author.magenta}"
67
- end
68
-
69
55
  def method_missing(method, *args, &block)
70
56
  if lib && lib.respond_to?(method)
71
57
  lib.send(method, *args, &block)
@@ -73,7 +59,6 @@ module Arli
73
59
  super(method, *args, &block)
74
60
  end
75
61
  end
76
-
77
62
  end
78
63
  end
79
64
  end
@@ -17,9 +17,9 @@ module Arli
17
17
 
18
18
  def initialize(config: Arli.config)
19
19
  self.config = config
20
- self.lock_file_path = "#{config.arlifile.path}/#{config.arlifile.lock_name}"
21
20
  self.format = config.arlifile.lock_format
22
21
  self.formatter = set_formatter(format)
22
+ self.lock_file_path = "#{config.arlifile.path}/#{config.arlifile.name}.#{formatter.extension}"
23
23
  self.file = ::File.open(lock_file_path, 'w')
24
24
 
25
25
  append(formatter.header)
@@ -41,7 +41,6 @@ module Arli
41
41
  append(formatter.footer)
42
42
  ensure
43
43
  file.close
44
- FileUtils.cp(lock_file_path, "#{lock_file_path}.#{format}")
45
44
  end
46
45
 
47
46
  def append(line = nil)
@@ -1,8 +1,12 @@
1
+ require 'arli/helpers/inherited'
1
2
 
2
3
  module Arli
3
4
  module Lock
4
5
  module Formats
5
6
  class Base
7
+ include Arli::Helpers::Inherited
8
+ attr_assignable :extension
9
+
6
10
  attr_accessor :lock_file
7
11
 
8
12
  def initialize(lock_file)
@@ -20,6 +24,10 @@ module Arli
20
24
  # Optional footer
21
25
  def footer
22
26
  end
27
+
28
+ def extension
29
+ self.class.extension
30
+ end
23
31
  end
24
32
  end
25
33
  end
@@ -4,19 +4,35 @@ module Arli
4
4
  module Lock
5
5
  module Formats
6
6
  class Cmake < Base
7
+ extension :cmake
8
+
9
+
10
+ attr_accessor :libs, :comments
7
11
 
8
12
  def header
9
- "# vi:syntax=cmake\n" +
10
- "set(ARLI_LIBRARIES)"
13
+ @comments = []
14
+ @libs = []
15
+ "# vi:syntax=cmake"
11
16
  end
12
17
 
13
18
  def format(library)
14
- "# Library #{library.name}, version #{library.version}, url: #{library.url}\n" +
15
- "prepend(ARDUINO_ARLI_LIBS ${ARDUINO_ARLI_LIBS} #{library.canonical_dir})"
19
+ @libs << library
20
+ @comments << "# Library #{library.name}:\n# version #{library.version}\n# url: #{library.url}"
21
+ nil
16
22
  end
17
23
 
18
24
  def footer
19
- "set(ARLI_LIBRARIES $ARLI_LIBRARIES PARENT_SCOPE)"
25
+ %Q[
26
+ # This file is auto-generated by Arli library manager.
27
+ # See https://github.com/kigster/arli for more info.
28
+
29
+ set(ARLI_LIBRARIES_PATH "#{Arli.config.libraries.path}")
30
+ set(ARLI_LIBRARIES #{@libs.map(&:canonical_dir).join(' ')})
31
+
32
+ set(ARLI_LIBRARIES $ARLI_LIBRARIES PARENT_SCOPE)
33
+
34
+ #{@comments.join("\n")}
35
+ ]
20
36
  end
21
37
  end
22
38
  end
@@ -4,6 +4,8 @@ module Arli
4
4
  module Lock
5
5
  module Formats
6
6
  class Json < Base
7
+ extension :json
8
+
7
9
  attr_accessor :hash
8
10
 
9
11
  def header
@@ -4,6 +4,8 @@ module Arli
4
4
  module Lock
5
5
  module Formats
6
6
  class Text < Base
7
+ extension :txt
8
+
7
9
  def format(library)
8
10
  "#{library.canonical_dir},#{library.version},#{library.path}"
9
11
  end
@@ -4,9 +4,11 @@ module Arli
4
4
  module Lock
5
5
  module Formats
6
6
  class Yaml < Json
7
+ extension :yml
8
+
7
9
  def footer
8
10
  "# vi:syntax=yaml\n" +
9
- YAML.dump(hash)
11
+ YAML.dump(unique_libraries)
10
12
  end
11
13
  end
12
14
  end
@@ -1,3 +1,3 @@
1
1
  module Arli
2
- VERSION = '0.8.3'.freeze
2
+ VERSION = '0.9.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Gredeskoul
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-04 00:00:00.000000000 Z
11
+ date: 2017-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: arduino-library
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: hashie
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -217,7 +231,6 @@ extensions: []
217
231
  extra_rdoc_files: []
218
232
  files:
219
233
  - ".gitignore"
220
- - ".rake_tasks~"
221
234
  - ".rspec"
222
235
  - ".travis.yml"
223
236
  - Gemfile
@@ -252,9 +265,12 @@ files:
252
265
  - lib/arli/configuration.rb
253
266
  - lib/arli/errors.rb
254
267
  - lib/arli/extensions.rb
268
+ - lib/arli/helpers/inherited.rb
269
+ - lib/arli/helpers/output.rb
255
270
  - lib/arli/library.rb
256
271
  - lib/arli/library/installer.rb
257
- - lib/arli/library/proxy.rb
272
+ - lib/arli/library/multi_version.rb
273
+ - lib/arli/library/single_version.rb
258
274
  - lib/arli/lock/file.rb
259
275
  - lib/arli/lock/formats.rb
260
276
  - lib/arli/lock/formats/base.rb
@@ -262,7 +278,6 @@ files:
262
278
  - lib/arli/lock/formats/json.rb
263
279
  - lib/arli/lock/formats/text.rb
264
280
  - lib/arli/lock/formats/yaml.rb
265
- - lib/arli/output.rb
266
281
  - lib/arli/version.rb
267
282
  homepage: https://github.com/kigster/arli
268
283
  licenses:
@@ -1,8 +0,0 @@
1
- build
2
- clean
3
- clobber
4
- doc
5
- install
6
- install:local
7
- release[remote]
8
- spec