Class: Rubion::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/rubion.rb

Class Method Summary collapse

Class Method Details

.parse_scan_options(args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rubion.rb', line 30

def self.parse_scan_options(args)
  # Default to sorting by "Behind By(Time)" in descending order
  options = {
    gems: true,
    packages: true,
    sort_by: 'Behind By(Time)',
    sort_desc: true,
    exclude_dependencies: false,
    vulnerabilities_only: false
  }

  # Check for --gems-only or --packages-only flags
  if args.include?('--gems-only') || args.include?('-g')
    options[:gems] = true
    options[:packages] = false
  elsif args.include?('--packages-only') || args.include?('-p')
    options[:gems] = false
    options[:packages] = true
  elsif args.include?('--gems') || args.include?('--packages')
    # Legacy support for --gems and --packages
    options[:gems] = args.include?('--gems')
    options[:packages] = args.include?('--packages')
  end

  # Parse --sort-by or -s option
  sort_index = args.index('--sort-by') || args.index('-s')
  options[:sort_by] = args[sort_index + 1] if sort_index && args[sort_index + 1]

  # Parse --asc/--ascending or --desc/--descending for sort order
  if args.include?('--asc') || args.include?('--ascending')
    options[:sort_desc] = false
  elsif args.include?('--desc') || args.include?('--descending')
    options[:sort_desc] = true
  end

  # Parse --exclude-dependencies flag
  options[:exclude_dependencies] = true if args.include?('--exclude-dependencies')

  # Parse --vulnerabilities-only flag
  options[:vulnerabilities_only] = true if args.include?('--vulnerabilities-only') || args.include?('--vulns-only')

  options
end


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/rubion.rb', line 94

def self.print_help
  puts <<~HELP

    🔒 Rubion - Security & Version Scanner for Ruby and JavaScript projects

    USAGE:
      rubion scan [OPTIONS]       Scan current project for vulnerabilities and outdated versions
      rubion version              Display Rubion version
      rubion help                 Display this help message

    SCAN OPTIONS:
      --gems, --gem, -g               Scan only Ruby gems (skip NPM packages)
      --packages, --npm, -p           Scan only NPM packages (skip Ruby gems)
      --all, -a                       Scan both gems and packages (default)
      --sort-by COLUMN, -s COLUMN     Sort results by column (Name, Current, Date, Latest, Behind By(Time), Behind By(Versions))
                                     (default: "Behind By(Time)" in descending order)
      --asc, --ascending              Sort in ascending order (use with --sort-by)
      --desc, --descending            Sort in descending order (use with --sort-by, default)
      --exclude-dependencies          Show only direct dependencies (from Gemfile/package.json)
      --vulnerabilities-only          Show only vulnerability tables (hide version/outdated sections)

    DESCRIPTION:
      Rubion scans your project for:
        - Ruby gem vulnerabilities (using bundler-audit)
        - Outdated Ruby gems (using bundle outdated)
        - NPM/JavaScript package vulnerabilities (using npm audit or yarn audit)
        - Outdated NPM/JavaScript packages (using npm outdated or yarn outdated)

    OUTPUT:
      Results are displayed in organized tables with:
        📛 Vulnerabilities with severity icons (🔴 Critical, 🟠 High, 🟡 Medium, 🟢 Low)
        📦 Version information with release dates
        ⏱️  Time difference ("Behind By" column)
        🔢 Version count between current and latest

    EXAMPLES:
      # Scan both gems and packages (default)
      rubion scan
    #{'  '}
      # Scan only Ruby gems
      rubion scan --gems
    #{'  '}
      # Scan only NPM packages
      rubion scan --packages
    #{'  '}
      # Sort by name
      rubion scan --sort-by Name
    #{'  '}
      # Sort by versions behind
      rubion scan -s "Behind By(Versions)"
    #{'  '}
      # Sort by name in descending order (default)
      rubion scan --sort-by Name
    #{'  '}
      # Sort by name in ascending order
      rubion scan --sort-by Name --asc
    #{'  '}
      # Sort by name in descending order
      rubion scan --sort-by Name --desc
    #{'  '}
      # Show only direct dependencies
      rubion scan --exclude-dependencies
    #{'  '}
      # Show only vulnerabilities (no version/outdated tables)
      rubion scan --vulnerabilities-only
    #{'  '}
      # Get help
      rubion help

    REQUIREMENTS:
      - Ruby 2.6+
      - Bundler (for gem scanning)
      - NPM or Yarn (for package scanning, optional)
      - bundler-audit (optional, install with: gem install bundler-audit)
    #{'  '}
    NOTE:
      If both npm and yarn are available, you will be prompted to choose which one to use.

  HELP
end

.scan(options = { gems: true, packages: true, sort_by: 'Behind By(Time)', sort_desc: true, exclude_dependencies: false }) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rubion.rb', line 74

def self.scan(options = { gems: true, packages: true, sort_by: 'Behind By(Time)', sort_desc: true,
                          exclude_dependencies: false })
  project_path = Dir.pwd

  scanner = Scanner.new(project_path: project_path, vulnerabilities_only: options[:vulnerabilities_only])
  result = scanner.scan_incremental(options)

  # Results are already printed incrementally based on options
  # Package results are printed in scan_incremental, but we need to ensure
  # they use the same reporter instance with sort_by
  # Actually, scan_incremental handles gem printing, but package printing
  # happens here, so we need a reporter for packages
  return unless options[:packages]

  reporter = Reporter.new(result, sort_by: options[:sort_by], sort_desc: options[:sort_desc],
                                  exclude_dependencies: options[:exclude_dependencies])
  reporter.print_package_vulnerabilities
  reporter.print_package_versions unless options[:vulnerabilities_only]
end

.start(args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rubion.rb', line 11

def self.start(args)
  command = args[0]

  case command
  when 'scan'
    # Parse options
    options = parse_scan_options(args[1..-1])
    scan(options)
  when 'version', '-v', '--version'
    puts "Rubion version #{VERSION}"
  when 'help', '-h', '--help', nil
    print_help
  else
    puts "Unknown command: #{command}"
    print_help
    exit 1
  end
end