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

Implement: atmos list vendor #994

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open

Implement: atmos list vendor #994

wants to merge 33 commits into from

Conversation

Cerebrovinny
Copy link
Collaborator

@Cerebrovinny Cerebrovinny commented Feb 1, 2025

what

Listing all vendor config in tabular way

why

Evidence:
image

Screenshot 2025-02-01 at 19 18 20
Screenshot 2025-02-01 at 19 18 41
Screenshot 2025-02-01 at 19 19 08
Screenshot 2025-02-01 at 19 19 21

references

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added a new CLI command that lists vendor configurations with flexible output options including table, JSON, CSV, and TSV.
    • Extended workflow listings to support TSV output, enabling smoother data viewing.
    • Introduced a new field in the vendor configuration for enhanced data management.
    • Added detailed documentation for the atmos list vendor command, including usage examples and output options.
  • Tests

    • Introduced a comprehensive test suite to ensure vendor configuration listings work reliably across various formats.
  • Refactor

    • Enhanced error messages and user feedback during vendor configuration processing for clearer guidance.
    • Improved visibility of the ProcessVendorImports function for better accessibility across packages.

@Cerebrovinny Cerebrovinny marked this pull request as ready for review February 1, 2025 19:22
@Cerebrovinny Cerebrovinny requested a review from a team as a code owner February 1, 2025 19:22
@mergify mergify bot added the triage Needs triage label Feb 1, 2025
Copy link
Contributor

coderabbitai bot commented Feb 1, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a new CLI command (atmos list vendor) along with vendor configuration processing logic and related tests. It adds functions to process vendor files and list vendor configurations in configurable output formats (table, JSON, CSV, TSV). Additionally, the vendor schema is updated with a new field, and workflow listing support is extended with a TSV format. Minor improvements are also made to the error handling and function visibility in the vendor utilities.

Changes

Files Change Summary
cmd/list_vendor.go, pkg/list/list_vendor.go, pkg/list/list_vendor_test.go Added new CLI command listVendorCmd with persistent flags; introduced functions (processVendorFile, FilterAndListVendors) to process vendor configurations; created comprehensive tests for vendor listing based on various output formats.
pkg/schema/schema.go Updated the Vendor struct by adding a new List field with YAML/JSON/mapstructure annotations.
tests/snapshots/.../TestCLICommands_atmos_describe_config.stdout.golden Modified the vendor section to include a new list object with format and columns properties.
pkg/list/list_workflows.go Added a new constant FormatTSV and updated the ValidateFormat function to support TSV output.
internal/exec/vendor_utils.go Renamed processVendorImports to exported ProcessVendorImports and enhanced error messages for vendor configuration validation.

Assessment against linked issues

Objective Addressed Explanation
DEV-2806: Implement atmos list vendor for vendor listing with configurable output in atmos.yaml

Possibly related PRs

  • get atmos config and vendor from .yaml or .yml #736: The changes in the main PR, specifically the introduction of the FilterAndListVendors function, are related to the modifications in the retrieved PR that enhance the handling of vendor configuration files, as both involve processing vendor data and configurations in a structured manner.
  • Fix vendor pull directory creation issue #782: The changes in the main PR, which introduce a new CLI command for listing vendor configurations and utilize the FilterAndListVendors function, are related to the changes in the retrieved PR, which also involves vendor processing and error handling.
  • fix bug atmos vendor pull URI cannot contain path traversal sequences and git schema #899: The changes in the main PR, specifically the introduction of the FilterAndListVendors function in pkg/list/list_vendor.go, are related to the modifications in the retrieved PR that enhance URI handling in the internal/exec/vendor_utils.go, as both involve processing vendor configurations and handling errors related to vendor data.

Suggested labels

minor

Suggested reviewers

  • aknysh
  • kevcube

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
pkg/list/list_vendor.go (1)

142-144: Sorting strategy could be refined.
Using strings.Join on row columns might not match expected sorting on individual fields.

cmd/list_vendor.go (1)

55-59: Consider direct test coverage.
You may add an integration or CLI test for this command’s flow to ensure consistency.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a6fb9e6 and 13a0665.

📒 Files selected for processing (4)
  • cmd/list_vendor.go (1 hunks)
  • pkg/list/list_vendor.go (1 hunks)
  • pkg/list/list_vendor_test.go (1 hunks)
  • pkg/schema/schema.go (1 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
pkg/list/list_vendor_test.go

111-111: Error return value of os.Chdir is not checked

(errcheck)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: Summary
🔇 Additional comments (6)
pkg/list/list_vendor.go (2)

21-27: Struct layout looks congruent.
No apparent issues with the VendorInfo fields or JSON annotations.


44-55: Validate source component references.
Consider verifying source.Component is non-empty to avoid potential folder creation issues.

cmd/list_vendor.go (1)

15-23: Command usage is concise.
Arguments and examples are clear, supporting multiple formats.

pkg/list/list_vendor_test.go (2)

18-240: Test coverage is thorough.
Your table-driven tests ensure multiple vendor formats are well-exercised.

🧰 Tools
🪛 golangci-lint (1.62.2)

111-111: Error return value of os.Chdir is not checked

(errcheck)


111-111: Defer’s error return is unchecked.
It might be prudent to catch os.Chdir(currentDir) errors in a deferred function.

Proposed fix:

-	defer os.Chdir(currentDir)
+	defer func() {
+		if err := os.Chdir(currentDir); err != nil {
+			t.Logf("Error returning to original directory: %v", err)
+		}
+}()
🧰 Tools
🪛 golangci-lint (1.62.2)

111-111: Error return value of os.Chdir is not checked

(errcheck)

pkg/schema/schema.go (1)

637-638: LGTM! Clean addition of vendor list configuration.

The addition of the List field to the Vendor struct is well-structured and consistent with the existing codebase pattern, reusing the ListConfig type that's already used by the Workflows struct. The field is properly tagged for YAML, JSON, and mapstructure serialization.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 1, 2025
@mergify mergify bot removed the triage Needs triage label Feb 1, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 1, 2025
@mergify mergify bot removed the triage Needs triage label Feb 1, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
pkg/list/list_vendor_test.go (2)

18-28: Consider extracting test setup into a helper function.

The test setup code is well-structured, but extracting it into a helper function would improve reusability for future test cases.

+func setupTestEnvironment(t *testing.T) (string, func()) {
+    tmpDir, err := os.MkdirTemp("", "vendor_test")
+    require.NoError(t, err)
+    
+    // Create vendor directory structure
+    vendorDir := filepath.Join(tmpDir, "vendor.d")
+    err = os.MkdirAll(vendorDir, 0o755)
+    require.NoError(t, err)
+    
+    return tmpDir, func() {
+        os.RemoveAll(tmpDir)
+    }
+}
+
 func TestListVendors(t *testing.T) {
-    // Create a temporary directory for test files
-    tmpDir, err := os.MkdirTemp("", "vendor_test")
-    require.NoError(t, err)
-    defer os.RemoveAll(tmpDir)
-
-    // Create vendor directory structure
-    vendorDir := filepath.Join(tmpDir, "vendor.d")
-    err = os.MkdirAll(vendorDir, 0o755)
-    require.NoError(t, err)
+    tmpDir, cleanup := setupTestEnvironment(t)
+    defer cleanup()

136-235: Consider adding edge cases to the test suite.

The test cases are well-structured, but consider adding these scenarios:

  1. Empty vendor configuration
  2. Invalid format string
  3. Missing required columns
  4. Special characters in component names

I can help generate the additional test cases if you'd like.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0a99336 and c7c97a2.

📒 Files selected for processing (1)
  • pkg/list/list_vendor_test.go (1 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
pkg/list/list_vendor_test.go

134-134: Error return value of os.Chdir is not checked

(errcheck)

⏰ Context from checks skipped due to timeout of 90000ms (21)
  • GitHub Check: [mock-macos] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-macos] examples/demo-vendoring
  • GitHub Check: [mock-macos] examples/demo-context
  • GitHub Check: [mock-macos] examples/demo-component-versions
  • GitHub Check: [mock-macos] examples/demo-atlantis
  • GitHub Check: [mock-windows] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-windows] examples/demo-vendoring
  • GitHub Check: [mock-windows] examples/demo-context
  • GitHub Check: [mock-windows] examples/demo-component-versions
  • GitHub Check: [mock-windows] examples/demo-atlantis
  • GitHub Check: [mock-linux] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-linux] examples/demo-vendoring
  • GitHub Check: [mock-linux] examples/demo-context
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: [mock-linux] examples/demo-component-versions
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: [k3s] demo-helmfile
  • GitHub Check: [localstack] demo-localstack
  • GitHub Check: Docker Lint
  • GitHub Check: Summary
🔇 Additional comments (2)
pkg/list/list_vendor_test.go (2)

1-16: LGTM! Well-organized imports.

The imports are properly organized and include all necessary packages for testing, including JSON handling, file operations, and testing utilities.


237-263: LGTM! Robust test execution.

The test execution follows Go's table-driven test pattern with proper error handling and validation.

pkg/list/list_vendor_test.go Outdated Show resolved Hide resolved
pkg/list/list_vendor.go Outdated Show resolved Hide resolved
pkg/list/list_vendor.go Outdated Show resolved Hide resolved
pkg/list/list_vendor.go Outdated Show resolved Hide resolved
@osterman
Copy link
Member

osterman commented Feb 1, 2025

image

Note, csv stands for "Comma Separated Values", but we default to tab. Maybe we should have tsv and csv as presets, and accept --delimiter for everything else.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
pkg/list/list_vendor.go (3)

21-28: Add field documentation for better code maintainability.

While the struct itself is documented, adding documentation for each field would improve code maintainability.

 // VendorInfo represents a vendor configuration entry
 type VendorInfo struct {
+    // Component is the name of the vendor component
     Component string `json:"component"`
+    // Type indicates the type of vendor configuration
     Type      string `json:"type"`
+    // Manifest is the path to the vendor manifest file
     Manifest  string `json:"manifest"`
+    // Folder is the path to the component folder
     Folder    string `json:"folder"`
+    // Version specifies the version of the vendor component
     Version   string `json:"version"`
 }

144-147: Improve sort function reliability.

The current sort implementation could produce unexpected results when the delimiter appears in the data.

-    sort.Slice(rows, func(i, j int) bool {
-        return strings.Join(rows[i], delimiter) < strings.Join(rows[j], delimiter)
-    })
+    sort.Slice(rows, func(i, j int) bool {
+        // Compare by component first, then by type
+        if rows[i][0] != rows[j][0] {
+            return rows[i][0] < rows[j][0]
+        }
+        return rows[i][1] < rows[j][1]
+    })

171-188: Extract table styling logic for better maintainability.

The table styling code should be extracted into a separate function for better organization.

+func createStyledTable(header []string, rows [][]string) string {
+    t := table.New().
+        Border(lipgloss.ThickBorder()).
+        BorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color(theme.ColorBorder))).
+        StyleFunc(func(row, col int) lipgloss.Style {
+            style := lipgloss.NewStyle().PaddingLeft(1).PaddingRight(1)
+            if row == 0 {
+                return style.Inherit(theme.Styles.CommandName).Align(lipgloss.Center)
+            }
+            return style.Inherit(theme.Styles.Description)
+        }).
+        Headers(header...).
+        Rows(rows...)
+    return t.String() + utils.GetLineEnding()
+}
+
 // In FilterAndListVendors:
     if format == "" && exec.CheckTTYSupport() {
-        // Create a styled table for TTY
-        t := table.New().
-            Border(lipgloss.ThickBorder()).
-            // ... rest of the table styling code ...
-        return t.String() + utils.GetLineEnding(), nil
+        return createStyledTable(header, rows), nil
     }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7c97a2 and 359802a.

📒 Files selected for processing (2)
  • pkg/list/list_vendor.go (1 hunks)
  • pkg/list/list_vendor_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/list/list_vendor_test.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (1)
pkg/list/list_vendor.go (1)

1-19: LGTM! Well-organized imports.

The imports are properly organized and all are being used in the code.

pkg/list/list_vendor.go Outdated Show resolved Hide resolved
pkg/list/list_vendor.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
pkg/list/list_workflows.go (2)

26-26: Consider enhancing format-specific delimiter handling.

The addition of FormatTSV is a good step, but we should ensure consistent delimiter handling between CSV and TSV formats.

Consider defining format-specific delimiters as constants and using them in the format handling logic:

 const (
 	FormatTable = "table"
 	FormatJSON  = "json"
 	FormatCSV   = "csv"
 	FormatTSV   = "tsv"
+	DelimiterCSV = ","
+	DelimiterTSV = "\t"
 )

Also applies to: 34-34


192-199: Enhance format-specific output handling.

The current implementation uses the same logic for both CSV and TSV formats. Consider separating these cases to handle format-specific requirements.

Consider updating the format handling:

 	switch format {
 	case "json":
 		// ... existing JSON handling ...
 	case "csv":
-		// Use the provided delimiter for CSV output
+		// Use comma delimiter for CSV unless custom delimiter provided
+		csvDelimiter := DelimiterCSV
+		if delimiter != "" {
+			csvDelimiter = delimiter
+		}
 		var output strings.Builder
-		output.WriteString(strings.Join(header, delimiter) + utils.GetLineEnding())
+		output.WriteString(strings.Join(header, csvDelimiter) + utils.GetLineEnding())
 		for _, row := range rows {
-			output.WriteString(strings.Join(row, delimiter) + utils.GetLineEnding())
+			output.WriteString(strings.Join(row, csvDelimiter) + utils.GetLineEnding())
 		}
 		return output.String(), nil
+	case "tsv":
+		// Use tab delimiter for TSV unless custom delimiter provided
+		tsvDelimiter := DelimiterTSV
+		if delimiter != "" {
+			tsvDelimiter = delimiter
+		}
+		var output strings.Builder
+		output.WriteString(strings.Join(header, tsvDelimiter) + utils.GetLineEnding())
+		for _, row := range rows {
+			output.WriteString(strings.Join(row, tsvDelimiter) + utils.GetLineEnding())
+		}
+		return output.String(), nil
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 359802a and 32eb1e8.

📒 Files selected for processing (3)
  • cmd/list_vendor.go (1 hunks)
  • pkg/list/list_vendor.go (1 hunks)
  • pkg/list/list_workflows.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/list/list_vendor.go
  • cmd/list_vendor.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 2, 2025
@mergify mergify bot removed the triage Needs triage label Feb 2, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
pkg/list/list_vendor.go (1)

94-254: LGTM! Consider enhancing error messages.

The implementation handles output formats and delimiters well, aligning with the PR objectives.

Consider enhancing error messages with more context:

-        return "", fmt.Errorf("error initializing CLI config: %w", err)
+        return "", fmt.Errorf("failed to initialize CLI config while listing vendors: %w", err)
website/docs/cli/commands/list/list-vendor.mdx (1)

1-108: Enhance documentation readability with consistent typography.

The documentation is comprehensive and well-structured.

Apply these typographical improvements:

-The type of the vendor manifest (always "Vendor Manifest")
+The type of the vendor manifest (always "Vendor Manifest")

-[atmos vendor pull](/cli/commands/vendor/usage) - Pull vendored components
+[atmos vendor pull](/cli/commands/vendor/usage) — Pull vendored components

-[atmos vendor push](/cli/commands/vendor/usage) - Push vendored components
+[atmos vendor push](/cli/commands/vendor/usage) — Push vendored components

-[atmos list components](/cli/commands/list/components) - List available components
+[atmos list components](/cli/commands/list/components) — List available components
🧰 Tools
🪛 LanguageTool

[typographical] ~61-~61: Consider using typographic quotation marks here.
Context: ...The type of the vendor manifest (always "Vendor Manifest") - Manifest: The path to the vendor m...

(EN_QUOTES)


[typographical] ~106-~106: To join two clauses or introduce examples, consider using an em dash.
Context: ...vendor pull](/cli/commands/vendor/usage) - Pull vendored components - [atmos vendor...

(DASH_RULE)


[typographical] ~107-~107: To join two clauses or introduce examples, consider using an em dash.
Context: ...vendor push](/cli/commands/vendor/usage) - Push vendored components - [atmos list c...

(DASH_RULE)


[typographical] ~108-~108: To join two clauses or introduce examples, consider using an em dash.
Context: ...mponents](/cli/commands/list/components) - List available components

(DASH_RULE)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26ded60 and 705f5dc.

📒 Files selected for processing (3)
  • internal/exec/vendor_utils.go (3 hunks)
  • pkg/list/list_vendor.go (1 hunks)
  • website/docs/cli/commands/list/list-vendor.mdx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
website/docs/cli/commands/list/list-vendor.mdx

[typographical] ~61-~61: Consider using typographic quotation marks here.
Context: ...The type of the vendor manifest (always "Vendor Manifest") - Manifest: The path to the vendor m...

(EN_QUOTES)


[typographical] ~106-~106: To join two clauses or introduce examples, consider using an em dash.
Context: ...vendor pull](/cli/commands/vendor/usage) - Pull vendored components - [atmos vendor...

(DASH_RULE)


[typographical] ~107-~107: To join two clauses or introduce examples, consider using an em dash.
Context: ...vendor push](/cli/commands/vendor/usage) - Push vendored components - [atmos list c...

(DASH_RULE)


[typographical] ~108-~108: To join two clauses or introduce examples, consider using an em dash.
Context: ...mponents](/cli/commands/list/components) - List available components

(DASH_RULE)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (3)
pkg/list/list_vendor.go (2)

1-23: LGTM! Well-organized imports and constants.

The imports are properly organized and the delimiter constants are appropriately defined.


25-92: Verify template processing for edge cases.

The template processing for targets and sources looks good, but let's ensure it handles all edge cases correctly.

Run this script to check template processing with various inputs:

✅ Verification successful

I'm not getting enough output with the previous regex command. Let's re-verify the usage of the template processing logic directly in the vendor file. We'll run a simpler search for the exec.ProcessTmpl( invocations within the file.


Template processing invocations verified in vendor logic.

The invocations for processing both target and source templates using exec.ProcessTmpl are present as expected in the file. This confirms that the template processing logic is correctly integrated.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Test template processing with various inputs including special characters and empty values

# Test: Search for template processing patterns
rg -A 5 'ProcessTmpl.*"target"|ProcessTmpl.*"source"'

Length of output: 55


Script:

#!/bin/bash
# Verify ProcessTmpl invocations in pkg/list/list_vendor.go
grep -R "exec.ProcessTmpl(" pkg/list/list_vendor.go

Length of output: 142

internal/exec/vendor_utils.go (1)

440-495: LGTM! Good addition of recursion depth limit.

The implementation of depth limiting for vendor imports is a solid defensive programming practice.

pkg/list/list_vendor.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
website/docs/cli/commands/list/list-vendor.mdx (1)

104-108: Related Commands – Minor Stylistic Suggestion
The related commands section is useful; however, consider using an em dash (—) instead of a hyphen for joining the descriptive text, per the static analysis recommendations.

🧰 Tools
🪛 LanguageTool

[typographical] ~106-~106: To join two clauses or introduce examples, consider using an em dash.
Context: ...vendor pull](/cli/commands/vendor/usage) - Pull vendored components - [atmos vendor...

(DASH_RULE)


[typographical] ~107-~107: To join two clauses or introduce examples, consider using an em dash.
Context: ...vendor push](/cli/commands/vendor/usage) - Push vendored components - [atmos list c...

(DASH_RULE)


[typographical] ~108-~108: To join two clauses or introduce examples, consider using an em dash.
Context: ...omponents](/cli/commands/list/component) - List available components

(DASH_RULE)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 705f5dc and 65f697d.

📒 Files selected for processing (1)
  • website/docs/cli/commands/list/list-vendor.mdx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
website/docs/cli/commands/list/list-vendor.mdx

[typographical] ~61-~61: Consider using typographic quotation marks here.
Context: ...The type of the vendor manifest (always "Vendor Manifest") - Manifest: The path to the vendor m...

(EN_QUOTES)


[typographical] ~106-~106: To join two clauses or introduce examples, consider using an em dash.
Context: ...vendor pull](/cli/commands/vendor/usage) - Pull vendored components - [atmos vendor...

(DASH_RULE)


[typographical] ~107-~107: To join two clauses or introduce examples, consider using an em dash.
Context: ...vendor push](/cli/commands/vendor/usage) - Push vendored components - [atmos list c...

(DASH_RULE)


[typographical] ~108-~108: To join two clauses or introduce examples, consider using an em dash.
Context: ...omponents](/cli/commands/list/component) - List available components

(DASH_RULE)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Build (macos-latest, macos)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: website-deploy-preview
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
🔇 Additional comments (8)
website/docs/cli/commands/list/list-vendor.mdx (8)

1-4: YAML Header is Well-Formatted
The front matter correctly sets the title and ID for the documentation page.


6-9: Command Heading and Introduction Clarity
The title and introductory text clearly explain the purpose of the atmos list vendor command.


10-14: Usage Section Readability
The usage example is concise and easy to follow. It provides a simple guide on how to invoke the command with flags.


16-24: Detailed Command Description
This section effectively outlines what the command does and highlights the key pieces of information—such as component names, versions, folders, and source repositories—that users can expect.


25-30: Default Columns Information
The list of default columns is clearly presented. The information is helpful for users to understand the standard output layout.


56-63: Available Columns List is Clear
The list of available columns is comprehensive and effectively mirrors the configuration options provided above.

🧰 Tools
🪛 LanguageTool

[typographical] ~61-~61: Consider using typographic quotation marks here.
Context: ...The type of the vendor manifest (always "Vendor Manifest") - Manifest: The path to the vendor m...

(EN_QUOTES)


66-76: Flags Section is Well Documented
The flags are clearly described, including support for both csv and tsv output formats as well as the --delimiter option. This directly addresses prior feedback and enhances usability.


77-103: Examples Section Effectiveness
The examples are illustrative and cover different output formats and the use of custom delimiters. They provide practical guidance that users can follow without ambiguity.

website/docs/cli/commands/list/list-vendor.mdx Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
website/docs/cli/commands/list/list-vendor.mdx (1)

1-108: Enhance documentation readability with consistent formatting.

The documentation is comprehensive but could benefit from some formatting improvements:

  1. Use typographic quotation marks consistently
  2. Use em dashes (—) instead of hyphens for separating related commands
  3. Consider adding "of" in list descriptions:
    • "List of vendored components in JSON format"
    • "List of vendored components in TSV format"
-The type of the vendor manifest (always "Vendor Manifest")
+The type of the vendor manifest (always "Vendor Manifest")

-[atmos vendor pull](/cli/commands/vendor/usage) - Pull vendored components
+[atmos vendor pull](/cli/commands/vendor/usage) — Pull vendored components

-List vendored components in JSON format:
+List of vendored components in JSON format:
🧰 Tools
🪛 LanguageTool

[typographical] ~61-~61: Consider using typographic quotation marks here.
Context: ...The type of the vendor manifest (always "Vendor Manifest") - Manifest: The path to the vendor m...

(EN_QUOTES)


[uncategorized] ~84-~84: Possible missing preposition found.
Context: ...): shell atmos list vendor List vendored components in JSON format: ```shell atm...

(AI_HYDRA_LEO_MISSING_OF)


[uncategorized] ~94-~94: Possible missing preposition found.
Context: ...tmos list vendor --format csv List vendored components in TSV format:shell atmo...

(AI_HYDRA_LEO_MISSING_OF)


[typographical] ~106-~106: To join two clauses or introduce examples, consider using an em dash.
Context: ...vendor pull](/cli/commands/vendor/usage) - Pull vendored components - [atmos vendor...

(DASH_RULE)


[typographical] ~107-~107: To join two clauses or introduce examples, consider using an em dash.
Context: ...vendor push](/cli/commands/vendor/usage) - Push vendored components - [atmos list c...

(DASH_RULE)


[typographical] ~108-~108: To join two clauses or introduce examples, consider using an em dash.
Context: ...omponents](/cli/commands/list/component) - List available components

(DASH_RULE)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65f697d and a572d0a.

📒 Files selected for processing (3)
  • internal/exec/vendor_utils.go (3 hunks)
  • pkg/list/list_vendor.go (1 hunks)
  • website/docs/cli/commands/list/list-vendor.mdx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
website/docs/cli/commands/list/list-vendor.mdx

[typographical] ~61-~61: Consider using typographic quotation marks here.
Context: ...The type of the vendor manifest (always "Vendor Manifest") - Manifest: The path to the vendor m...

(EN_QUOTES)


[uncategorized] ~84-~84: Possible missing preposition found.
Context: ...): shell atmos list vendor List vendored components in JSON format: ```shell atm...

(AI_HYDRA_LEO_MISSING_OF)


[uncategorized] ~94-~94: Possible missing preposition found.
Context: ...tmos list vendor --format csv List vendored components in TSV format:shell atmo...

(AI_HYDRA_LEO_MISSING_OF)


[typographical] ~106-~106: To join two clauses or introduce examples, consider using an em dash.
Context: ...vendor pull](/cli/commands/vendor/usage) - Pull vendored components - [atmos vendor...

(DASH_RULE)


[typographical] ~107-~107: To join two clauses or introduce examples, consider using an em dash.
Context: ...vendor push](/cli/commands/vendor/usage) - Push vendored components - [atmos list c...

(DASH_RULE)


[typographical] ~108-~108: To join two clauses or introduce examples, consider using an em dash.
Context: ...omponents](/cli/commands/list/component) - List available components

(DASH_RULE)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (5)
pkg/list/list_vendor.go (4)

94-140: LGTM! Well-structured initialization.

The function properly validates formats, handles delimiters, and sets up default columns with good error handling.


142-181: LGTM! Robust file handling implementation.

The code properly handles both file and directory cases with appropriate error messages and path processing.


25-92: 🛠️ Refactor suggestion

Add input validation and improve path handling.

The function should validate inputs and ensure consistent path handling across different platforms.

 func processVendorFile(filePath string, atmosConfig schema.AtmosConfiguration) ([]schema.AtmosVendorSource, error) {
+    if filePath == "" {
+        return nil, fmt.Errorf("filePath cannot be empty")
+    }
+    if atmosConfig.BasePath == "" {
+        return nil, fmt.Errorf("atmosConfig.BasePath cannot be empty")
+    }
+
+    // Ensure consistent path format
+    filePath = filepath.Clean(filepath.ToSlash(filePath))
     var vendors []schema.AtmosVendorSource

Likely invalid or redundant comment.


183-302: 🛠️ Refactor suggestion

Implement separate CSV and TSV formats with configurable delimiters.

Based on the PR feedback, we should distinguish between CSV and TSV formats and allow custom delimiters.

 switch format {
 case FormatJSON:
     // ... existing JSON handling ...
 case FormatCSV:
+    if delimiter == "" {
+        delimiter = DefaultCSVDelimiter
+    }
+    var output strings.Builder
+    output.WriteString(strings.Join(header, delimiter) + utils.GetLineEnding())
+    for _, row := range rows {
+        output.WriteString(strings.Join(row, delimiter) + utils.GetLineEnding())
+    }
+    return output.String(), nil
+case FormatTSV:
+    if delimiter == "" {
+        delimiter = DefaultTSVDelimiter
+    }
     var output strings.Builder
     output.WriteString(strings.Join(header, delimiter) + utils.GetLineEnding())
     for _, row := range rows {
         output.WriteString(strings.Join(row, delimiter) + utils.GetLineEnding())
     }
     return output.String(), nil

Likely invalid or redundant comment.

internal/exec/vendor_utils.go (1)

440-454: LGTM! Good protection against deeply nested imports.

The addition of depth checking prevents stack overflow issues while processing vendor imports.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 5, 2025
@mergify mergify bot removed the triage Needs triage label Feb 5, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
pkg/list/list_vendor.go (3)

1-2: Add package documentation.

Consider adding a package-level documentation comment to describe the purpose and functionality of the list package.

Add this documentation above the package declaration:

+// Package list provides functionality for listing and formatting Atmos configurations,
+// including vendor configurations, in various output formats (table, JSON, CSV, TSV).
 package list

217-229: Optimize template data map creation.

Consider extracting the data map creation to a separate function to improve readability and reusability.

+func createVendorTemplateData(vendor schema.AtmosVendorSource, atmosConfig schema.AtmosConfiguration) map[string]interface{} {
+    data := map[string]interface{}{
+        "Component":           vendor.Component,
+        "Version":            vendor.Version,
+        "Type":               "Vendor Manifest",
+        "File":               vendor.File,
+        "Source":             vendor.Source,
+        "Target":             "",
+        "Tags":               vendor.Tags,
+        "atmos_component":    vendor.Component,
+        "atmos_vendor_type":  "Vendor Manifest",
+        "atmos_vendor_file":  vendor.File,
+        "atmos_vendor_target": "",
+    }
+
+    if len(vendor.Targets) > 0 {
+        target := filepath.Join(atmosConfig.BasePath, vendor.Targets[0])
+        data["Target"] = target
+        data["atmos_vendor_target"] = target
+    }
+
+    return data
+}

249-258: Consider using sort.Slice with a more efficient comparison.

The current sorting implementation compares all columns for each row. Consider implementing a more efficient comparison that stops at the first difference.

-sort.Slice(rows, func(i, j int) bool {
-    for col := 0; col < len(rows[i]); col++ {
-        if rows[i][col] != rows[j][col] {
-            return rows[i][col] < rows[j][col]
-        }
-    }
-    return false
-})
+sort.Slice(rows, func(i, j int) bool {
+    // Compare only the first column (usually Component) for better performance
+    if rows[i][0] != rows[j][0] {
+        return rows[i][0] < rows[j][0]
+    }
+    // If first column is equal, compare second column
+    if len(rows[i]) > 1 && rows[i][1] != rows[j][1] {
+        return rows[i][1] < rows[j][1]
+    }
+    return false
+})
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a572d0a and 4c5e0ef.

📒 Files selected for processing (2)
  • pkg/list/list_vendor.go (1 hunks)
  • pkg/list/list_vendor_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/list/list_vendor_test.go
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: [mock-macos] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-macos] examples/demo-vendoring
  • GitHub Check: [mock-windows] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-windows] examples/demo-vendoring
  • GitHub Check: [mock-windows] examples/demo-context
  • GitHub Check: [mock-windows] examples/demo-component-versions
  • GitHub Check: [mock-linux] tests/fixtures/scenarios/complete
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: [localstack] demo-localstack
  • GitHub Check: [k3s] demo-helmfile
  • GitHub Check: Summary
🔇 Additional comments (1)
pkg/list/list_vendor.go (1)

25-92: LGTM! Proper use of existing vendoring logic.

The implementation correctly utilizes the existing vendoring infrastructure through exec.ReadAndProcessVendorConfigFile and exec.ProcessVendorImports, maintaining consistency with the established vendoring system.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 5, 2025
@mergify mergify bot removed the triage Needs triage label Feb 5, 2025
@Cerebrovinny Cerebrovinny requested a review from osterman February 5, 2025 11:54
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
internal/exec/vendor_utils.go (1)

440-454: Consider making maxDepth configurable.

While the implementation of depth limit is a good safeguard against stack overflow, consider making the maxDepth configurable through CLI flags or configuration file to accommodate different use cases.

 func ProcessVendorImports(
     atmosConfig schema.AtmosConfiguration,
     vendorConfigFile string,
     imports []string,
     sources []schema.AtmosVendorSource,
     allImports []string,
     depth int,
-    maxDepth int,
+    maxDepth int, // TODO: Make this configurable via CLI flags or config file
 ) ([]schema.AtmosVendorSource, []string, error) {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c5e0ef and f98652b.

📒 Files selected for processing (1)
  • internal/exec/vendor_utils.go (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (2)
internal/exec/vendor_utils.go (2)

279-287: LGTM! Good defensive programming with depth limits.

The addition of depth parameters (0 for initial depth, 50 for max depth) helps prevent stack overflow from deeply nested imports.


481-482: LGTM! Proper depth tracking in recursive call.

The recursive call correctly increments the depth counter and passes the maxDepth parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Needs triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants