Skip to content

refactor: complete_filename to reduce cognitive complexity - #177

Open
bhagathkrishnacdac wants to merge 1 commit into
omec-project:mainfrom
bhagathkrishnacdac:bess-refactore-commands
Open

refactor: complete_filename to reduce cognitive complexity#177
bhagathkrishnacdac wants to merge 1 commit into
omec-project:mainfrom
bhagathkrishnacdac:bess-refactore-commands

Conversation

@bhagathkrishnacdac

Copy link
Copy Markdown

Summary
This PR refactors commands.py to address code quality and cognitive complexity. This specific change modularizes the filename auto-completion logic used by the CLI.

Key Changes

  • Extracted Visibility Filter: Introduced _visible_candidate to isolate dotfile exclusion rules and check against allowed filenames (is_allowed_filename).
  • Extracted Pattern Matcher: Introduced _process_file_match to handle shell glob pattern matching and suffix stripping.
  • Simplified Main Function: Refactored complete_filename to focus strictly on resolving directory paths and orchestrating the file-system scan loop.

Signed-off-by: bhagathkrishnacdac <bhagath.krishna@cdac.in>

Copilot AI 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.

Pull request overview

This PR refactors complete_filename in bessctl/commands.py to reduce cognitive complexity by extracting the visibility rules and filename pattern/suffix handling into helper functions, while keeping the main function focused on path resolution and iteration.

Changes:

  • Added _visible_candidate() to centralize dotfile visibility and is_allowed_filename() filtering.
  • Added _process_file_match() to encapsulate fnmatch matching plus optional suffix stripping.
  • Simplified complete_filename() to orchestrate directory scanning and candidate construction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bessctl/commands.py
Comment on lines +174 to +175
def complete_filename(partial_word, start_dir='', suffix='', skip_suffix=False):
"""Refactored complete_filename with Cognitive Complexity < 10."""

@gab-arrobo gab-arrobo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, I get empty trailing whitespaces

pr.patch:20: trailing whitespace.

pr.patch:47: trailing whitespace.

pr.patch:50: trailing whitespace.

pr.patch:59: trailing whitespace.

pr.patch:76: trailing whitespace.

warning: 5 lines add whitespace errors.

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.

3 participants