myspace-cli 1.6.0__tar.gz → 1.6.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: myspace-cli
3
- Version: 1.6.0
3
+ Version: 1.6.1
4
4
  Summary: A macOS disk space analysis CLI: health, index, app usage, big files.
5
5
  Author-email: Your Name <you@example.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "myspace-cli"
7
- version = "1.6.0"
7
+ version = "1.6.1"
8
8
  description = "A macOS disk space analysis CLI: health, index, app usage, big files."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -24,7 +24,7 @@ Homepage = "https://github.com/kennyz/space-cli"
24
24
  Issues = "https://github.com/kennyz/space-cli/issues"
25
25
 
26
26
  [project.scripts]
27
- space-cli = "space_cli:main"
27
+ space-cli = "space_cli.spacecli_class:main"
28
28
 
29
29
  [tool.setuptools.packages.find]
30
30
  where = ["src"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: myspace-cli
3
- Version: 1.6.0
3
+ Version: 1.6.1
4
4
  Summary: A macOS disk space analysis CLI: health, index, app usage, big files.
5
5
  Author-email: Your Name <you@example.com>
6
6
  License: MIT
@@ -9,4 +9,4 @@ src/myspace_cli.egg-info/top_level.txt
9
9
  src/space_cli/__init__.py
10
10
  src/space_cli/index_store.py
11
11
  src/space_cli/space_analyzer.py
12
- src/space_cli/space_cli.py
12
+ src/space_cli/spacecli_class.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ space-cli = space_cli.spacecli_class:main
@@ -5,6 +5,6 @@ SpaceCli - macOS 磁盘空间分析工具
5
5
 
6
6
  from .index_store import IndexStore
7
7
  from .space_analyzer import SpaceAnalyzer
8
- from .space_cli import SpaceCli
8
+ from .spacecli_class import SpaceCli
9
9
 
10
10
  __all__ = ['IndexStore', 'SpaceAnalyzer', 'SpaceCli']
@@ -629,4 +629,183 @@ class SpaceCli:
629
629
  json.dump(report, f, ensure_ascii=False, indent=2)
630
630
  print(f"✅ 报告已保存到: {output_file}")
631
631
  except Exception as e:
632
- print(f"❌ 保存报告失败: {e}")
632
+ print(f"❌ 保存报告失败: {e}")
633
+
634
+
635
+ def main():
636
+ """包内 CLI 入口:参数解析 + 交互菜单,执行完返回菜单"""
637
+ import argparse
638
+ from pathlib import Path
639
+ import os
640
+ import sys
641
+
642
+ parser = argparse.ArgumentParser(
643
+ description="SpaceCli - Mac OS 磁盘空间分析工具",
644
+ formatter_class=argparse.RawDescriptionHelpFormatter,
645
+ epilog="""
646
+ 示例用法:
647
+ space-cli # 菜单 + 默认执行
648
+ space-cli -p /Users # 分析用户目录
649
+ space-cli -n 10 # 显示前10个最大目录
650
+ space-cli --export report.json # 导出报告
651
+ space-cli --health-only # 只显示健康状态
652
+ """
653
+ )
654
+
655
+ parser.add_argument('-p', '--path', default='/', help='要分析的路径 (默认: /)')
656
+ parser.add_argument('--home', action='store_true', help='将分析路径设置为当前用户目录($HOME)')
657
+ parser.add_argument('-n', '--top-n', type=int, default=20, help='显示前N个最大的目录 (默认: 20)')
658
+ parser.add_argument('--health-only', action='store_true', help='只显示磁盘健康状态')
659
+ parser.add_argument('--directories-only', action='store_true', help='只显示目录分析')
660
+
661
+ # 索引相关
662
+ parser.add_argument('--use-index', dest='use_index', action='store_true', help='使用已存在的索引缓存(若存在)')
663
+ parser.add_argument('--no-index', dest='use_index', action='store_false', help='不使用索引缓存')
664
+ parser.set_defaults(use_index=True)
665
+ parser.add_argument('--reindex', action='store_true', help='强制重建索引')
666
+ parser.add_argument('--index-ttl', type=int, default=24, help='索引缓存有效期(小时),默认24小时')
667
+ parser.add_argument('--no-prompt', action='store_true', help='非交互模式:不提示是否使用缓存')
668
+
669
+ # 应用分析
670
+ parser.add_argument('--apps', action='store_true', help='显示应用目录空间分析与卸载建议')
671
+
672
+ # 大文件分析
673
+ parser.add_argument('--big-files', action='store_true', help='显示大文件分析结果')
674
+ parser.add_argument('--big-files-top', type=int, default=20, help='大文件分析显示前N个(默认20)')
675
+ parser.add_argument('--big-files-min', type=str, default='0', help='只显示大于该阈值的文件,支持K/M/G/T,如 500M、2G,默认0')
676
+
677
+ parser.add_argument('--export', metavar='FILE', help='导出分析报告到JSON文件')
678
+ parser.add_argument('--version', action='version', version='SpaceCli 1.6.0')
679
+
680
+ args = parser.parse_args()
681
+
682
+ # 解析 --big-files-min 阈值字符串到字节
683
+ def parse_size(s: str) -> int:
684
+ s = (s or '0').strip().upper()
685
+ if s.endswith('K'):
686
+ return int(float(s[:-1]) * 1024)
687
+ if s.endswith('M'):
688
+ return int(float(s[:-1]) * 1024**2)
689
+ if s.endswith('G'):
690
+ return int(float(s[:-1]) * 1024**3)
691
+ if s.endswith('T'):
692
+ return int(float(s[:-1]) * 1024**4)
693
+ try:
694
+ return int(float(s))
695
+ except ValueError:
696
+ return 0
697
+ args.big_files_min_bytes = parse_size(getattr(args, 'big_files_min', '0'))
698
+
699
+ # 单次执行
700
+ def run_once(run_args, interactive: bool = False):
701
+ if getattr(run_args, 'home', False):
702
+ run_args.path = str(Path.home())
703
+ if not os.path.exists(run_args.path):
704
+ print(f"❌ 错误: 路径 '{run_args.path}' 不存在")
705
+ if interactive:
706
+ return
707
+ sys.exit(1)
708
+ space_cli = SpaceCli()
709
+ space_cli.args = run_args
710
+ try:
711
+ space_cli.print_system_info()
712
+ if run_args.health_only:
713
+ space_cli.print_disk_health(run_args.path)
714
+ if run_args.directories_only or run_args.path != '/':
715
+ space_cli.print_largest_directories(run_args.path, run_args.top_n)
716
+ if os.path.abspath(run_args.path) == os.path.abspath(str(Path.home())):
717
+ space_cli.print_home_deep_analysis(run_args.top_n)
718
+ if run_args.apps:
719
+ space_cli.print_app_analysis(run_args.top_n)
720
+ if run_args.big_files:
721
+ space_cli.print_big_files(run_args.path, top_n=run_args.big_files_top, min_size_bytes=run_args.big_files_min_bytes)
722
+ if getattr(run_args, 'memory_cleanup', False):
723
+ space_cli.print_memory_cleanup()
724
+ if run_args.export:
725
+ space_cli.export_report(run_args.export, run_args.path)
726
+ print("=" * 60)
727
+ print("✅ 分析完成!")
728
+ print("=" * 60)
729
+ except KeyboardInterrupt:
730
+ print("\n\n❌ 用户中断操作")
731
+ if interactive:
732
+ return
733
+ sys.exit(1)
734
+ except Exception as e:
735
+ print(f"\n❌ 发生错误: {e}")
736
+ if interactive:
737
+ return
738
+ sys.exit(1)
739
+
740
+ # 交互式菜单:当未传入任何参数时触发(默认执行全部),执行后返回菜单
741
+ if len(sys.argv) == 1:
742
+ while True:
743
+ print("=" * 60)
744
+ print("🧭 SpaceCli 菜单(直接回车 = 执行全部项目)")
745
+ print("=" * 60)
746
+ home_path = str(Path.home())
747
+ # 动态获取磁盘与内存占用率
748
+ try:
749
+ analyzer_for_menu = SpaceAnalyzer()
750
+ disk_info = analyzer_for_menu.get_disk_usage('/')
751
+ disk_usage_display = f"{disk_info['usage_percent']:.1f}%" if disk_info else "未知"
752
+ sysinfo = analyzer_for_menu.get_system_info()
753
+ mem_usage_display = sysinfo.get("内存使用率", "未知")
754
+ except Exception:
755
+ disk_usage_display = "未知"
756
+ mem_usage_display = "未知"
757
+
758
+ print("1) \033[36m执行主要项目(系统信息 + 健康 + 应用)\033[0m")
759
+ print(f"2) \033[36m当前用户目录分析(路径: {home_path})\033[0m")
760
+ print("3) \033[36m仅显示系统信息\033[0m")
761
+ print(f"4) \033[36m仅显示磁盘健康状态\033[0m — 当前磁盘占用: \033[33m{disk_usage_display}\033[0m")
762
+ print("5) \033[36m交互式目录空间分析\033[0m")
763
+ print("6) \033[36m仅分析程序应用目录空间\033[0m")
764
+ print("7) \033[36m仅进行大文件分析(比较耗时,可随时终止)\033[0m")
765
+ print(f"8) \033[36m内存释放优化\033[0m — 当前内存使用率: \033[33m{mem_usage_display}\033[0m")
766
+ print("0) \033[36m退出\033[0m")
767
+ try:
768
+ choice = input("请选择 [回车=1]: ").strip()
769
+ except EOFError:
770
+ choice = ""
771
+
772
+ # 重置
773
+ args.health_only = False
774
+ args.directories_only = False
775
+ args.apps = False
776
+ args.big_files = False
777
+ args.memory_cleanup = False
778
+ args.path = '/'
779
+
780
+ if choice == "0":
781
+ sys.exit(0)
782
+ elif choice == "2":
783
+ args.path = home_path
784
+ args.directories_only = True
785
+ elif choice == "3":
786
+ pass
787
+ elif choice == "4":
788
+ args.health_only = True
789
+ elif choice == "5":
790
+ args.directories_only = True
791
+ elif choice == "6":
792
+ args.apps = True
793
+ elif choice == "7":
794
+ args.big_files = True
795
+ elif choice == "8":
796
+ args.memory_cleanup = True
797
+ else:
798
+ args.health_only = True
799
+ args.apps = True
800
+
801
+ run_once(args, interactive=True)
802
+
803
+ try:
804
+ back = input("按回车返回菜单,输入 q 退出: ").strip().lower()
805
+ except EOFError:
806
+ back = ""
807
+ if back == 'q':
808
+ sys.exit(0)
809
+ else:
810
+ # 非交互:按参数执行一次
811
+ run_once(args, interactive=False)
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- space-cli = space_cli:main
File without changes
File without changes