mirror of
https://github.com/kirill-markin/repo-to-text.git
synced 2025-12-05 19:12:24 -08:00
Merge pull request #35 from kirill-markin/fix-issue-26-windows-tree-command
Fix tree command for Windows
This commit is contained in:
commit
2807344752
1 changed files with 11 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ Core functionality for repo-to-text
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import platform
|
||||||
from typing import Tuple, Optional, List, Dict, Any, Set
|
from typing import Tuple, Optional, List, Dict, Any, Set
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from importlib.machinery import ModuleSpec
|
from importlib.machinery import ModuleSpec
|
||||||
|
|
@ -36,12 +37,20 @@ def get_tree_structure(
|
||||||
|
|
||||||
def run_tree_command(path: str) -> str:
|
def run_tree_command(path: str) -> str:
|
||||||
"""Run the tree command and return its output."""
|
"""Run the tree command and return its output."""
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
cmd = ["cmd", "/c", "tree", "/a", "/f", path]
|
||||||
|
else:
|
||||||
|
cmd = ["tree", "-a", "-f", "--noreport", path]
|
||||||
|
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
['tree', '-a', '-f', '--noreport', path],
|
cmd,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
|
encoding='utf-8',
|
||||||
check=True
|
check=True
|
||||||
)
|
)
|
||||||
return result.stdout.decode('utf-8')
|
return result.stdout
|
||||||
|
|
||||||
def filter_tree_output(
|
def filter_tree_output(
|
||||||
tree_output: str,
|
tree_output: str,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue