Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gemspec
group :runtime, :cli do
gem 'dry-cli', '~> 1.4' # for arg parsing
gem 'dry-cli-completion', '~> 2.0' # for shell completion
gem 'dry-types', '>= 1.9.1' # for arg casting
gem 'paint', '~> 2.3' # for colorized ouput
end

Expand Down
20 changes: 20 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PATH
ctf-party (~> 5.0)
dry-cli (~> 1.4)
dry-cli-completion (~> 2.0.0)
dry-types (>= 1.9.1)
paint (~> 2.3)
twitter_cldr (~> 6.13)
unicode-confusable (~> 1.13)
Expand Down Expand Up @@ -37,6 +38,23 @@ GEM
dry-cli-completion (2.0.0)
completely (~> 0.7)
dry-cli (~> 1.4)
dry-core (1.2.0)
concurrent-ruby (~> 1.0)
logger
zeitwerk (~> 2.6)
dry-inflector (1.3.1)
dry-logic (1.6.0)
bigdecimal
concurrent-ruby (~> 1.0)
dry-core (~> 1.1)
zeitwerk (~> 2.6)
dry-types (1.9.1)
bigdecimal (>= 3.0)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0)
dry-inflector (~> 1.0)
dry-logic (~> 1.4)
zeitwerk (~> 2.6)
erb (6.0.4)
io-console (0.8.2)
irb (1.18.0)
Expand Down Expand Up @@ -115,6 +133,7 @@ GEM
yard-coderay (0.1.0)
coderay
yard
zeitwerk (2.8.2)

PLATFORMS
x86_64-linux
Expand All @@ -126,6 +145,7 @@ DEPENDENCIES
ctf-party (~> 5.0)
dry-cli (~> 1.4)
dry-cli-completion (~> 2.0)
dry-types (>= 1.9.1)
irb
logger
minitest (~> 6.0)
Expand Down
8 changes: 4 additions & 4 deletions lib/unisec/cli/blocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ module Blocks
class List < Dry::CLI::Command
desc 'List all Unicode blocks'

option :with_count, default: 'false', values: %w[true false],
option :with_count, default: 'false', cast: Types::Params::Bool.default(false),
desc: "calculate block's range size & char count?"

# List Unicode blocks
def call(**options)
Unisec::Blocks.list_display(with_count: options[:with_count].to_bool)
Unisec::Blocks.list_display(with_count: options[:with_count])
end
end

Expand All @@ -49,14 +49,14 @@ class Search < Dry::CLI::Command
'(only one, so be careful with emojis, composed or joint characters using ' \
'several units) | block name (case insensitive)'

option :with_count, default: 'false', values: %w[true false],
option :with_count, default: 'false', cast: Types::Params::Bool.default(false),
desc: "calculate block's range size & char count?"

# Display a block matching a decimal code point, standardized hexadecimal codepoint, string character or block name
# @param block_arg [Integer|String] Decimal code point or standardized hexadecimal codepoint or string character (only one, so be careful with emojis, composed or joint characters using several units) or directly look for the block name (case insensitive).
def call(block_arg: nil, **options)
block_arg = block_arg.to_i if /\A\d+\Z/.match?(block_arg) # cast decimal string to integer
Unisec::Blocks.block_display(block_arg, with_count: options[:with_count].to_bool)
Unisec::Blocks.block_display(block_arg, with_count: options[:with_count])
end
end

Expand Down
5 changes: 2 additions & 3 deletions lib/unisec/cli/confusables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ class List < Dry::CLI::Command
desc 'List confusables characters for a given character'

argument :character, required: true, desc: 'Unicode code point (as string)'
option :map, default: true, values: %w[true false],
option :map, default: true, cast: Types::Params::Bool.default(true),
desc: 'Allows partial mapping, includes confusable where the given chart is a part of'

# List confusables characters for a given character
# @param character [String] the character to search confusables for
# @option options [Boolean] :map allows partial mapping, includes confusable where the given chart is a
# part of
def call(character: nil, **options)
to_bool = ->(str) { ['true', true].include?(str) }
Unisec::Confusables.list_display(character, map: to_bool.call(options.fetch(:map)))
Unisec::Confusables.list_display(character, map: options.fetch(:map))
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/unisec/cli/dump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ class Reverse < Dry::CLI::Command
option :enc, default: 'utf8', values: %w[utf8 utf16be utf16le utf32be utf32le],
desc: 'The target encoding in which to search.'

option :exact, default: 'true', values: %w[true false],
option :exact, default: 'true', cast: Types::Params::Bool.default(true),
desc: 'true (default) = exact search, false = "sub-string" search / the value is included ' \
'in the encoded value'

# Search X byte(s) hexadecimal value in Y encoding, basically which characters will give this resulting encoded value
# @param hexbytes [String] The target encoding in which to search.
def call(hexbytes: nil, **options)
hexbytes = $stdin.read.chomp if hexbytes == '-'
puts Unisec::Hexdump.display_reverse(hexbytes, options[:enc], exact: options[:exact].to_bool)
puts Unisec::Hexdump.display_reverse(hexbytes, options[:enc], exact: options[:exact])
end
end
end
Expand Down
20 changes: 10 additions & 10 deletions lib/unisec/cli/planes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ module Planes
class List < Dry::CLI::Command
desc 'List all Unicode planes'

option :with_blocks, default: 'false', values: %w[true false],
option :with_blocks, default: 'false', cast: Types::Params::Bool.default(false),
desc: 'display the blocks associated with each plane?'
option :with_count, default: 'false', values: %w[true false],
option :with_count, default: 'false', cast: Types::Params::Bool.default(false),
desc: "calculate block's range size & char count?"

# List Unicode blocks
def call(**options)
Unisec::Planes.list_display(with_blocks: options[:with_blocks].to_bool,
with_count: options[:with_count].to_bool)
Unisec::Planes.list_display(with_blocks: options[:with_blocks],
with_count: options[:with_count])
end
end

Expand Down Expand Up @@ -80,17 +80,17 @@ class Search < Dry::CLI::Command
argument :plane_arg, required: true,
desc: 'Name or number of the plane'

option :with_blocks, default: 'false', values: %w[true false],
desc: 'display the blocks associated with each plane?'
option :with_count, default: 'false', values: %w[true false],
desc: "calculate block's range size & char count?"
option :with_blocks, default: 'false',
desc: 'display the blocks associated with each plane?', cast: Types::Params::Bool.default(false)
option :with_count, default: 'false',
desc: "calculate block's range size & char count?", cast: Types::Params::Bool.default(false)

# Display a plane matching a plane name or plane number
# @param plane_arg [String|Integer] name or number of the plane
def call(plane_arg: nil, **options)
plane_arg = plane_arg.to_i if /\A\d+\Z/.match?(plane_arg) # cast decimal string to integer
Unisec::Planes.plane_display(plane_arg, with_blocks: options[:with_blocks].to_bool,
with_count: options[:with_count].to_bool)
Unisec::Planes.plane_display(plane_arg, with_blocks: options[:with_blocks],
with_count: options[:with_count])
end
end
end
Expand Down
8 changes: 5 additions & 3 deletions lib/unisec/cli/properties.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# frozen_string_literal: true

require 'dry/cli'
require 'dry-types'
require 'unisec'
require 'unisec/utils'

Types = Dry.Types()

module Unisec
module CLI
module Commands
Expand Down Expand Up @@ -68,14 +71,13 @@ class Char < Dry::CLI::Command
desc 'Returns all properties of a given Unicode character (code point as string)'

argument :character, required: true, desc: 'Unicode character'
option :extended, default: false, values: %w[true false], desc: 'Show all properties'
option :extended, default: false, desc: 'Show all properties', cast: Types::Params::Bool.default(false)

# Returns all properties of a given Unicode character (code point as string)
# @param character [String] Unicode code point (as character / string)
# @option options [Boolean] :extended Show all properties
def call(character: nil, **options)
to_bool = ->(str) { str == 'true' }
Unisec::Properties.char_display(character, extended: to_bool.call(options.fetch(:extended)))
Unisec::Properties.char_display(character, extended: options.fetch(:extended))
end
end
end
Expand Down
1 change: 1 addition & 0 deletions unisec.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency('ctf-party', '~> 5.0') # string conversion
s.add_runtime_dependency('dry-cli', '~> 1.4') # CLI
s.add_runtime_dependency('dry-cli-completion', '~> 2.0.0') # shell completion
s.add_runtime_dependency('dry-types', '>= 1.9.1') # CLI
s.add_runtime_dependency('paint', '~> 2.3') # colorized output
s.add_runtime_dependency('twitter_cldr', '~> 6.13') # ICU / CLDR
s.add_runtime_dependency('unicode-confusable', '~> 1.13') # confusable chars
Expand Down
Loading