Repository: clap-rs/clap (rust)

Issue:
global_setting(AppSettings::DisableVersion) does not disable autocomplete for subcommands.
### Make sure you completed the following tasks

- [x] Searched the [discussions](https://github.com/clap-rs/clap/discussions)
- [x] Searched the closed issues

### Code
This is a modification of the `bash_completion.rs` example in the `clap_generate` workspace.

```rust
use clap::{App, AppSettings};
use clap_generate::{generate, generators::Bash};
use std::io;

fn main() {
    let mut app = App::new("myapp")
        .global_setting(AppSettings::DisableVersion)
        .subcommand(App::new("test").subcommand(App::new("config")))
        .subcommand(App::new("hello"));

    generate::<Bash, _>(&mut app, "myapp", &mut io::stdout());
}
```

### Steps to reproduce the issue

1. Run `cargo run --example bash_completion` (with above modifications)
2. Observe that there are auto-completion options for `-V --version` in the sub-commands, despite not being valid commands.

```bash
        myapp__test)
            opts=" -h -V  --help --version  config"  # <----- -V and --version should not be here
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
```

### Version

* **Rust**: rustc 1.45.2 (d3fb005a3 2020-07-31)
* **Clap**:  `8454136126b48bd69d9218e19680082cc28fa5ef` (master)

### Actual Behavior Summary

When I disable version globally it disables `-V` and `--version` for subcommands; but these are still auto-completion options for subcommands, and I do not think there should be.

### Expected Behavior Summary

I think that using `AppSettings::DisableVersion` as a `global_setting` should also disable the autocomplete for subcommands.

### Debug output

```
[            clap::build::app]  App::_build
[            clap::build::app]  App::_derive_display_order:myapp
[            clap::build::app]  App::_derive_display_order:test
[            clap::build::app]  App::_derive_display_order:config
[            clap::build::app]  App::_derive_display_order:hello
[            clap::build::app]  App::_create_help_and_version
[            clap::build::app]  App::_create_help_and_version: Building --help
[            clap::build::app]  App::_create_help_and_version: Building help
[clap::build::app::debug_asserts]       App::_debug_asserts
[            clap::build::arg]  Arg::_debug_asserts:help
[            clap::build::app]  App::_build_bin_names
[            clap::build::app]  App::_build_bin_names:iter: bin_name set...
[            clap::build::app]  No
[            clap::build::app]  App::_build_bin_names:iter: Setting bin_name of myapp to myapp test
[            clap::build::app]  App::_build_bin_names:iter: Calling build_bin_names from...test
[            clap::build::app]  App::_build_bin_names
[            clap::build::app]  App::_build_bin_names:iter: bin_name set...
[            clap::build::app]  No
[            clap::build::app]  App::_build_bin_names:iter: Setting bin_name of test to myapp test config
[            clap::build::app]  App::_build_bin_names:iter: Calling build_bin_names from...config
[            clap::build::app]  App::_build_bin_names
[            clap::build::app]  App::_build_bin_names:iter: bin_name set...
[            clap::build::app]  No
[            clap::build::app]  App::_build_bin_names:iter: Setting bin_name of myapp to myapp hello
[            clap::build::app]  App::_build_bin_names:iter: Calling build_bin_names from...hello
[            clap::build::app]  App::_build_bin_names
[            clap::build::app]  App::_build_bin_names:iter: bin_name set...
[            clap::build::app]  No
[            clap::build::app]  App::_build_bin_names:iter: Setting bin_name of myapp to myapp help
[            clap::build::app]  App::_build_bin_names:iter: Calling build_bin_names from...help
[            clap::build::app]  App::_build_bin_names
```


Pull request:
Fix propagation
<!--
If your PR closes some issues, please write `Closes #XXXX`
where `XXXX` is the number of the issue you want to fix.
Each issue goes on its own line.
-->
Closes #2090 

Patch:
diff --git a/src/build/app/mod.rs b/src/build/app/mod.rs
index 0216a0e8..e45f582d 100644
--- a/src/build/app/mod.rs
+++ b/src/build/app/mod.rs
@@ -2139,6 +2139,8 @@ impl<'help> App<'help> {
         // Make sure all the globally set flags apply to us as well
         self.settings = self.settings | self.g_settings;
 
+        self._propagate(Propagation::Full);
+
         self._derive_display_order();
         self._create_help_and_version();
 
@@ -2242,8 +2244,11 @@ impl<'help> App<'help> {
                     $sc.max_w = $_self.max_w;
                 }
                 {
+                    // FIXME: This doesn't belong here at all.
                     for a in $_self.args.args.iter().filter(|a| a.global) {
-                        $sc.args.push(a.clone());
+                        if $sc.find(&a.id).is_none() {
+                            $sc.args.push(a.clone());
+                        }
                     }
                 }
             }};
diff --git a/src/build/arg/mod.rs b/src/build/arg/mod.rs
index 59b2e2b6..50c0cc98 100644
--- a/src/build/arg/mod.rs
+++ b/src/build/arg/mod.rs
@@ -2210,9 +2210,9 @@ impl<'help> Arg<'help> {
     /// different. `Arg::default_value` *only* takes affect when the user has not provided this arg
     /// at runtime. `Arg::default_value_if` however only takes effect when the user has not provided
     /// a value at runtime **and** these other conditions are met as well. If you have set
-    /// `Arg::default_value` and `Arg::default_value_if`, and the user **did not** provide this arg
-    /// at runtime, nor were the conditions met for `Arg::default_value_if`, the `Arg::default_value`
-    /// will be applied.
+    /// `Arg::default_value` and `Arg::default_value_if`, and the user **did not** provide a this
+    /// arg at runtime, nor did were the conditions met for `Arg::default_value_if`, the
+    /// `Arg::default_value` will be applied.
     ///
     /// **NOTE:** This implicitly sets [`Arg::takes_value(true)`].
     ///
@@ -2403,8 +2403,9 @@ impl<'help> Arg<'help> {
     /// different. `Arg::default_value` *only* takes affect when the user has not provided this arg
     /// at runtime. This setting however only takes affect when the user has not provided a value at
     /// runtime **and** these other conditions are met as well. If you have set `Arg::default_value`
-    /// and `Arg::default_value_if`, and the user **did not** provide this arg at runtime, nor were
-    /// the conditions met for `Arg::default_value_if`, the `Arg::default_value` will be applied.
+    /// and `Arg::default_value_if`, and the user **did not** provide a this arg at runtime, nor did
+    /// were the conditions met for `Arg::default_value_if`, the `Arg::default_value` will be
+    /// applied.
     ///
     /// **NOTE:** This implicitly sets [`Arg::takes_value(true)`].
     ///


Test patch:
diff --git a/src/build/app/tests.rs b/src/build/app/tests.rs
index bdf21114..2f9aaa25 100644
--- a/src/build/app/tests.rs
+++ b/src/build/app/tests.rs
@@ -51,3 +51,13 @@ fn app_send_sync() {
     fn foo<T: Send + Sync>(_: T) {}
     foo(App::new("test"))
 }
+
+#[test]
+fn issue_2090() {
+    let mut app = App::new("app")
+        .global_setting(AppSettings::DisableVersion)
+        .subcommand(App::new("sub"));
+    app._build();
+
+    assert!(app.subcommands[0].is_set(AppSettings::DisableVersion));
+}