rust: Including make stronger for world flags that follow for all subcommands with structopt

(*1*)

We need to construct out capability to let the person
write right into a report of their backyard. To do this, we
have to grasp the positioning in their backyard.

We will get started through imposing a serve as to get the
default backyard trail.

fn get_default_garden_dir() -> Consequence<PathBuf>  eyre!("May just now not to find house listing"))?; Adequate(user_dirs.home_dir().sign up for(".backyard"))

This makes use of the person’s gadget directories by way of the
directories crate to search out their house dir. We
then upload .backyard to the house dir for the default
backyard.

Preferably, we would need the person so to
specify their backyard trail. The use of structopt, we
can allow them to specify it as a brief, lengthy, or
env var.

In our README, we’re going to specify how this will have to paintings.


```shell
GARDEN_PATH=~/github/my-digital-garden backyard write
backyard -p ~/github/my-digital-garden write
backyard --garden_path ~/github/my-digital-garden write
```

And in our Choose struct, we will be able to inform structopt the way to
take care of it. Placing this in our Choose struct as a substitute of
our Command enum make it a world flag that may be
specified for all subcommands.

struct Choose { #[structopt(parse(from_os_str), short = "p", long, env)] garden_path: Choice<PathBuf>, #[structopt(subcommand)] cmd: Command,
}

structopt is handiest dealing with the person enter, so in
major() we nonetheless wish to fall again to the
default if the garden_path isn’t specified.

let garden_path = fit choose.garden_path { Some(pathbuf) => Adequate(pathbuf), None => get_default_garden_dir().wrap_err("`garden_path` was once now not equipped"),
}?;

if we pressure an Err in get_default_garden_dir
We will see how the wrapped mistakes finally end up stacking.

Error: 0: `garden_path` was once now not equipped 1: May just now not to find house listing

We will additionally trade the signature of write to
settle for the pathbuf.

Command::Write { name } => write(garden_path, name),

Word that we wish to import PathBuf. We will additionally
dbg! the backyard trail and name to peer their
values.

use std::trail::PathBuf; pub fn write(garden_path: PathBuf, name: Choice<String>) -> Consequence<()> { dbg!(garden_path, name); todo!()
}