mlvzk / manix

A fast CLI documentation searcher for Nix.
Mozilla Public License 2.0
337 stars 19 forks source link

Option to filter out results? #20

Closed gvolpe closed 3 years ago

gvolpe commented 3 years ago

Hi, thanks for working on this, it's awesome!

I was wondering if it would be possible to add a --source option (or something like that) so it can only search in a specific source (e.g. only search Home Manager options)?

For example, if I search for programs.chromium, I currently get this result:

❯ manix -s programs.chromium  

HomeManager Options
────────────────────
# programs.chromium.package
The Chromium package to use.
type: package

HomeManager Options
────────────────────
# programs.chromium.extensions
List of Chromium extensions to install.
To find the extension ID, check its URL on the
<link xlink:href="https://chrome.google.com/webstore/category/extensions">Chrome Web Store</link>.

type: list of strings

HomeManager Options
────────────────────
# programs.chromium.enable
Whether to enable Chromium.
type: boolean

NixOS Options
────────────────────
# programs.chromium.enable
Whether to enable <command>chromium</command> policies.
type: boolean

NixOS Options
────────────────────
# programs.chromium.defaultSearchProviderSuggestURL
Chromium default search provider url for suggestions.
type: null or string

NixOS Options
────────────────────
# programs.chromium.homepageLocation
Chromium default homepage
type: null or string

NixOS Options
────────────────────
# programs.chromium.extensions
List of chromium extensions to install.
For list of plugins ids see id in url of extensions on
<link xlink:href="https://chrome.google.com/webstore/category/extensions">chrome web store</link>
page. To install a chromium extension not included in the chrome web
store, append to the extension id a semicolon ";" followed by a URL
pointing to an Update Manifest XML file. See
<link xlink:href="https://www.chromium.org/administrators/policy-list-3#ExtensionInstallForcelist">ExtensionInstallForcelist</link>
for additional details.

type: list of strings

NixOS Options
────────────────────
# programs.chromium.extraOpts
Extra chromium policy options. A list of available policies
can be found in the Chrome Enterprise documentation:
<link xlink:href="https://cloud.google.com/docs/chrome-enterprise/policies/">https://cloud.google.com/docs/chrome-enterprise/policies/</link>
Make sure the selected policy is supported on Linux and your browser version.

type: attribute set

NixOS Options
────────────────────
# programs.chromium.defaultSearchProviderSearchURL
Chromium default search provider url.
type: null or string

When I'm only interested in seeing Home Manager options. I could filter the results out using grep or ripgrep but I think it would be more efficient to only search in the sources I'm interested in.

What do you think?

mlvzk commented 3 years ago

implemented in https://github.com/mlvzk/manix/commit/7e905be2c72ac0795ff8b5d919683f426186c057 Care to try before I tag release?

You can either compile it yourself with cargo build --release and running the binary in target/release/manix or you can use this binary.

Example usage: manix test --source=nixos_options,nixpkgs_doc

gvolpe commented 3 years ago

Works like a charm, thanks a lot!

❯ manix -s programs.chromium --source hm_options      
HomeManager Options
────────────────────
# programs.chromium.extensions
List of Chromium extensions to install.
To find the extension ID, check its URL on the
<link xlink:href="https://chrome.google.com/webstore/category/extensions">Chrome Web Store</link>.

type: list of strings

HomeManager Options
────────────────────
# programs.chromium.enable
Whether to enable Chromium.
type: boolean

HomeManager Options
────────────────────
# programs.chromium.package
The Chromium package to use.
type: package
elkowar commented 3 years ago

@mlvzk additionally, would a --list-sources flag make sense? otherwise, it might be non-obvious what the exact names of the different sources are. It could also be possible to check for source availability here, to allow any scripts that make use of manix to restrict themselves to the available sources (-> only show home-manager when home-manager is available, etc). With scripts i'm thinking about things like a rofi menu to search through manix, etc

gvolpe commented 3 years ago

@elkowar you can get that from --help.

❯ manix --help
manix 0.6.2

USAGE:
    manix [FLAGS] [OPTIONS] <QUERY>

FLAGS:
    -h, --help            Prints help information
    -s, --strict          Matches entries stricly
    -u, --update-cache    Force update cache
    -V, --version         Prints version information

OPTIONS:
        --source <source>...    Restrict search to chosen sources [default:
                                nixos_options,hm_options,nixpkgs_doc,nixpkgs_tree,nixpkgs_comments]  [possible values:
                                nixos_options, hm_options, nixpkgs_doc, nixpkgs_tree, nixpkgs_comments]

ARGS:
    <QUERY>    
elkowar commented 3 years ago

i guess, but that's not particularily parseable for scripts, which is why a --list-sources might still be nice. Of course this is more of a nice-to-have ;D