summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/flags.rs52
-rw-r--r--cli/main.rs1
-rw-r--r--website/manual.md46
3 files changed, 83 insertions, 16 deletions
diff --git a/cli/flags.rs b/cli/flags.rs
index 99d78546b..f7444f8d1 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -1,7 +1,14 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
+use clap::App;
+use clap::AppSettings;
+use clap::Arg;
+use clap::ArgMatches;
+use clap::Shell;
+use clap::SubCommand;
use crate::deno_dir;
use log::Level;
+use std;
+use std::str::FromStr;
// Creates vector of strings, Vec<String>
macro_rules! svec {
@@ -300,7 +307,7 @@ ability to spawn subprocesses.
// this is a fake subcommand - it's used in conjunction with
// AppSettings:AllowExternalSubcommand to treat it as an
// entry point script
- SubCommand::with_name("<script>").about("Script to run"),
+ SubCommand::with_name("[SCRIPT]").about("Script to run"),
),
).subcommand(
SubCommand::with_name("xeval")
@@ -376,13 +383,31 @@ To change installation directory use -d/--dir flag
// this is a fake subcommand - it's used in conjunction with
// AppSettings:AllowExternalSubcommand to treat it as an
// entry point script
- SubCommand::with_name("<script>").about("Script URL"),
+ SubCommand::with_name("[SCRIPT]").about("Script URL"),
),
).subcommand(
+ SubCommand::with_name("completions")
+ .settings(&[
+ AppSettings::DisableHelpSubcommand,
+ AppSettings::DisableVersion,
+ ]).about("Generate shell completions")
+ .long_about(
+"Output shell completion script to standard output.
+
+Example:
+
+ deno completions bash > /usr/local/etc/bash_completion.d/deno.bash
+ source /usr/local/etc/bash_completion.d/deno.bash")
+ .arg(
+ Arg::with_name("shell")
+ .possible_values(&Shell::variants())
+ .required(true),
+ ),
+ ).subcommand(
// this is a fake subcommand - it's used in conjunction with
// AppSettings:AllowExternalSubcommand to treat it as an
// entry point script
- SubCommand::with_name("<script>").about("Script to run"),
+ SubCommand::with_name("[SCRIPT]").about("Script to run"),
)
}
@@ -537,6 +562,7 @@ const INSTALLER_URL: &str = "https://deno.land/std@b13441f/installer/mod.ts";
#[derive(Debug, PartialEq)]
pub enum DenoSubcommand {
Bundle,
+ Completions,
Eval,
Fetch,
Info,
@@ -590,6 +616,15 @@ pub fn flags_from_vec(
argv.extend(vec![source_file.to_string(), out_file.to_string()]);
DenoSubcommand::Bundle
}
+ ("completions", Some(completions_match)) => {
+ let shell: &str = completions_match.value_of("shell").unwrap();
+ create_cli_app().gen_completions_to(
+ "deno",
+ Shell::from_str(shell).unwrap(),
+ &mut std::io::stdout(),
+ );
+ DenoSubcommand::Completions
+ }
("eval", Some(eval_match)) => {
flags.allow_net = true;
flags.allow_env = true;
@@ -1392,4 +1427,13 @@ mod tests {
assert_eq!(subcommand, DenoSubcommand::Run);
assert_eq!(argv, svec!["deno", "script.ts"])
}
+
+ #[test]
+ fn test_flags_from_vec_32() {
+ let (flags, subcommand, argv) =
+ flags_from_vec(svec!["deno", "completions", "bash"]);
+ assert_eq!(flags, DenoFlags::default());
+ assert_eq!(subcommand, DenoSubcommand::Completions);
+ assert_eq!(argv, svec!["deno"])
+ }
}
diff --git a/cli/main.rs b/cli/main.rs
index 8121e5f7c..02409d750 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -346,6 +346,7 @@ fn main() {
match subcommand {
DenoSubcommand::Bundle => bundle_command(flags, argv),
+ DenoSubcommand::Completions => {}
DenoSubcommand::Eval => eval_command(flags, argv),
DenoSubcommand::Fetch => fetch_or_info_command(flags, argv, false),
DenoSubcommand::Info => fetch_or_info_command(flags, argv, true),
diff --git a/website/manual.md b/website/manual.md
index c2e1b99d5..58f13f426 100644
--- a/website/manual.md
+++ b/website/manual.md
@@ -618,18 +618,19 @@ OPTIONS:
--v8-flags=<v8-flags> Set V8 command line options
SUBCOMMANDS:
- <script> Script to run
- bundle Bundle module and dependencies into single file
- eval Eval script
- fetch Fetch the dependencies
- fmt Format files
- help Prints this message or the help of the given subcommand(s)
- info Show source file related info
- install Install script as executable
- run Run a program given a filename or url to the source code
- types Print runtime TypeScript declarations
- version Print the version
- xeval Eval a script on text segments from stdin
+ [SCRIPT] Script to run
+ bundle Bundle module and dependencies into single file
+ completions Generate shell completions
+ eval Eval script
+ fetch Fetch the dependencies
+ fmt Format files
+ help Prints this message or the help of the given subcommand(s)
+ info Show source file related info
+ install Install script as executable
+ run Run a program given a filename or url to the source code
+ types Print runtime TypeScript declarations
+ version Print the version
+ xeval Eval a script on text segments from stdin
ENVIRONMENT VARIABLES:
DENO_DIR Set deno's base directory
@@ -647,6 +648,27 @@ generated and cached source code is written and read to.
code can test if `NO_COLOR` was set without having `--allow-env` by using the
boolean constant `Deno.noColor`.
+### Shell completion
+
+You can generate completion script for your shell using the
+`deno completions <shell>` command. The command outputs to stdout so you should
+redirect it to an appropriate file.
+
+The supported shells are:
+
+- zsh
+- bash
+- fish
+- powershell
+- elvish
+
+Example:
+
+```shellsession
+deno completions bash > /usr/local/etc/bash_completion.d/deno.bash
+source /usr/local/etc/bash_completion.d/deno.bash
+```
+
### V8 flags
V8 has many many internal command-line flags, that you can see with