Refactor CLI handling (#1368)

* Rework cli handling

* Update readme

* Adds support for custom subcommands and extra run parameters

* Update readme

* Fixes compilation after master merge

* Make "Run" the default subcommand

Actually its hidden to the outside that is an subcommand.

* Rewrite CLI to work without breaking old CLI behavior

* Some cleanup

* Fix incorrect config setup

* Update README

* Fixes after merge

* Fixes incorrect README
This commit is contained in:
Bastian Köcher
2019-01-25 11:48:46 +01:00
committed by Gav Wood
parent 375e01e6b1
commit 27a882bfac
13 changed files with 814 additions and 575 deletions
+16 -24
View File
@@ -14,16 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
extern crate clap;
extern crate substrate_cli as cli;
extern crate structopt;
use std::fs;
use std::env;
use clap::Shell;
use std::path::Path;
use cli::{NoCustom, CoreParams};
include!("src/params.rs");
use std::{fs, env, path::Path};
use structopt::{StructOpt, clap::Shell};
fn main() {
build_shell_completion();
@@ -32,30 +30,24 @@ fn main() {
/// Build shell completion scripts for all known shells
/// Full list in https://github.com/kbknapp/clap-rs/blob/e9d0562a1dc5dfe731ed7c767e6cee0af08f0cf9/src/app/parser.rs#L123
fn build_shell_completion() {
let shells = [Shell::Bash, Shell::Fish, Shell::Zsh, Shell::Elvish, Shell::PowerShell];
for shell in shells.iter() {
build_completion(shell);
for shell in &[Shell::Bash, Shell::Fish, Shell::Zsh, Shell::Elvish, Shell::PowerShell] {
build_completion(shell);
}
}
/// Build the shell auto-completion for a given Shell
fn build_completion(shell: &Shell) {
let outdir = match env::var_os("OUT_DIR") {
None => return,
Some(dir) => dir,
};
let path = Path::new(&outdir)
.parent().unwrap()
.parent().unwrap()
.parent().unwrap()
.join("completion-scripts");
None => return,
Some(dir) => dir,
};
let path = Path::new(&outdir)
.parent().unwrap()
.parent().unwrap()
.parent().unwrap()
.join("completion-scripts");
fs::create_dir(&path).ok();
fs::create_dir(&path).ok();
let mut app = Params::clap();
app.gen_completions(
"substrate-node",
*shell,
&path);
CoreParams::<NoCustom, NoCustom>::clap().gen_completions("substrate-node", *shell, &path);
}