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 shell completion for flamegraph #153

Merged
merged 1 commit into from
Sep 6, 2021

Conversation

ede1998
Copy link
Contributor

@ede1998 ede1998 commented Sep 3, 2021

About

This PR adds shell auto-completion support for the flamegraph binary. flamegraph --completions <shell> prints the completion script for the given shell to stdout. Currently supported shells are bash, fish, powershell andelvish (and zsh but it does not work).

Internally, claps completion generation is used.

Known issues/limitations:

Completions must be installed manually.

cargo install does not support installing extra files right now if claps documentation is to be believed. This means we cannot place a completion script into a completion directory for the user on install and would have to provide a distribution package (deb, rpm, ...) for this.

No completions for cargo flamegraph.

As far as I know, there is no official way to get completions for custom cargo subcommands. I tried getting it to work anyway without success. The issue is that you have to provide a binary name for which the completions will be generated. cargo-flamegraph sort of works for this if you invoke it directly but does not work at all when using cargo flamegraph as a custom subcommand. cargo as the binary name seems to be working great for cargo flamegraph. However it overrides existing completions so that you lose completions for cargo build etc.

Invoking flamegraph --completions zsh panics.

I didn't look into this. clap panics:

thread 'main' panicked at 'Fatal internal error. Please consider filing a bug report at https://github.com/clap-rs/clap/issues', ~/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.33.3/src/completions/zsh.rs:346:29
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/panicking.rs:92:14
   2: core::option::expect_failed
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/option.rs:1243:5
   3: core::option::Option<T>::expect
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/option.rs:351:21
   4: clap::completions::zsh::write_opts_of
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.33.3/src/completions/zsh.rs:346:29
   5: clap::completions::zsh::get_args_of
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.33.3/src/completions/zsh.rs:284:16
   6: clap::completions::zsh::ZshGen::generate_to
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.33.3/src/completions/zsh.rs:56:32
   7: clap::completions::ComplGen::generate
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.33.3/src/completions/mod.rs:38:27
   8: clap::app::parser::Parser::gen_completions_to
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.33.3/src/app/parser.rs:121:9
   9: clap::app::App::gen_completions_to
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.33.3/src/app/mod.rs:1442:9
  10: flamegraph::main

Copy link
Contributor

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

src/bin/flamegraph.rs Show resolved Hide resolved
src/bin/flamegraph.rs Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@djc djc merged commit 0872b7c into flamegraph-rs:main Sep 6, 2021
@djc
Copy link
Contributor

djc commented Sep 6, 2021

I added some conflict handling in f5a1b9c. Doesn't need to be with all the options, just the ones that allow specifying a workload.

@ede1998 ede1998 deleted the shell-completions branch September 6, 2021 08:42
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.

2 participants