Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tabs example work on Windows and upgrade to StructOpt #4859

Merged
merged 2 commits into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion examples/tabs-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ license = "MPL-2.0"
edition = "2021"
publish = false

[features]
default = ["with-clipboard"]

# The `clipboard` module we use appears to want to link against X11, which
# is a problem in some cases (notably, Windows/WSL)
# Running this example with, eg, `--no-default-features` will avoid using that module,
# but disable certain functionality.
with-clipboard = []

[[example]]
name = "tabs-sync"
path = "src/tabs-sync.rs"
Expand All @@ -16,6 +25,6 @@ serde_json = "1"
log = "0.4"
anyhow = "1.0"
clipboard = "0.5"
clap = "2.33"
structopt = "0.3"
cli-support = { path = "../cli-support" }
viaduct-reqwest = { path = "../../components/support/viaduct-reqwest" }
44 changes: 26 additions & 18 deletions examples/tabs-sync/src/tabs-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,32 @@

use cli_support::fxa_creds::{get_cli_fxa, get_default_fxa_config};
use cli_support::prompt::prompt_char;
use clipboard::{ClipboardContext, ClipboardProvider};
use std::sync::Arc;
use structopt::StructOpt;
use tabs::{RemoteTab, TabsStore};

use anyhow::Result;

#[derive(Clone, Debug, StructOpt)]
#[structopt(name = "tabs_sync", about = "CLI for Sync tabs store")]
pub struct Opts {
#[structopt(
name = "credential_file",
value_name = "CREDENTIAL_JSON",
long = "credentials",
short = "c",
default_value = "./credentials.json"
)]
/// Path to credentials.json.
pub creds_file: String,
}

fn main() -> Result<()> {
viaduct_reqwest::use_reqwest_backend();
cli_support::init_logging();
let matches = clap::App::new("tabs_sync")
.about("CLI for Sync tabs store")
.arg(
clap::Arg::with_name("credential_file")
.short("c")
.long("credentials")
.value_name("CREDENTIAL_JSON")
.takes_value(true)
.help(
"Path to store our cached fxa credentials (defaults to \"./credentials.json\"",
),
)
.get_matches();
let cred_file = matches
.value_of("credential_file")
.unwrap_or("./credentials.json");
let opts = Opts::from_args();

let mut cli_fxa = get_cli_fxa(get_default_fxa_config(), cred_file)?;
let mut cli_fxa = get_cli_fxa(get_default_fxa_config(), &opts.creds_file)?;
let device_id = cli_fxa.account.get_current_device_id()?;

let store = Arc::new(TabsStore::new());
Expand Down Expand Up @@ -107,7 +106,9 @@ fn main() -> Result<()> {
Ok(())
}

#[cfg(feature = "with-clipboard")]
fn read_local_state() -> Vec<RemoteTab> {
use clipboard::{ClipboardContext, ClipboardProvider};
println!("Please run the following command in the Firefox Browser Toolbox and copy it.");
println!(
" JSON.stringify(await Weave.Service.engineManager.get(\"tabs\")._store.getAllTabs())"
Expand Down Expand Up @@ -148,3 +149,10 @@ fn read_local_state() -> Vec<RemoteTab> {
}
local_state
}

#[cfg(not(feature = "with-clipboard"))]
fn read_local_state() -> Vec<RemoteTab> {
println!("This module is build without the `clipboard` feature, so we can't");
println!("read the local state.");
vec![]
}