Skip to content

Commit

Permalink
Merge pull request #151 from main--/comp1337
Browse files Browse the repository at this point in the history
Bash completion for windows-gaming
  • Loading branch information
oberien authored Aug 6, 2017
2 parents 95688e0 + 3cdf385 commit 07c6c44
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
GA_EXE := guest-agent/VfioService.exe
GA_ISO := guest-agent/windows-gaming-ga.iso
OVMF := ovmf-x64/OVMF_CODE-pure-efi.fd ovmf-x64/OVMF_VARS-pure-efi.fd
BASH_COMPLETION := target/release/windows-gaming.bash-completion

all: cargo $(GA_ISO) $(OVMF)
all: cargo $(GA_ISO) $(OVMF) $(BASH_COMPLETION)

clippy:
rustup run nightly cargo clippy
Expand Down Expand Up @@ -32,6 +33,8 @@ ovmf-x64/OVMF_CODE-pure-efi%fd ovmf-x64/OVMF_VARS-pure-efi%fd: ovmf%rpm
guest-agent/VfioService/VfioService/Protocol.cs: windows-gaming/driver/clientpipe-proto/src/protocol.proto
protoc windows-gaming/driver/clientpipe-proto/src/protocol.proto --csharp_out=guest-agent/VfioService/VfioService/

$(BASH_COMPLETION): cargo
cd target/release/ && ./windows-gaming --generate-bash-completions > windows-gaming.bash-completion

clean:
$(RM) ovmf.rpm $(OVMF)
Expand All @@ -45,6 +48,7 @@ install: all
install -D target/release/windows-gaming $(DESTDIR)/usr/bin/windows-gaming
install -D target/release/windows-edge-grab $(DESTDIR)/usr/bin/windows-edge-grab
install -D -m4755 target/release/vfio-ubind $(DESTDIR)/usr/lib/windows-gaming/vfio-ubind
install -D -m644 $(BASH_COMPLETION) $(DESTDIR)/usr/share/bash-completion/completions/windows-gaming
install -D -m644 ovmf-x64/OVMF_CODE-pure-efi.fd $(DESTDIR)/usr/lib/windows-gaming/ovmf-code.fd
install -D -m644 ovmf-x64/OVMF_VARS-pure-efi.fd $(DESTDIR)/usr/lib/windows-gaming/ovmf-vars.fd
install -D -m644 $(GA_ISO) $(DESTDIR)/usr/lib/windows-gaming/windows-gaming-ga.iso
Expand Down
18 changes: 14 additions & 4 deletions windows-gaming/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ mod logger;

use std::path::Path;
use std::os::unix::net::UnixStream;
use std::io::Write;
use std::io::{self, Write};

use clap::{Arg, App, SubCommand, AppSettings, ArgGroup};
use clap::{Arg, App, SubCommand, AppSettings, ArgGroup, Shell};
use nix::unistd;

use common::config::Config;
Expand All @@ -29,7 +29,7 @@ const DATA_FOLDER: &'static str = "/usr/lib/windows-gaming";
fn main() {
logger::init().expect("Error initializing env_logger");

let matches = App::new(crate_name!())
let mut cli = App::new(crate_name!())
.version(crate_version!())
.about("Windows Gaming")
.setting(AppSettings::DeriveDisplayOrder)
Expand All @@ -42,6 +42,10 @@ fn main() {
.help("Config to use")
.takes_value(true)
.global(true)
).arg(Arg::with_name("generate-bash-completions")
.long("generate-bash-completions")
.hidden(true)
.takes_value(false)
).subcommand(SubCommand::with_name("run")
.about("Starts Windows")
.visible_alias("start")
Expand Down Expand Up @@ -76,7 +80,13 @@ fn main() {
).subcommand(SubCommand::with_name("suspend")
.about("Suspends Windows")
)
).get_matches();
);
let matches = cli.clone().get_matches();

if matches.is_present("generate-bash-completions") {
cli.gen_completions_to(crate_name!(), Shell::Bash, &mut io::stdout());
return;
}

let mode = if unistd::getuid() == 0 {
debug!("Running in system mode");
Expand Down

0 comments on commit 07c6c44

Please sign in to comment.