Skip to content

Rehabilitate CI, upgrade to syn@2 #542

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: ci

on:
push:
branches:
- master

pull_request:
branches:
- master

schedule:
- cron: 00 4 * * *

jobs:
build:
strategy:
fail-fast: false
matrix:
rust:
# https://github.com/unicode-rs/unicode-width/commit/afab363383557c39942706c9441a5670e321b4a0
# added a call to `wrapping_add_signed`, added in 1.66.0.
- 1.66.0
- stable
- beta
- nightly

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
components: clippy,rustfmt
toolchain: ${{ matrix.rust }}
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@v2
with:
tool: taplo-cli
- run: taplo fmt --check
- run: cargo fmt --all -- --check
# Only exercise none/all feature sets; else we'd run the builder out of disk space.
- run: cargo build
- run: cargo build --all-features
# See https://github.com/dtolnay/trybuild/commit/4fc90bf70f4744a250dfb8804479f88c188de41b.
#
# Cannot build tests below 1.70.0.
- run: cargo clippy --all-targets --workspace -- --deny warnings --allow dead_code # TODO: remove?
if: matrix.rust != '1.66.0'
- run: cargo clippy --all-targets --workspace --all-features -- --deny warnings --allow dead_code # TODO: remove?
if: matrix.rust != '1.66.0'
- run: cargo test --workspace --no-default-features
if: matrix.rust != '1.66.0'
- run: cargo test --workspace --all-features
if: matrix.rust != '1.66.0'
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ suggestions = ["clap/suggestions"]
color = ["clap/color"]
wrap_help = ["clap/wrap_help"]
yaml = ["clap/yaml"]
lints = ["clap/lints"]
lints = []
debug = ["clap/debug"]
no_cargo = ["clap/no_cargo"]
doc = ["clap/doc"]
paw = ["structopt-derive/paw", "paw_dep"]

[badges]
travis-ci = { repository = "TeXitoi/structopt" }

[dependencies]
clap = { version = "2.33", default-features = false }
structopt-derive = { path = "structopt-derive", version = "=0.4.18" }
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# StructOpt

[![Build status](https://travis-ci.com/TeXitoi/structopt.svg?branch=master)](https://app.travis-ci.com/github/TeXitoi/structopt) [![](https://img.shields.io/crates/v/structopt.svg)](https://crates.io/crates/structopt) [![](https://docs.rs/structopt/badge.svg)](https://docs.rs/structopt)
[![Build status](../../actions/workflows/ci.yml/badge.svg)](../../actions)
[![](https://img.shields.io/crates/v/structopt.svg)](https://crates.io/crates/structopt)
[![](https://docs.rs/structopt/badge.svg)](https://docs.rs/structopt)
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)

Parse command line arguments by defining a struct. It combines [clap](https://crates.io/crates/clap) with custom derive.
Expand All @@ -15,7 +17,7 @@ See the [structopt -> clap migration guide](https://github.com/clap-rs/clap/blob

## Documentation

Find it on [Docs.rs](https://docs.rs/structopt). You can also check the [examples](https://github.com/TeXitoi/structopt/tree/master/examples) and the [changelog](https://github.com/TeXitoi/structopt/blob/master/CHANGELOG.md).
Find it on [Docs.rs](https://docs.rs/structopt). You can also check the [examples](examples) and the [changelog](CHANGELOG.md).

## Example

Expand Down Expand Up @@ -139,7 +141,7 @@ Opt {

## StructOpt rustc version policy

- Minimum rustc version modification must be specified in the [changelog](https://github.com/TeXitoi/structopt/blob/master/CHANGELOG.md) and in the [travis configuration](https://github.com/TeXitoi/structopt/blob/master/.travis.yml).
- Minimum rustc version modification must be specified in the [changelog](CHANGELOG.md) and in the [CI configuration](.github/workflows/ci.yml).
- Contributors can increment minimum rustc version without any justification if the new version is required by the latest version of one of StructOpt's dependencies (`cargo update` will not fail on StructOpt).
- Contributors can increment minimum rustc version if the library user experience is improved.

Expand Down
6 changes: 3 additions & 3 deletions examples/enum_in_args_with_strum.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! Running this example with --help prints this message:
//! -----------------------------------------------------
//! structopt 0.3.25
//!
//!
//! USAGE:
//! enum_in_args_with_strum [OPTIONS]
//!
//!
//! FLAGS:
//! -h, --help Prints help information
//! -V, --version Prints version information
//!
//!
//! OPTIONS:
//! --format <format> [default: txt] [possible values: txt, md, html]
//! -----------------------------------------------------
Expand Down
9 changes: 2 additions & 7 deletions examples/skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ pub struct Opt {
s: String,
}

#[derive(Debug, PartialEq)]
#[derive(Debug, Default, PartialEq)]
enum Kind {
A,
#[default]
B,
}

impl Default for Kind {
fn default() -> Self {
return Kind::B;
}
}

fn main() {
assert_eq!(
Opt::from_iter(&["test", "-n", "10"]),
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,7 @@
//! use std::{fmt, str::FromStr};
//!
//! // a struct with single custom argument
//! #[cfg(not(feature = "paw"))]
//! #[derive(StructOpt)]
//! struct GenericArgs<T: FromStr> where <T as FromStr>::Err: fmt::Display + fmt::Debug {
//! generic_arg_1: String,
Expand All @@ -1101,7 +1102,9 @@
//!
//! ```
//! # use structopt::StructOpt;
//!
//! // a struct with multiple custom arguments in a substructure
//! #[cfg(not(feature = "paw"))]
//! #[derive(StructOpt)]
//! struct GenericArgs<T: StructOpt> {
//! generic_arg_1: String,
Expand Down Expand Up @@ -1202,7 +1205,7 @@ pub trait StructOptInternal: StructOpt {
false
}

fn from_subcommand<'a, 'b>(_sub: (&'b str, Option<&'b clap::ArgMatches<'a>>)) -> Option<Self>
fn from_subcommand<'a>(_sub: (&'a str, Option<&'a clap::ArgMatches<'_>>)) -> Option<Self>
where
Self: std::marker::Sized,
{
Expand All @@ -1227,7 +1230,7 @@ impl<T: StructOptInternal> StructOptInternal for Box<T> {
}

#[doc(hidden)]
fn from_subcommand<'a, 'b>(sub: (&'b str, Option<&'b clap::ArgMatches<'a>>)) -> Option<Self> {
fn from_subcommand<'a>(sub: (&'a str, Option<&'a clap::ArgMatches<'_>>)) -> Option<Self> {
<T as StructOptInternal>::from_subcommand(sub).map(Box::new)
}

Expand Down
5 changes: 1 addition & 4 deletions structopt-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ keywords = ["clap", "cli", "derive", "docopt"]
categories = ["command-line-interface"]
license = "Apache-2.0/MIT"

[badges]
travis-ci = { repository = "TeXitoi/structopt" }

[dependencies]
syn = { version = "1", features = ["full"] }
syn = { version = "2", features = ["full"] }
quote = "1"
proc-macro2 = "1"
heck = "0.4.0"
Expand Down
21 changes: 13 additions & 8 deletions structopt-derive/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use proc_macro2::{Span, TokenStream};
use proc_macro_error::abort;
use quote::{quote, quote_spanned, ToTokens};
use syn::{
self, ext::IdentExt, spanned::Spanned, Attribute, Expr, Ident, LitStr, MetaNameValue, Type,
self, ext::IdentExt, spanned::Spanned, Attribute, Expr, ExprLit, Ident, LitStr, MetaNameValue,
Type,
};

#[derive(Clone)]
Expand Down Expand Up @@ -382,14 +383,18 @@ impl Attrs {

let comment_parts: Vec<_> = attrs
.iter()
.filter(|attr| attr.path.is_ident("doc"))
.filter(|attr| attr.path().is_ident("doc"))
.filter_map(|attr| {
if let Ok(NameValue(MetaNameValue { lit: Str(s), .. })) = attr.parse_meta() {
Some(s.value())
} else {
// non #[doc = "..."] attributes are not our concern
// we leave them for rustc to handle
None
match &attr.meta {
NameValue(MetaNameValue {
value: Expr::Lit(ExprLit { lit: Str(s), .. }),
..
}) => Some(s.value()),
_ => {
// non #[doc = "..."] attributes are not our concern
// we leave them for rustc to handle
None
}
}
})
.collect();
Expand Down
2 changes: 1 addition & 1 deletion structopt-derive/src/doc_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn split_paragraphs(lines: &[&str]) -> Vec<String> {
let len = slice
.iter()
.position(|s| is_blank(s))
.unwrap_or_else(|| slice.len());
.unwrap_or(slice.len());

last_line += start + len;

Expand Down
12 changes: 6 additions & 6 deletions structopt-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ fn gen_from_subcommand(
let sub_name = attrs.cased_name();
let variant_name = &variant.ident;
let constructor_block = match variant.fields {
Named(ref fields) => gen_constructor(&fields.named, &attrs),
Named(ref fields) => gen_constructor(&fields.named, attrs),
Unit => quote!(),
Unnamed(ref fields) if fields.unnamed.len() == 1 => {
let ty = &fields.unnamed[0];
Expand Down Expand Up @@ -776,21 +776,21 @@ fn gen_paw_impl(_: &ImplGenerics, _: &Ident, _: &TypeGenerics, _: &TokenStream)
fn split_structopt_generics_for_impl(
generics: &Generics,
) -> (ImplGenerics, TypeGenerics, TokenStream) {
use syn::{token::Add, TypeParamBound::Trait};
use syn::{token::Plus, TypeParamBound::Trait};

fn path_ends_with(path: &Path, ident: &str) -> bool {
path.segments.last().unwrap().ident == ident
}

fn type_param_bounds_contains(bounds: &Punctuated<TypeParamBound, Add>, ident: &str) -> bool {
fn type_param_bounds_contains(bounds: &Punctuated<TypeParamBound, Plus>, ident: &str) -> bool {
for bound in bounds {
if let Trait(bound) = bound {
if path_ends_with(&bound.path, ident) {
return true;
}
}
}
return false;
false
}

struct TraitBoundAmendments {
Expand Down Expand Up @@ -874,7 +874,7 @@ fn impl_structopt_for_struct(
attrs: &[Attribute],
generics: &Generics,
) -> TokenStream {
let (impl_generics, ty_generics, where_clause) = split_structopt_generics_for_impl(&generics);
let (impl_generics, ty_generics, where_clause) = split_structopt_generics_for_impl(generics);

let basic_clap_app_gen = gen_clap_struct(attrs);
let augment_clap = gen_augment_clap(fields, &basic_clap_app_gen.attrs);
Expand Down Expand Up @@ -931,7 +931,7 @@ fn impl_structopt_for_enum(
attrs: &[Attribute],
generics: &Generics,
) -> TokenStream {
let (impl_generics, ty_generics, where_clause) = split_structopt_generics_for_impl(&generics);
let (impl_generics, ty_generics, where_clause) = split_structopt_generics_for_impl(generics);

let basic_clap_app_gen = gen_clap_enum(attrs);
let clap_tokens = basic_clap_app_gen.tokens;
Expand Down
Loading