Skip to content

Commit

Permalink
fix: add "info -A" and global "-c" flags
Browse files Browse the repository at this point in the history
  • Loading branch information
chaaz committed Nov 20, 2020
1 parent 9008300 commit 2c026ae
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 72 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ can be a headache to resolve. And it can be inefficient to halt all
contributions while a release is being built.
-->

Software go through a _release process_, where the software is
Software goes through a _release process_, where the software is
described, assigned a version number, and deployed to sites where it can
be executed or distributed. This process occurs first when the
application is created, and again whenever maintenance or improvements
Expand Down Expand Up @@ -129,9 +129,9 @@ Subdirectories](./docs/subs.md) page for a description.
### VCS Levels

VCS Levels allow you to control the way Versio interacts with a Git
repository: you can have interact only locally, with a remote, or not at
all. See the description in its [document](./docs/vcs_levels.md) for
more information.
repository: you can interact only locally, with a remote, or not at all.
See the description in its [document](./docs/vcs_levels.md) for more
information.

### Version Chains

Expand Down
16 changes: 13 additions & 3 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ $ versio <global options> [subcommand] <subcommand options>
- `vcs-level` (`-l`), `vcs-level-min` (`-m`), `vcs-level-max` (`-x`):
see the [VCS Levels](./vcs_levels.md) page for a description of these
global options.
- `no-current` (`-c`): when the calculated vcs level is "local",
commands that make no changes (`check`, `get`, `show`, `diff`,
`files`, `changes`, `plan`, `info`) will not verify that the repo is
current.

### Subcommands
[Subcommands]: #subcommands
Expand Down Expand Up @@ -139,16 +143,22 @@ along with their options and flags. You can always use `versio help` or
- `files`: See all files that have changed since the previous version.
- `plan`: View the update plan.
- `info`: Outputs a JSON document with information about projects:
- `--id` (`-i <ID>`): include an ID'd project in the document (you can
provide this option more than once).
- `--id` (`-i <ID>`): include a single project with the given ID (you
can provide this option more than once).
- `--name` (`-n <name>`): include a named project in the document (you
can provide this option more than once).
- `--label` (`-l <label>`): include all projects with a label (you can
provide this option more than once).
- `--all` (`-a`): include all projects.
- `--show-root` (`-R`): include the projects' root directories in the
document.
- `--show-name` (`-N`): include the projects' names in the document.
- `--show-name` (`-N`): include the projects' names.
- `--show-full-version` (`-F`): include the projects' full version
(including the tag prefix).
- `--show-version` (`-V`): include the projects' version numbers.
- `--show-tag-prefix` (`-T`): include the projects' tag prefixes.
- `--show-id` (`-I`): include the projects' ids.
- `--show-all` (`-A`): include all fields from the projects.

This command is useful to generate a machine-consumable document of
one or more of the project configurations. It's especially helpful to
Expand Down
2 changes: 1 addition & 1 deletion docs/use_cases.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Get up and running quickly with Versio, and get a brief introduction to
what it does. This example assumes a standard Node.js/NPM layout, but
Versio can handle lots of different project types.

If you don't have rust installed, you can't use `cargo install`.
If you don't have Rust installed, you can't use `cargo install`.
Instead, download a binary for your platform directly from the [Releases
page](https://github.com/chaaz/versio/releases).

Expand Down
16 changes: 15 additions & 1 deletion docs/vcs_levels.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ There are four such levels, ordered from minimal to maximal:
level: no network or remote interaction is allowed. Fetches, pulls
and pushes are not done: not even with tags. No effort is made to
ensure that the local repository is synchronized with any remote.

- **Remote**: The command interacts fully with the VCS system, including
a guarantee that the local repository is fully synced with the remote
both before and after the command executes.
Expand Down Expand Up @@ -49,6 +49,20 @@ gather information and write a new versions and changelogs based on pull
request information from the remote GitHub API, but then run `versio -l
local release --resume` to commit and tag only the local repo.

### Vs Current

The `--no-current` flag only works on some commands, and only when the
final VCS level is calculated as "local" (see "Calculation" below).
Normally all commands at the "local" level will verify that the repo is
current: i.e., it does not contain local modifications or untracked
files. These commands don't make any changes though, so it may be safe
to run them without this check, depending on your workflow.

At a VCS level of "remote" or higher, the check is always done (the
`--no-current` flag is ignored) because only a current repo can be
reconciled with remote changes. At the level of "none", the VCS isn't
consulted in any case, so the flag is effectively ignored.

## Calculation

Every Versio command except for `versio init` calculates the final VCS
Expand Down
46 changes: 32 additions & 14 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ pub fn execute(info: &EarlyInfo) -> Result<()> {
.display_order(1)
.help("The maximum VCS level")
)
.arg(
Arg::with_name("ignorecurrent")
.short("c")
.long("no-current")
.takes_value(false)
.display_order(1)
.help("Accept local repo changes")
)
.subcommand(
SubCommand::with_name("check")
.setting(AppSettings::UnifiedHelpMessage)
Expand Down Expand Up @@ -285,6 +293,14 @@ pub fn execute(info: &EarlyInfo) -> Result<()> {
.arg(
Arg::with_name("all").short("a").long("all").takes_value(false).display_order(1).help("Info on all projects")
)
.arg(
Arg::with_name("showall")
.short("A")
.long("show-all")
.takes_value(false)
.display_order(1)
.help("Show all fields")
)
.arg(
Arg::with_name("showroot")
.short("R")
Expand Down Expand Up @@ -348,23 +364,25 @@ fn parse_matches(m: ArgMatches) -> Result<()> {
}

let pref_vcs = parse_vcs(&m)?;
let ignore_current = m.is_present("ignorecurrent");

match m.subcommand() {
("check", _) => check(pref_vcs)?,
("check", _) => check(pref_vcs, ignore_current)?,
("get", Some(m)) => get(
pref_vcs,
m.is_present("wide"),
m.is_present("versiononly"),
m.is_present("prev"),
m.value_of("id"),
m.value_of("name")
m.value_of("name"),
ignore_current
)?,
("show", Some(m)) => show(pref_vcs, m.is_present("wide"), m.is_present("prev"))?,
("show", Some(m)) => show(pref_vcs, m.is_present("wide"), m.is_present("prev"), ignore_current)?,
("set", Some(m)) => set(pref_vcs, m.value_of("id"), m.value_of("name"), m.value_of("value").unwrap())?,
("diff", Some(_)) => diff(pref_vcs)?,
("files", Some(_)) => files(pref_vcs)?,
("changes", Some(_)) => changes(pref_vcs)?,
("plan", Some(_)) => plan(pref_vcs)?,
("diff", Some(_)) => diff(pref_vcs, ignore_current)?,
("files", Some(_)) => files(pref_vcs, ignore_current)?,
("changes", Some(_)) => changes(pref_vcs, ignore_current)?,
("plan", Some(_)) => plan(pref_vcs, ignore_current)?,
("release", Some(m)) if m.is_present("abort") => abort()?,
("release", Some(m)) if m.is_present("resume") => resume(pref_vcs)?,
("release", Some(m)) => release(pref_vcs, m.is_present("all"), m.is_present("dry"), m.is_present("pause"))?,
Expand All @@ -380,14 +398,14 @@ fn parse_matches(m: ArgMatches) -> Result<()> {

let show = InfoShow::new()
.pick_all(m.is_present("all"))
.show_name(m.is_present("showname"))
.show_root(m.is_present("showroot"))
.show_id(m.is_present("showid"))
.show_full_version(m.is_present("showfull"))
.show_version(m.is_present("showversion"))
.show_tag_prefix(m.is_present("showtagprefix"));
.show_name(m.is_present("showname") || m.is_present("showall"))
.show_root(m.is_present("showroot") || m.is_present("showall"))
.show_id(m.is_present("showid") || m.is_present("showall"))
.show_full_version(m.is_present("showfull") || m.is_present("showall"))
.show_version(m.is_present("showversion") || m.is_present("showall"))
.show_tag_prefix(m.is_present("showtagprefix") || m.is_present("showall"));

info(pref_vcs, ids, names, labels, show)?
info(pref_vcs, ids, names, labels, show, ignore_current)?
}
("", _) => empty_cmd()?,
(c, _) => unknown_cmd(c)?
Expand Down
49 changes: 29 additions & 20 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::git::Repo;
use crate::mono::Mono;
use crate::output::{Output, ProjLine};
use crate::state::{CommitState, StateRead};
use crate::vcs::{VcsLevel, VcsRange};
use crate::vcs::{VcsLevel, VcsRange, VcsState};
use error_chain::bail;
use std::collections::HashMap;
use std::fs::{remove_file, File};
Expand Down Expand Up @@ -34,8 +34,8 @@ impl EarlyInfo {
pub fn working_dir(&self) -> &Path { &self.working_dir }
}

pub fn check(pref_vcs: Option<VcsRange>) -> Result<()> {
let mono = build(pref_vcs, VcsLevel::None, VcsLevel::Local, VcsLevel::None, VcsLevel::Smart)?;
pub fn check(pref_vcs: Option<VcsRange>, ignore_current: bool) -> Result<()> {
let mono = with_opts(pref_vcs, VcsLevel::None, VcsLevel::Local, VcsLevel::None, VcsLevel::Smart, ignore_current)?;
let output = Output::new();
let mut output = output.check();

Expand All @@ -46,9 +46,10 @@ pub fn check(pref_vcs: Option<VcsRange>) -> Result<()> {
}

pub fn get(
pref_vcs: Option<VcsRange>, wide: bool, versonly: bool, prev: bool, id: Option<&str>, name: Option<&str>
pref_vcs: Option<VcsRange>, wide: bool, versonly: bool, prev: bool, id: Option<&str>, name: Option<&str>,
ignore_current: bool
) -> Result<()> {
let mono = build(pref_vcs, VcsLevel::None, VcsLevel::Local, VcsLevel::None, VcsLevel::Smart)?;
let mono = with_opts(pref_vcs, VcsLevel::None, VcsLevel::Local, VcsLevel::None, VcsLevel::Smart, ignore_current)?;

if prev {
get_using_cfg(&mono.config().slice_to_prev(mono.repo())?, wide, versonly, id, name)
Expand Down Expand Up @@ -83,8 +84,8 @@ fn get_using_cfg<R: StateRead>(
output.commit()
}

pub fn show(pref_vcs: Option<VcsRange>, wide: bool, prev: bool) -> Result<()> {
let mono = build(pref_vcs, VcsLevel::None, VcsLevel::Local, VcsLevel::None, VcsLevel::Smart)?;
pub fn show(pref_vcs: Option<VcsRange>, wide: bool, prev: bool, ignore_current: bool) -> Result<()> {
let mono = with_opts(pref_vcs, VcsLevel::None, VcsLevel::Local, VcsLevel::None, VcsLevel::Smart, ignore_current)?;

if prev {
show_using_cfg(&mono.config().slice_to_prev(mono.repo())?, wide)
Expand Down Expand Up @@ -115,8 +116,8 @@ pub fn set(pref_vcs: Option<VcsRange>, id: Option<&str>, name: Option<&str>, val
mono.commit(false, false)
}

pub fn diff(pref_vcs: Option<VcsRange>) -> Result<()> {
let mono = build(pref_vcs, VcsLevel::None, VcsLevel::Local, VcsLevel::Local, VcsLevel::Smart)?;
pub fn diff(pref_vcs: Option<VcsRange>, ignore_current: bool) -> Result<()> {
let mono = with_opts(pref_vcs, VcsLevel::None, VcsLevel::Local, VcsLevel::Local, VcsLevel::Smart, ignore_current)?;
let output = Output::new();
let mut output = output.diff();

Expand All @@ -126,26 +127,26 @@ pub fn diff(pref_vcs: Option<VcsRange>) -> Result<()> {
output.commit()
}

pub fn files(pref_vcs: Option<VcsRange>) -> Result<()> {
let mono = build(pref_vcs, VcsLevel::None, VcsLevel::Smart, VcsLevel::Local, VcsLevel::Smart)?;
pub fn files(pref_vcs: Option<VcsRange>, ignore_current: bool) -> Result<()> {
let mono = with_opts(pref_vcs, VcsLevel::None, VcsLevel::Smart, VcsLevel::Local, VcsLevel::Smart, ignore_current)?;
let output = Output::new();
let mut output = output.files();

output.write_files(mono.keyed_files()?)?;
output.commit()
}

pub fn changes(pref_vcs: Option<VcsRange>) -> Result<()> {
let mono = build(pref_vcs, VcsLevel::None, VcsLevel::Smart, VcsLevel::Local, VcsLevel::Smart)?;
pub fn changes(pref_vcs: Option<VcsRange>, ignore_current: bool) -> Result<()> {
let mono = with_opts(pref_vcs, VcsLevel::None, VcsLevel::Smart, VcsLevel::Local, VcsLevel::Smart, ignore_current)?;
let output = Output::new();
let mut output = output.changes();

output.write_changes(mono.changes()?)?;
output.commit()
}

pub fn plan(pref_vcs: Option<VcsRange>) -> Result<()> {
let mono = build(pref_vcs, VcsLevel::None, VcsLevel::Smart, VcsLevel::Local, VcsLevel::Smart)?;
pub fn plan(pref_vcs: Option<VcsRange>, ignore_current: bool) -> Result<()> {
let mono = with_opts(pref_vcs, VcsLevel::None, VcsLevel::Smart, VcsLevel::Local, VcsLevel::Smart, ignore_current)?;
let output = Output::new();
let mut output = output.plan();

Expand All @@ -154,9 +155,10 @@ pub fn plan(pref_vcs: Option<VcsRange>) -> Result<()> {
}

pub fn info(
pref_vcs: Option<VcsRange>, ids: Vec<ProjectId>, names: Vec<&str>, labels: Vec<&str>, show: InfoShow
pref_vcs: Option<VcsRange>, ids: Vec<ProjectId>, names: Vec<&str>, labels: Vec<&str>, show: InfoShow,
ignore_current: bool
) -> Result<()> {
let mono = build(pref_vcs, VcsLevel::None, VcsLevel::Smart, VcsLevel::None, VcsLevel::Smart)?;
let mono = with_opts(pref_vcs, VcsLevel::None, VcsLevel::Smart, VcsLevel::None, VcsLevel::Smart, ignore_current)?;
let output = Output::new();
let all = show.all();
let mut output = output.info(show);
Expand Down Expand Up @@ -331,7 +333,7 @@ pub fn release(pref_vcs: Option<VcsRange>, all: bool, dry: bool, pause: bool) ->

pub fn resume(user_pref_vcs: Option<VcsRange>) -> Result<()> {
let vcs = combine_vcs(user_pref_vcs, VcsLevel::None, VcsLevel::Smart, VcsLevel::Local, VcsLevel::Smart)?;
let repo = Repo::open(".", vcs.max())?;
let repo = Repo::open(".", VcsState::new(vcs.max(), false))?;
let output = Output::new();
let mut output = output.resume();

Expand Down Expand Up @@ -366,12 +368,19 @@ pub fn sanity_check() -> Result<()> {
}
}

fn with_opts(
user_pref_vcs: Option<VcsRange>, my_pref_lo: VcsLevel, my_pref_hi: VcsLevel, my_reqd_lo: VcsLevel,
my_reqd_hi: VcsLevel, ignore_current: bool
) -> Result<Mono> {
let vcs = combine_vcs(user_pref_vcs, my_pref_lo, my_pref_hi, my_reqd_lo, my_reqd_hi)?;
Mono::here(VcsState::new(vcs.max(), ignore_current))
}

fn build(
user_pref_vcs: Option<VcsRange>, my_pref_lo: VcsLevel, my_pref_hi: VcsLevel, my_reqd_lo: VcsLevel,
my_reqd_hi: VcsLevel
) -> Result<Mono> {
let vcs = combine_vcs(user_pref_vcs, my_pref_lo, my_pref_hi, my_reqd_lo, my_reqd_hi)?;
Mono::here(vcs.max())
with_opts(user_pref_vcs, my_pref_lo, my_pref_hi, my_reqd_lo, my_reqd_hi, false)
}

fn combine_vcs(
Expand Down
Loading

0 comments on commit 2c026ae

Please sign in to comment.