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

slither: implement shell completions with shtab #2317

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

elopez
Copy link
Member

@elopez elopez commented Feb 19, 2024

These can be generated by running e.g. slither --print-completion zsh and installed as usual.

Closes #2055

Copy link

coderabbitai bot commented Feb 19, 2024

Important

Auto Review Skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@elopez elopez force-pushed the dev-autocompletion branch 3 times, most recently from 591a63d to 5a3a2f8 Compare February 20, 2024 00:41
@elopez
Copy link
Member Author

elopez commented Feb 20, 2024

Sample Homebrew patch to generate and install these new completions (keep this in mind as well):

diff --git a/Formula/s/slither-analyzer.rb b/Formula/s/slither-analyzer.rb
index d8e1b9a97cb..6ac645f6c3d 100644
--- a/Formula/s/slither-analyzer.rb
+++ b/Formula/s/slither-analyzer.rb
@@ -7,7 +7,7 @@ class SlitherAnalyzer < Formula
   sha256 "d01ad88a7fc9581f717859c66d01ef1658ba49505c60e89d5cf38ce6a7f4cdff"
   license "AGPL-3.0-only"
   revision 1
-  head "https://github.com/crytic/slither.git", branch: "master"
+  head "https://github.com/crytic/slither.git", branch: "dev-autocompletion"
 
   bottle do
     rebuild 3
@@ -179,6 +179,11 @@ class SlitherAnalyzer < Formula
     sha256 "0210b2668f24c078307260bf88bdac9d6f1093635df5123789bfee4d8d7fc8e7"
   end
 
+  resource "shtab" do
+    url "https://files.pythonhosted.org/packages/14/0e/ce211daf7b28fe685b1c9a21d943b3a1c4f300a07e6c59d8765c5f22eb06/shtab-1.6.5.tar.gz"
+    sha256 "cf4ab120183e84cce041abeb6f620f9560739741dfc31dd466315550c08be9ec"
+  end
+
   resource "toolz" do
     url "https://files.pythonhosted.org/packages/3e/bf/5e12db234df984f6df3c7f12f1428aa680ba4e101f63f4b8b3f9e8d2e617/toolz-0.12.1.tar.gz"
     sha256 "ecca342664893f177a13dac0e6b41cbd8ac25a358e5f215316d43e2100224f4d"
@@ -223,6 +228,18 @@ class SlitherAnalyzer < Formula
     site_packages = Language::Python.site_packages("python3.12")
     paths = %w[crytic-compile solc-select].map { |p| Formula[p].opt_libexec/site_packages }
     (libexec/site_packages/"homebrew-deps.pth").write paths.join("\n")
+
+    bin.each_child do |tool|
+      # simil requires optional dependency
+      next if tool == bin/"slither-simil"
+
+      generate_completions_from_executable(
+        tool,
+        shell_parameter_format: "--print-completion=",
+        shells:                 [:bash, :zsh],
+        base_name:              tool.basename.to_s
+      )
+    end
   end
 
   test do

HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source --HEAD slither-analyzer

@0xalpharush
Copy link
Contributor

Is this ready to go?

@elopez
Copy link
Member Author

elopez commented Mar 29, 2024

@0xalpharush I think so! some more testing would be appreciated though

@montyly
Copy link
Member

montyly commented Oct 24, 2024

@elopez is this still a draft?

@elopez elopez marked this pull request as ready for review October 24, 2024 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants