Skip to content

Commit

Permalink
Merge pull request #56 from dotenv-rs/github-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoeyR authored Jun 26, 2020
2 parents fcdfc49 + 8c2ba38 commit 3c1a77b
Show file tree
Hide file tree
Showing 23 changed files with 258 additions and 321 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI

on:
push:
branches:
master
pull_request:
branches:
master

jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust: [stable, beta, nightly]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
- uses: actions-rs/cargo@v1
with:
command: test
check:
runs-on: ubuntu-latest
name: Check
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check

- uses: actions-rs/[email protected]
with:
args: --ignore-tests -- --test-threads 1
- uses: codecov/codecov-action@v1
- name: Archive code coverage results
uses: actions/upload-artifact@v1
with:
name: code-coverage-report
path: cobertura.xml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# rust-dotenv

[![Build Status](https://dev.azure.com/dotenv-rs/dotenv/_apis/build/status/dotenv-rs.dotenv?branchName=master)](https://dev.azure.com/dotenv-rs/dotenv/_build/latest?definitionId=2&branchName=master)
![CI](https://github.com/dotenv-rs/dotenv/workflows/CI/badge.svg)
[![codecov](https://codecov.io/gh/dotenv-rs/dotenv/branch/master/graph/badge.svg)](https://codecov.io/gh/dotenv-rs/dotenv)
[![Crates.io](https://img.shields.io/crates/v/dotenv.svg)](https://crates.io/crates/dotenv)

Expand Down
22 changes: 0 additions & 22 deletions azure-pipelines.yml

This file was deleted.

68 changes: 0 additions & 68 deletions azure-pipelines/build-template.yml

This file was deleted.

77 changes: 0 additions & 77 deletions azure-pipelines/fix_coverage_for_cobertura.py

This file was deleted.

22 changes: 13 additions & 9 deletions dotenv/src/bin/dotenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate dotenv;

use clap::{App, AppSettings, Arg};
use std::os::unix::process::CommandExt;
use std::process::{Command, exit};
use std::process::{exit, Command};

macro_rules! die {
($fmt:expr) => ({
Expand Down Expand Up @@ -33,26 +33,30 @@ fn main() {
.setting(AppSettings::AllowExternalSubcommands)
.setting(AppSettings::ArgRequiredElseHelp)
.setting(AppSettings::UnifiedHelpMessage)
.arg(Arg::with_name("FILE")
.short("f")
.long("file")
.takes_value(true)
.help("Use a specific .env file (defaults to .env)"))
.arg(
Arg::with_name("FILE")
.short("f")
.long("file")
.takes_value(true)
.help("Use a specific .env file (defaults to .env)"),
)
.get_matches();

match matches.value_of("FILE") {
None => dotenv::dotenv(),
Some(file) => dotenv::from_filename(file),
}.unwrap_or_else(|e| die!("error: failed to load environment: {}", e));
}
.unwrap_or_else(|e| die!("error: failed to load environment: {}", e));

let mut command = match matches.subcommand() {
(name, Some(matches)) => {
let args = matches.values_of("")
let args = matches
.values_of("")
.map(|v| v.collect())
.unwrap_or(Vec::new());

make_command(name, args)
},
}
_ => die!("error: missing required argument <COMMAND>"),
};

Expand Down
31 changes: 23 additions & 8 deletions dotenv/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;
use std::fmt;
use std::error;
use std::fmt;
use std::io;

pub type Result<T> = std::result::Result<T, Error>;

Expand All @@ -10,7 +10,7 @@ pub enum Error {
Io(io::Error),
EnvVar(std::env::VarError),
#[doc(hidden)]
__Nonexhaustive
__Nonexhaustive,
}

impl Error {
Expand All @@ -37,7 +37,11 @@ impl fmt::Display for Error {
match self {
Error::Io(err) => write!(fmt, "{}", err),
Error::EnvVar(err) => write!(fmt, "{}", err),
Error::LineParse(line, error_index) => write!(fmt, "Error parsing line: '{}', error at line index: {}", line, error_index),
Error::LineParse(line, error_index) => write!(
fmt,
"Error parsing line: '{}', error at line index: {}",
line, error_index
),
_ => unreachable!(),
}
}
Expand All @@ -52,14 +56,22 @@ mod test {
#[test]
fn test_io_error_source() {
let err = Error::Io(std::io::ErrorKind::PermissionDenied.into());
let io_err = err.source().unwrap().downcast_ref::<std::io::Error>().unwrap();
let io_err = err
.source()
.unwrap()
.downcast_ref::<std::io::Error>()
.unwrap();
assert_eq!(std::io::ErrorKind::PermissionDenied, io_err.kind());
}

#[test]
fn test_envvar_error_source() {
let err = Error::EnvVar(std::env::VarError::NotPresent);
let var_err = err.source().unwrap().downcast_ref::<std::env::VarError>().unwrap();
let var_err = err
.source()
.unwrap()
.downcast_ref::<std::env::VarError>()
.unwrap();
assert_eq!(&std::env::VarError::NotPresent, var_err);
}

Expand Down Expand Up @@ -105,6 +117,9 @@ mod test {
fn test_lineparse_error_display() {
let err = Error::LineParse("test line".to_string(), 2);
let err_desc = format!("{}", err);
assert_eq!("Error parsing line: 'test line', error at line index: 2", err_desc);
assert_eq!(
"Error parsing line: 'test line', error at line index: 2",
err_desc
);
}
}
}
15 changes: 10 additions & 5 deletions dotenv/src/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::errors::*;
use crate::iter::Iter;

pub struct Finder<'a> {
filename: &'a Path,
filename: &'a Path,
}

impl<'a> Finder<'a> {
Expand Down Expand Up @@ -34,9 +34,11 @@ pub fn find(directory: &Path, filename: &Path) -> Result<PathBuf> {
let candidate = directory.join(filename);

match fs::metadata(&candidate) {
Ok(metadata) => if metadata.is_file() {
return Ok(candidate);
},
Ok(metadata) => {
if metadata.is_file() {
return Ok(candidate);
}
}
Err(error) => {
if error.kind() != io::ErrorKind::NotFound {
return Err(Error::Io(error));
Expand All @@ -47,6 +49,9 @@ pub fn find(directory: &Path, filename: &Path) -> Result<PathBuf> {
if let Some(parent) = directory.parent() {
find(parent, filename)
} else {
Err(Error::Io(io::Error::new(io::ErrorKind::NotFound, "path not found")))
Err(Error::Io(io::Error::new(
io::ErrorKind::NotFound,
"path not found",
)))
}
}
2 changes: 1 addition & 1 deletion dotenv/src/iter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::env;
use std::io::{BufReader, Lines};
use std::io::prelude::*;
use std::io::{BufReader, Lines};

use crate::errors::*;
use crate::parse;
Expand Down
Loading

0 comments on commit 3c1a77b

Please sign in to comment.