Skip to content

Commit

Permalink
Add a way to transpose the matrix
Browse files Browse the repository at this point in the history
```
./bin/hellgrid -r -t
         x        | diff-lcs | rspec | rspec-core | rspec-expectations | rspec-mocks |  rake  | rspec-support | hellgrid
------------------+----------+-------+------------+--------------------+-------------+--------+---------------+----------
         hellgrid |  1.5.1   | 3.8.0 |   3.8.2    |       3.8.6        |    3.8.2    |   x    |     3.8.3     |  0.4.0
     spec/tmp/bar |  1.2.5   | 2.0.0 |   2.0.0    |       2.0.0        |    2.0.0    | 10.0.0 |       x       |    x
  spec/tmp/in/foo |  1.2.5   | 3.0.0 |   3.0.4    |       3.0.4        |    3.0.4    | 11.1.0 |     3.0.4     |    x
```
  • Loading branch information
bliof-fc committed Apr 26, 2024
1 parent ed929b1 commit 5e04ed4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ gem install hellgrid
Let say that you have a directory `/path/to/root/dir` somewhere in which the Ruby projects `foo` and `bar` could be found.

Executing:

```bash
hellgrid /path/to/root/dir
```

To search recursively (should you have nested projects), use the `-r ` flag:
```

```bash
hellgrid -r /path/to/root/dir
```

Expand All @@ -35,7 +37,21 @@ Should result in:
rspec-mocks | 2.0.0 | 3.0.4
rake | 10.0.0 | 11.1.0
rspec-support | x | 3.0.4
hellgrid | x | x
```

To have the gems as columns, use the `-t` flag:

```bash
hellgrid -t /path/to/root/dir
```

Should result in:

```bash
x | diff-lcs | rake | rspec | rspec-core | rspec-expectations | rspec-mocks | rspec-support
--------+----------+--------+-------+------------+--------------------+-------------+---------------
bar | 1.2.5 | 10.0.0 | 2.0.0 | 2.0.0 | 2.0.0 | 2.0.0 | x
foo | 1.2.5 | 11.1.0 | 3.0.0 | 3.0.4 | 3.0.4 | 3.0.4 | 3.0.4
```

## License
Expand Down
7 changes: 6 additions & 1 deletion lib/hellgrid/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def initialize(argv = ARGV)

def start
recursive_search = !!(argv.delete('-r'))
transpose = !!(argv.delete('-t'))

folders = argv.empty? ? [Dir.pwd] : argv

folders.each do |folder|
Expand All @@ -24,7 +26,10 @@ def start
end
end

view = Hellgrid::Views::Console.new(matrix.sorted_by_most_used)
data = matrix.sorted_by_most_used
data = data.transpose if transpose

view = Hellgrid::Views::Console.new(data)

view.render
end
Expand Down
2 changes: 1 addition & 1 deletion lib/hellgrid/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Hellgrid
VERSION = '0.4.0'
VERSION = '0.5.0'
end
15 changes: 15 additions & 0 deletions spec/hellgrid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,19 @@ def with_unbundled_env(&block)
end
end
end

context 'when passing -t' do
it 'transposes the result and the project names on the left' do
expected_result = <<-TABLE
x | diff-lcs | rake | rspec | rspec-core | rspec-expectations | rspec-mocks | rspec-support
--------+----------+--------+-------+------------+--------------------+-------------+---------------
bar | 1.2.5 | 10.0.0 | 2.0.0 | 2.0.0 | 2.0.0 | 2.0.0 | x
in/foo | 1.2.5 | 11.1.0 | 3.0.0 | 3.0.4 | 3.0.4 | 3.0.4 | 3.0.4
TABLE

with_unbundled_env do
expect(`cd #{PROJECT_ROOT}/spec/tmp && #{PROJECT_ROOT}/bin/hellgrid -t`).to eq(expected_result)

Check failure on line 146 in spec/hellgrid_spec.rb

View check run for this annotation

Funding Circle Checks / fc-checks/coberos

ruby.lang.security.dangerous-subshell.dangerous-subshell

Detected non-static command inside `...`. If unverified user data can reach this call site, this is a code injection vulnerability. A malicious actor can inject a malicious script to execute arbitrary code.
Raw output
Fingerprint: cfe59e475c1a35e0a708b0ec8b9be93fa53eeeefb78c5020adb1ed70326a02bd
Category: CWE-94 Improper Control of Generation of Code ('Code Injection')
end
end
end
end

0 comments on commit 5e04ed4

Please sign in to comment.