Skip to content

Commit

Permalink
Merge pull request #6339 from kmk3/build-sort-py-n
Browse files Browse the repository at this point in the history
build: sort.py: use -i by default and add -n
  • Loading branch information
kmk3 committed May 20, 2024
2 parents 812449c + a6d2119 commit 83469a3
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions contrib/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
__doc__ = f"""\
Sort the arguments of commands in profiles.
Usage: {path.basename(argv[0])} [-i] [/path/to/profile ...]
Usage: {path.basename(argv[0])} [-i] [-n] [--] [/path/to/profile ...]
The following commands are supported:
Expand All @@ -21,13 +21,15 @@
Note that this is only applicable to commands that support multiple arguments.
Options:
-i Edit the profile file(s) in-place.
-i Edit the profile file(s) in-place (this is the default).
-n Do not edit the profile file(s) in-place.
-- End of options
Examples:
$ {argv[0]} -i MyAwesomeProfile.profile
$ {argv[0]} -i new_profile.profile second_new_profile.profile
$ {argv[0]} -i ~/.config/firejail/*.{{profile,inc,local}}
$ sudo {argv[0]} -i /etc/firejail/*.{{profile,inc,local}}
$ {argv[0]} MyAwesomeProfile.profile
$ {argv[0]} new_profile.profile second_new_profile.profile
$ {argv[0]} ~/.config/firejail/*.{{profile,inc,local}}
$ sudo {argv[0]} /etc/firejail/*.{{profile,inc,local}}
Exit Codes:
0: Success: No profiles needed fixing.
Expand Down Expand Up @@ -101,10 +103,22 @@ def check_profile(filename, overwrite):


def main(args):
overwrite = False
if len(args) > 0 and args[0] == "-i":
overwrite = True
args.pop(0)
overwrite = True
while len(args) > 0:
if args[0] == "-i":
overwrite = True
args.pop(0)
elif args[0] == "-n":
overwrite = False
args.pop(0)
elif args[0] == "--":
args.pop(0)
break
elif args[0][0] == "-":
print(f"[ Error ] Unknown option: {args[0]}", file=stderr)
return 2
else:
break

if len(args) < 1:
print(__doc__, file=stderr)
Expand Down

0 comments on commit 83469a3

Please sign in to comment.