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

Add compare command #282

Merged
merged 2 commits into from Dec 25, 2020
Merged

Add compare command #282

merged 2 commits into from Dec 25, 2020

Conversation

mstruebing
Copy link
Member

@mstruebing mstruebing commented Sep 18, 2020

A proof of concept how comparing could work.
I think this isn't the cleanest implementation and needs some abstraction work in terms of types, and duplicate work between compare and run but I wanted to see if it can work and how it could work.

We didn't already agreed that this feature needed to be added to the tool, but I liked the idea, found some time and had fun playing around with it.

So this could be the starting point of a discussion and further investigation of that topic.

What do you think?

Check this feature:

# creating test data
echo HELLO=value >> .env
echo HELLO=value >> .env.local
echo WORLD=value >> .env

# running
dotenv-linter --compare .env .env.local
# or
cargo run -- --compare .env .env.local

@mstruebing mstruebing added feature New feature or request proposal Suggest a new feature or changes discussion Discussion of something labels Sep 18, 2020
@mstruebing mstruebing requested a review from a team September 18, 2020 12:29
@mstruebing mstruebing force-pushed the feature-compare branch 2 times, most recently from 89f7ff2 to e407634 Compare September 18, 2020 12:34
@mgrachev
Copy link
Member

mgrachev commented Sep 18, 2020

@mstruebing Thank you for your contribution! 🔥 I like this feature too ❤️

I think we will merge it after release v2.2.0.

I have a few ideas how we can improve it, but I will come back with them a little later.

@mgrachev mgrachev added this to the v3.0.0 milestone Sep 25, 2020
@mgrachev mgrachev mentioned this pull request Oct 26, 2020
16 tasks
@DDtKey
Copy link
Member

DDtKey commented Oct 26, 2020

I think it would also make sense to do this as a separate subcommand after #333 🤔
What do you think? @dotenv-linter/core

This can also be done as a separate PR later on. Just a suggestion)

Multi-functional dotenv-linter👍

@mgrachev
Copy link
Member

I think it would also make sense to do this as a separate subcommand after #333 🤔
What do you think? @dotenv-linter/core

This can also be done as a separate PR later on. Just a suggestion)

To tell the truth, I would like to merge this PR after #333

@mgrachev
Copy link
Member

mgrachev commented Oct 27, 2020

Multi-functional dotenv-linter👍

Yes, we are slowly moving towards this way 🙂

$ dotenv-linter check
$ dotenv-linter fix
$ dotenv-linter compare
$ dotenv-linter something_else

If you have ideas what else we can include in the next release, let me know 😉

@mstruebing mstruebing force-pushed the feature-compare branch 4 times, most recently from 2d56d5b to d4d1400 Compare October 27, 2020 10:48
@mstruebing
Copy link
Member Author

I polished the PR a bit, feedback or desired changes are welcome

@mstruebing
Copy link
Member Author

I think this PR is on hold until the subcommands are finished, right?

@mgrachev
Copy link
Member

I think this PR is on hold until the subcommands are finished, right?

Yes, you are right 🙂

@mgrachev
Copy link
Member

I think this PR is on hold until the subcommands are finished, right?

Subcommands are finished 🎉

@mstruebing mstruebing force-pushed the feature-compare branch 3 times, most recently from 98bcd9e to b923765 Compare November 19, 2020 11:38
@mstruebing mstruebing changed the title Add compare-flag Add compare-command Nov 19, 2020
@mstruebing
Copy link
Member Author

I updated the PR right now as a subcommand

@codecov-io
Copy link

codecov-io commented Nov 19, 2020

Codecov Report

Merging #282 (933d9bb) into master (20a7a3b) will increase coverage by 0.13%.
The diff coverage is 97.01%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #282      +/-   ##
==========================================
+ Coverage   95.06%   95.19%   +0.13%     
==========================================
  Files          34       36       +2     
  Lines        2310     2373      +63     
==========================================
+ Hits         2196     2259      +63     
  Misses        114      114              
Impacted Files Coverage Δ
src/common.rs 100.00% <ø> (ø)
src/lib.rs 87.78% <94.59%> (+3.25%) ⬆️
src/common/compare.rs 100.00% <100.00%> (ø)
src/common/output/compare.rs 100.00% <100.00%> (ø)
src/main.rs 89.28% <100.00%> (+5.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 20a7a3b...933d9bb. Read the comment docs.

@mgrachev
Copy link
Member

@mstruebing Thank you!

Can you explain how this feature should work?
Also please give some examples.

@mstruebing
Copy link
Member Author

Sure, so in general what it does:
You use the compare command and at least two files to compare (as I'm writing this I realize I need to make sure that you pass at least two files).
It then collects all keys of every environment file and compares if some of them are present in one file but not in the other.

I think this is handy for testing if different environments have some variables missing.

Also sometimes you have an .env.sample file in your repository. Which might get's updated and you miss to update your development environment file. Then you could quickly run dotenv-linter compare .env.sample .env and see which keys you might need to add. This is especially useful in bigger projects with lots of environment variables.

To try it out you can use the command in the first comment, just replace --compare with compare.

Do you have any further questions I did not answered?

@mgrachev
Copy link
Member

mgrachev commented Nov 26, 2020

Right now the output of the compare command looks like this:

$ dotenv-linter compare .env .env.local .env2
Comparing .env
Comparing .env.local
Comparing .env2
".env" is missing keys: "OK, MULTILINE"
".env.local" is missing keys: "OK, MULTILINE, 1MULTILINE, FOO, ZOO, WORLD"
".env2" is missing keys: "1MULTILINE, HELLO, ZOO, WORLD"

I would like to see something like this:

$ dotenv-linter compare .env .env.local .env2
Comparing .env
.env is missing keys: MULTILINE, OK

Comparing .env.local
.env.local is missing keys: FOO, 1MULTILINE, WORLD, MULTILINE, OK, ZOO

Comparing .env2
.env2 is missing keys: 1MULTILINE, HELLO, WORLD, ZOO

What do you think?

src/common/output/compare.rs Outdated Show resolved Hide resolved
src/common/output/compare.rs Outdated Show resolved Hide resolved
src/common/warning.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
tests/compare/compare.rs Show resolved Hide resolved
src/common/compare.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
@mstruebing
Copy link
Member Author

mstruebing commented Dec 12, 2020

I think I adressed all of the review comments, still need to add some tests, however I have a problem now which I'm not able to fix:

src/lib.rs:154

        for line in lines {
            if let Some(key) = line.get_key() { // `line` does not live long enough: borrowed value does not live long enough
                all_keys.insert(key);
                keys.push(key)
            }
        }

What can I do to prevent this, I tried multiple things without success?

src/common/compare.rs Outdated Show resolved Hide resolved
src/common/warning.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
@mgrachev
Copy link
Member

mgrachev commented Dec 12, 2020

What can I do to prevent this, I tried multiple things without success?

Take a look at my comments above. I have sketched the fastest solution of your problem, but not the most efficient 😅

@mgrachev mgrachev removed the proposal Suggest a new feature or changes label Dec 12, 2020
@mstruebing mstruebing force-pushed the feature-compare branch 3 times, most recently from 24f5cc3 to 9f05c69 Compare December 12, 2020 17:10
tests/compare/compare.rs Outdated Show resolved Hide resolved
tests/compare/compare.rs Outdated Show resolved Hide resolved
src/common/compare.rs Outdated Show resolved Hide resolved
Copy link
Member

@DDtKey DDtKey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple of comments, please take a look 🙂
(this will also fix the current tests)

src/common/compare.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@DDtKey
Copy link
Member

DDtKey commented Dec 16, 2020

@dotenv-linter/core we should remember to add this to the documentation (dotenv-linter.github.io)

@mstruebing
Copy link
Member Author

Sorry for the long delay, I just pushed:

  • Tests for quiet mode
  • simplifications by @DDtKey

Is there anything else I need to do except documentation?

@mgrachev
Copy link
Member

Is there anything else I need to do except documentation?

I will add documentation for this command in dotenv-linter/dotenv-linter.github.io#16.

src/lib.rs Outdated Show resolved Hide resolved
DDtKey
DDtKey previously approved these changes Dec 24, 2020
Copy link
Member

@DDtKey DDtKey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have done an amazing job! 🚀
Thank you! 👍

Co-authored-by: Grachev Mikhail <work@mgrachev.com>
@mgrachev mgrachev merged commit 3892098 into master Dec 25, 2020
@mgrachev mgrachev deleted the feature-compare branch December 25, 2020 07:32
@mgrachev
Copy link
Member

@mstruebing Excellent work 🔥Thank you 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Development

Successfully merging this pull request may close these issues.

None yet

4 participants