cql_ruby 0.0.2 → 0.0.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cql_ruby +88 -0
  3. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6255a37c5d7ad3bb69be36d10bf4056eb8b40729a5989db72ecdc81e30a2784a
4
- data.tar.gz: e60a47023bf3062f83157f1d414dfc8122c58df9a4c6898f6048ac91727accea
3
+ metadata.gz: 5ff996bf0e61aa22dd53f9eaf9768f1d2748ccf56a35bf4fb4cc2d65ed1d1e08
4
+ data.tar.gz: fbe683ebe25ab5f2a93a42c1f182ec665852536bf3deca9315ba6bf8084e9b24
5
5
  SHA512:
6
- metadata.gz: 773f82e313c1ce9ad9a3c7f24d243d7045d7ad731d508ec082a5b8f3dce7a0d13078a9f21a0930bd535b2d3b530d801ee534eabcfa70ab44eada8af01b6adc65
7
- data.tar.gz: 9dbca8f1684162d99e81a8729cd1544fae6fc32bb7a327e184fa47b44939892a97940dc11e8880bfe99eac7e9d6793a235bfd0e0cae78b3053bc2ad5bf2c286e
6
+ metadata.gz: c1f7f6577eb7117f8f58057f880dd3dad25caf528a32251114aae9fb922583dcd2b6407b4ab782a4419dd040b04c47b5869fb4e49d0e5923c4ce55ae97c7f6ab
7
+ data.tar.gz: 58aca7b1d4323135126fd78c2b6b21df2cdd3b6ae6bdc06f211e75589349c2d286460bcf46f41211024e6bb0d07f4fe68b8364ad1a562ac9a697bdb3cf1ea16b
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cql_ruby'
4
+
5
+ def show_help
6
+ puts <<~HELP
7
+
8
+ \tSYNOPSIS
9
+ \tcql_ruby options pattern path filters ...
10
+
11
+ \tDESCRIPTION
12
+ \tCQL (Code Query Language) is a semantic search tool for your Ruby source code.
13
+
14
+ \tFILTERS
15
+ \t\tParent node type: type:T(,T)*
16
+
17
+ \tOPTIONS
18
+ \t\t-nc (--no-color) No color on output.
19
+ \t\t-nf (--no-file) No file names.
20
+ \t\t-ns (--no-source) No source code.
21
+
22
+ \tEXAMPLES
23
+ \tcql_ruby -ns update_user_info ./ type:send,arg
24
+ HELP
25
+
26
+ exit
27
+ end
28
+
29
+ # @return [Hash{Symbol->Boolean}]
30
+ def extract_options
31
+ options = {
32
+ show_color: true,
33
+ show_file: true,
34
+ show_source: true,
35
+ }
36
+
37
+ ARGV.delete_if do |arg|
38
+ if arg[0] == '-'
39
+ if %w[-nc --no-color].include?(arg)
40
+ options[:show_color] = false
41
+ elsif %w[-nf --no-file].include?(arg)
42
+ options[:show_file] = false
43
+ elsif %w[-ns --no-source].include?(arg)
44
+ options[:show_source] = false
45
+ elsif %w[-h --help]
46
+ show_help
47
+ else
48
+ raise "Unknown arg #{arg}"
49
+ end
50
+
51
+ true
52
+ else
53
+ false
54
+ end
55
+ end
56
+
57
+ options
58
+ end
59
+
60
+ # @return [Array]
61
+ def extract_filters
62
+ ARGV.take(ARGV.size)
63
+ end
64
+
65
+ begin
66
+ options = extract_options
67
+
68
+ raise unless ARGV.size >= 2
69
+
70
+ pattern = ARGV.shift
71
+ # TODO Make path patterns universal.
72
+ path = ARGV.shift
73
+
74
+ # Rest must be filters - can sink ARGV now.
75
+ filters = extract_filters
76
+ filter_reader = CqlRuby::FilterReader.new(filters)
77
+
78
+ printer = CqlRuby::ConsolePrinter.new
79
+ printer.color_on = options[:show_color]
80
+ printer.file_on = options[:show_file]
81
+ printer.source_on = options[:show_source]
82
+
83
+ collector = CqlRuby::CrumbCollector.new(printer)
84
+ CqlRuby::Executor.new(collector, filter_reader, pattern, path, filters).search_all
85
+ rescue => e
86
+ puts "Error: #{e}"
87
+ show_help
88
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cql_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - itarato
@@ -12,10 +12,12 @@ date: 2020-07-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: it.arato@gmail.com
15
- executables: []
15
+ executables:
16
+ - cql_ruby
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
20
+ - bin/cql_ruby
19
21
  - lib/cql_ruby.rb
20
22
  - lib/cql_ruby/abstract_printer.rb
21
23
  - lib/cql_ruby/console_printer.rb