Skip to content

implemented new changes regarding issue 5 #15

Open
sudarsan1030 wants to merge 2 commits into
NammaRust:mainfrom
sudarsan1030:feature
Open

implemented new changes regarding issue 5 #15
sudarsan1030 wants to merge 2 commits into
NammaRust:mainfrom
sudarsan1030:feature

Conversation

@sudarsan1030

@sudarsan1030 sudarsan1030 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

added parser for .emv kinda files , returns values in for dictionary , ignores comments and blank lines

Summary by CodeRabbit

  • New Features

    • Added support for reading environment-style files into key/value settings, automatically trimming whitespace and ignoring blank lines and comment lines.
  • Bug Fixes

    • Updated the app’s console startup message to reflect the latest “issue” status.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds an env-file parser that reads key=value lines into a HashMap while skipping blank and comment lines, and updates main() output text.

Changes

Env file parsing

Layer / File(s) Summary
Parser and imports
src/env_validator.rs
Imports HashMap, filesystem, and I/O support, then adds parse_env_file to read, filter, split, trim, and collect env entries into a HashMap.

Main output text

Layer / File(s) Summary
Printed message
src/main.rs
main() now prints issue 4/5/6 solution instead of issue 4!!!.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • suriyasureshok

Poem

I hopped through env files with glee,
Sniffed key=value by the tree,
Skipped comments, tidy and neat,
Then booped the main print text to a new beat. 🐰

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is too vague and generic to identify the main change in the pull request. Use a concise title that names the primary change, such as adding an environment-file parser that ignores comments and blank lines.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/env_validator.rs`:
- Around line 41-53: In env_validator.rs, update the line parsing logic in the
env-file reader so malformed records are rejected instead of ignored: the
current loop in the env parsing function silently skips non-empty, non-comment
lines without an '=' and accepts entries with an empty key. Add validation
around the existing split_once('=') handling so only non-empty keys are
inserted, and return an error for any malformed line rather than continuing with
Ok(...). Use the existing env-file parsing path and the vars insert logic as the
place to enforce this.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bd12059f-17bb-47c5-bd87-31d3d790138b

📥 Commits

Reviewing files that changed from the base of the PR and between 5e31388 and 3077c3c.

📒 Files selected for processing (2)
  • src/env_validator.rs
  • src/main.rs

Comment thread src/env_validator.rs
Comment on lines +41 to +53
for line in content.lines() {
let line = line.trim();

if line.is_empty() || line.starts_with('#') {
continue;
}

if let Some((key, value)) = line.split_once('=') {
vars.insert(
key.trim().to_string(),
value.trim().to_string(),
);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Reject malformed env records instead of skipping them.

Any non-empty, non-comment line without = is silently dropped here, and =value is accepted with an empty key. That turns env-file typos into missing configuration while still returning Ok(...).

Suggested fix
-    for line in content.lines() {
+    for (line_no, line) in content.lines().enumerate() {
         let line = line.trim();

         if line.is_empty() || line.starts_with('#') {
             continue;
         }

-        if let Some((key, value)) = line.split_once('=') {
-            vars.insert(
-                key.trim().to_string(),
-                value.trim().to_string(),
-            );
-        }
+        let (key, value) = line.split_once('=').ok_or_else(|| {
+            io::Error::new(
+                io::ErrorKind::InvalidData,
+                format!("invalid env entry on line {}: missing '='", line_no + 1),
+            )
+        })?;
+
+        let key = key.trim();
+        if key.is_empty() {
+            return Err(io::Error::new(
+                io::ErrorKind::InvalidData,
+                format!("invalid env entry on line {}: empty key", line_no + 1),
+            ));
+        }
+
+        vars.insert(key.to_string(), value.trim().to_string());
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for line in content.lines() {
let line = line.trim();
if line.is_empty() || line.starts_with('#') {
continue;
}
if let Some((key, value)) = line.split_once('=') {
vars.insert(
key.trim().to_string(),
value.trim().to_string(),
);
}
for (line_no, line) in content.lines().enumerate() {
let line = line.trim();
if line.is_empty() || line.starts_with('#') {
continue;
}
let (key, value) = line.split_once('=').ok_or_else(|| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("invalid env entry on line {}: missing '='", line_no + 1),
)
})?;
let key = key.trim();
if key.is_empty() {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
format!("invalid env entry on line {}: empty key", line_no + 1),
));
}
vars.insert(key.to_string(), value.trim().to_string());
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/env_validator.rs` around lines 41 - 53, In env_validator.rs, update the
line parsing logic in the env-file reader so malformed records are rejected
instead of ignored: the current loop in the env parsing function silently skips
non-empty, non-comment lines without an '=' and accepts entries with an empty
key. Add validation around the existing split_once('=') handling so only
non-empty keys are inserted, and return an error for any malformed line rather
than continuing with Ok(...). Use the existing env-file parsing path and the
vars insert logic as the place to enforce this.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/env_validator.rs`:
- Around line 73-84: The report output in `env_validator.rs` is currently
iterating `HashMap` entries directly in the “Unused Variables” and “Empty
Variables” sections, which makes the printed order nondeterministic. Update the
report generation logic around the existing `env` iteration to collect the
matching keys first, sort them, and then print them in a stable order before
emitting each section so `println!` output is deterministic and test-friendly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 932b6eea-3ed4-4e1a-b81b-85ebe1f8b3b7

📥 Commits

Reviewing files that changed from the base of the PR and between 3077c3c and 91c23dc.

📒 Files selected for processing (2)
  • src/env_validator.rs
  • src/main.rs
✅ Files skipped from review due to trivial changes (1)
  • src/main.rs

Comment thread src/env_validator.rs
Comment on lines +73 to +84
println!("\nUnused Variables:");
for key in env.keys() {
if !extracted.contains(key) {
println!("- {}", key);
}
}

println!("\nEmpty Variables:");
for (key, value) in env {
if value.trim().is_empty() {
println!("- {}", key);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Sort report entries before printing.

Lines 74-83 iterate HashMap directly, so the "Unused Variables" and "Empty Variables" sections come out in nondeterministic order. That makes the CLI output noisy and brittle to assert in tests.

Suggested fix
     println!("\nUnused Variables:");
-    for key in env.keys() {
-        if !extracted.contains(key) {
-            println!("- {}", key);
-        }
-    }
+    let mut unused: Vec<_> = env
+        .keys()
+        .filter(|key| !extracted.contains(*key))
+        .cloned()
+        .collect();
+    unused.sort();
+    for key in unused {
+        println!("- {}", key);
+    }

     println!("\nEmpty Variables:");
-    for (key, value) in env {
-        if value.trim().is_empty() {
-            println!("- {}", key);
-        }
-    }
+    let mut empty: Vec<_> = env
+        .iter()
+        .filter(|(_, value)| value.trim().is_empty())
+        .map(|(key, _)| key.clone())
+        .collect();
+    empty.sort();
+    for key in empty {
+        println!("- {}", key);
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
println!("\nUnused Variables:");
for key in env.keys() {
if !extracted.contains(key) {
println!("- {}", key);
}
}
println!("\nEmpty Variables:");
for (key, value) in env {
if value.trim().is_empty() {
println!("- {}", key);
}
println!("\nUnused Variables:");
let mut unused: Vec<_> = env
.keys()
.filter(|key| !extracted.contains(*key))
.cloned()
.collect();
unused.sort();
for key in unused {
println!("- {}", key);
}
println!("\nEmpty Variables:");
let mut empty: Vec<_> = env
.iter()
.filter(|(_, value)| value.trim().is_empty())
.map(|(key, _)| key.clone())
.collect();
empty.sort();
for key in empty {
println!("- {}", key);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/env_validator.rs` around lines 73 - 84, The report output in
`env_validator.rs` is currently iterating `HashMap` entries directly in the
“Unused Variables” and “Empty Variables” sections, which makes the printed order
nondeterministic. Update the report generation logic around the existing `env`
iteration to collect the matching keys first, sort them, and then print them in
a stable order before emitting each section so `println!` output is
deterministic and test-friendly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant