From 463b531bfd758fbdfb4a8e1c0e1193f147e92762 Mon Sep 17 00:00:00 2001 From: RA-Phil-K <122104365+RA-Phil-K@users.noreply.github.com> Date: Fri, 24 Nov 2023 18:40:29 +0100 Subject: [PATCH] feat: added new file list call &FILELIST. (#22) This differs from @FILELIST in that the working directory is changed to the directory of FILELIST before coging the files in the list. This has the effect that files and directiories in the FILELIST are relative to the FILELIST instead of where cog is called. Co-authored-by: Ned Batchelder --- cogapp/cogapp.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cogapp/cogapp.py b/cogapp/cogapp.py index ae76743..1514f27 100644 --- a/cogapp/cogapp.py +++ b/cogapp/cogapp.py @@ -22,11 +22,15 @@ usage = """\ cog - generate content with inlined Python code. -cog [OPTIONS] [INFILE | @FILELIST] ... +cog [OPTIONS] [INFILE | @FILELIST | &FILELIST] ... INFILE is the name of an input file, '-' will read from stdin. FILELIST is the name of a text file containing file names or -other @FILELISTs. +other @FILELISTs. + For @FILELIST, paths in the file list are relative to + the working directory where cog was called. + For &FILELIST, paths in the file list are relative to + the file list. OPTIONS: -c Checksum the output to protect it against accidental change. @@ -764,6 +768,14 @@ def processArguments(self, args): if self.options.sOutputName: raise CogUsageError("Can't use -o with @file") self.processFileList(args[0][1:]) + elif args[0][0] == '&': + if self.options.sOutputName: + raise CogUsageError("Can't use -o with @file") + saved_cwd = os.getcwd() + file_list = args[0][1:] + os.chdir(os.path.dirname(file_list)) + self.processFileList(os.path.basename(file_list)) + os.chdir(saved_cwd) else: self.processWildcards(args[0])