1- import argparse # ngit is CLI tool, so we need to parse CLI args
2-
3- # import configparser # ngit's config file uses INI format
4- # from datetime import datetime # to store time of each commit
5- # import grp, pwd # because ngit saves numerical owner/group ID of files author
6- # from fnmatch import fnmatch # to match .gitignore patterns like *.txt
7- # import hashlib # ngit uses SHA-1 hash extensively
8- # import math
9- import os # os and os.path provide some nice filesystem abstraction routines
10-
11- # import re # just a little-bit of RegEx
12- import sys # to access `sys.argv`
13- # import zlib # to compress & decompress files
1+ import argparse
2+ import os
3+ import sys
144
155from microprojects .ngit .object import GitObject , GitCommit , GitTree
166from microprojects .ngit .repository import GitRepository , repo_file , repo_find_f
17- from microprojects .ngit .repository import resolve_ref , ref_list , tag_list , GitIgnore
7+ from microprojects .ngit .repository import GitIgnore , resolve_ref , ref_list , tag_list
188from microprojects .ngit .object_utils import object_find_f , object_read , tag_create
199from microprojects .ngit .object_utils import gitignore_read , get_obj_type , get_obj_size
2010from microprojects .ngit .ngit_utils import cat_file , ls_tree , object_hash , repo_create
2111from microprojects .ngit .ngit_utils import checkout , show_ref , ls_files , check_ignore
2212from microprojects .ngit .log import print_logs
13+ from microprojects .ngit .status import filter_paths
2314
2415
2516def ngit_main () -> None :
@@ -41,6 +32,39 @@ def ngit_main() -> None:
4132 arg_subparser .required = True
4233
4334 # ArgParser for ngit add
35+ argsp_add = arg_subparser .add_parser ( # add
36+ "add" ,
37+ prog = "ngit add" ,
38+ description = "Add file contents to the index" ,
39+ help = "Add file contents to the index" ,
40+ formatter_class = argparse .RawTextHelpFormatter ,
41+ )
42+ argsp_add .add_argument ( # -f --force
43+ "-f" ,
44+ "--force" ,
45+ dest = "force" ,
46+ action = "store_true" ,
47+ help = "Allow adding otherwise ignored files" ,
48+ )
49+ argsp_add .add_argument ( # -A --all --no-ignore-removal
50+ "-A" ,
51+ "--all" ,
52+ "--no-ignore-removal" ,
53+ dest = "all" ,
54+ action = "store_true" ,
55+ help = "All files in entire worktree will be added to GitIndex" ,
56+ )
57+ argsp_add .add_argument ( # --ignore-errors
58+ "--ignore-errors" ,
59+ dest = "no_errors" ,
60+ action = "store_true" ,
61+ help = "If some files could not be added, do not abort the operation, but continue adding the others" ,
62+ )
63+ argsp_add .add_argument ( # paths
64+ "paths" ,
65+ nargs = "*" ,
66+ help = "Files to add content from" ,
67+ )
4468
4569 # ArgParser for ngit cat-file
4670 argsp_cat_file = arg_subparser .add_parser ( # cat-file
@@ -480,6 +504,54 @@ def ngit_main() -> None:
480504 )
481505
482506 # ArgParser for ngit rm
507+ argsp_rm = arg_subparser .add_parser ( # rm
508+ "rm" ,
509+ prog = "ngit rm" ,
510+ description = "Remove files from the working tree and from the index" ,
511+ help = "Remove files from the working tree and from the index" ,
512+ formatter_class = argparse .RawTextHelpFormatter ,
513+ )
514+ argsp_rm .add_argument ( # -f --force
515+ "-f" ,
516+ "--force" ,
517+ dest = "force" ,
518+ action = "store_true" ,
519+ help = "Override the up-to-date check" ,
520+ )
521+ argsp_rm .add_argument ( # -q --quiet
522+ "-q" ,
523+ "--quiet" ,
524+ dest = "quiet" ,
525+ action = "store_true" ,
526+ help = "Suppress all output except errors and warnings" ,
527+ )
528+ argsp_rm .add_argument ( # -r --recursive
529+ "-r" ,
530+ "--recursice" ,
531+ dest = "recursive" ,
532+ action = "store_true" ,
533+ help = "Allow recursive removal when a leading directory name is given" ,
534+ )
535+ argsp_rm .add_argument ( # --cached
536+ "--cached" ,
537+ dest = "cached" ,
538+ action = "store_true" ,
539+ help = "Use this option to unstage and remove paths only from the index. "
540+ "Working tree files, whether modified or not, will be left alone" ,
541+ )
542+ argsp_rm .add_argument ( # -i --stdin --pathspec-from-file
543+ "-i" ,
544+ "--stdin" ,
545+ "--pathspec-from-file" ,
546+ dest = "stdin" ,
547+ metavar = "<path>" ,
548+ help = "Pathspec is passed in <file> instead of args, if <file> is exactly - then standard input is used" ,
549+ )
550+ argsp_rm .add_argument ( # paths
551+ "paths" ,
552+ nargs = "*" ,
553+ help = "Files to add content from" ,
554+ )
483555
484556 # ArgParser for ngit show-ref
485557 argsp_show_ref = arg_subparser .add_parser ( # show-ref
@@ -563,6 +635,55 @@ def ngit_main() -> None:
563635 )
564636
565637 # ArgParser for ngit status
638+ argsp_staus = arg_subparser .add_parser (
639+ "status" ,
640+ prog = "ngit status" ,
641+ description = "Show the working tree status" ,
642+ help = "Show the working tree status" ,
643+ formatter_class = argparse .RawTextHelpFormatter ,
644+ )
645+ argsp_staus .add_argument ( # -s --short
646+ "-s" ,
647+ "--short" ,
648+ dest = "short" ,
649+ action = "store_true" ,
650+ help = "Give the output in the short-format" ,
651+ )
652+ argsp_staus .add_argument ( # -b --branch
653+ "-b" ,
654+ "--branch" ,
655+ dest = "branch" ,
656+ action = "store_true" ,
657+ help = "Show the branch and tracking info even in short-format" ,
658+ )
659+ argsp_staus .add_argument ( # --porcelain
660+ "--porcelain" ,
661+ dest = "porcelain" ,
662+ action = "store_true" ,
663+ help = "Give the output in an easy-to-parse format for scripts" ,
664+ )
665+ argsp_staus .add_argument ( # --long
666+ "--long" ,
667+ dest = "long" ,
668+ action = "store_true" ,
669+ help = "Give the output in the long-format (default)" ,
670+ )
671+ argsp_staus .add_argument ( # -u --untracked-files
672+ "-u" ,
673+ "--untracked-files" ,
674+ dest = "untracked" ,
675+ choices = ["all" , "normal" , "no" ],
676+ default = "all" ,
677+ const = "all" ,
678+ nargs = "?" ,
679+ help = "Show untracked files" ,
680+ )
681+ argsp_staus .add_argument ( # paths
682+ "paths" ,
683+ nargs = "*" ,
684+ help = "Files to add content from" ,
685+ )
686+
566687 # ArgParser for ngit tag
567688 argsp_tag = arg_subparser .add_parser (
568689 "tag" ,
0 commit comments