mufeedvh / code2prompt

A CLI tool to convert your codebase into a single LLM prompt with source tree, prompt templating, and token counting.
MIT License
1.45k stars 77 forks source link

--exclude-files and --exclude-folders Flags Not Working as Documented #8

Closed sagarspatil closed 4 months ago

sagarspatil commented 5 months ago

The --exclude-files and --exclude-folders flags, as documented in the code2prompt GitHub documentation, do not seem to function when used in the command-line interface (CLI). Attempting to use these flags results in an "unexpected argument" error, suggesting a possible discrepancy between the documentation and the tool's current CLI implementation.

Steps to Reproduce:

  1. Attempt to use code2prompt with the --exclude-files flag: This results in an error: error: unexpected argument '--exclude-files' found.

  2. Attempt to use code2prompt with the --exclude-folders flag: Similarly, this results in an error: error: unexpected argument '--exclude-folders' found.

Expected Behavior: According to the documentation, users should be able to exclude specific files and folders from the prompt generation process by using the --exclude-files and --exclude-folders flags. The expected behavior is for code2prompt to accept these flags without error and to exclude the specified files and folders accordingly.

Actual Behavior: The tool does not recognize the --exclude-files and --exclude-folders flags, resulting in an "unexpected argument" error message. This discrepancy between the documentation and the tool's behavior suggests a bug in the CLI implementation of these features.

Environment: code2prompt version: 1.0.0 Operating System: (e.g., Ubuntu 20.04) Shell: (e.g., bash, zsh)

ngirard commented 4 months ago

Unless I'm misunderstood, this feature hasn't been released yet. I too would benefit from it. @mufeedvh, could you please consider publishing a new release ?

xsayedmahmud commented 4 months ago

@mufeedvh Eagerly waiting for these two features. Any ETA on a release with them?

mufeedvh commented 4 months ago

Hey @sagarspatil @ngirard @xsayedmahmud, just published builds for v1.1.0. 🙌 🎉

ngirard commented 4 months ago

Thank you so much, @mufeedvh !

sammcj commented 4 months ago

Thanks for this Mufeed, really appreciate it :)

sammcj commented 4 months ago

FYI if it helps anyone else, this is my big wrapper for code2prompt to give it some useful defaults:

function code2prompt() {
  # wrap the code2prompt command in a function that sets a number of default excludes
  # https://github.com/mufeedvh/code2prompt/
  local arguments
  local excludeFiles
  local excludeFolders
  local excludeExtensions
  local templatesFolder
  templatesFolder="${HOME}/git/code2prompt/templates"
  excludeFiles=".editorconfig,.eslintignore,.eslintrc,tsconfig.json,.gitignore,.npmrc,LICENSE,esbuild.config.mjs,manifest.json,package-lock.json,\
  version-bump.mjs,versions.json,yarn.lock,CONTRIBUTING.md,CHANGELOG.md,SECURITY.md,.nvmrc,.env,.env.production,.prettierrc,.prettierignore,.stylelintrc,\
  CODEOWNERS,commitlint.config.js,renovate.json,pre-commit-config.yaml,.vimrc,poetry.lock,changelog.md,contributing.md,.pretterignore,.prettierrc.json,\
  .prettierrc.yml,.prettierrc.js,.eslintrc.js,.eslintrc.json,.eslintrc.yml,.eslintrc.yaml,.stylelintrc.js,.stylelintrc.json,.stylelintrc.yml,.stylelintrc.yaml"
  excludeFolders="screenshots,dist,node_modules,.git,.vscode,build,coverage,tmp,out,temp\
  src/complete/completers/ai21,src/complete/completers/chatgpt,src/complete/completers/gooseai"
  excludeExtensions="png,jpg,jpeg,gif,svg,mp4,webm,avi,mp3,wav,flac,zip,tar,gz,bz2,7z,iso,bin,exe,app,dmg,deb,rpm,apk,fig,xd,blend,fbx,obj,tmp,swp,\
  lock,DS_Store,sqlite,log,sqlite3,dll,woff,woff2,ttf,eot,otf,ico,icns,csv,doc,docx,ppt,pptx,xls,xlsx,pdf,cmd,bat,dat,baseline"

  echo "---"
  echo "Available templates:"
  ls -1 "$templatesFolder"
  echo "---"

  echo "Excluding files: $excludeFiles"
  echo "Excluding folders: $excludeFolders"
  echo "Run with -nn to disable the default excludes"

  # array of build arguments
  arguments=("--tokens")

  # if -t and a template name is provided, append the template flag with the full path to the template to the arguments array
  if [[ $1 == "-t" ]]; then
    arguments+=("--template" "$templatesFolder/$2")
    shift 2
  fi

  if [[ $1 == "-nn" ]]; then
    command code2prompt "${arguments[@]}" "${@:2}" # remove the -nn flag
  else
    command code2prompt "${arguments[@]}" --exclude-files "$excludeFiles" --exclude-folders "$excludeFolders" --exclude "$excludeExtensions" "${*}"
  fi
}