Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to transpose the matrix #36

Merged
merged 1 commit into from
May 7, 2024
Merged
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
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 @@
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