Skip to content

Commit

Permalink
feat: added new file list call &FILELIST. (#22)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
RA-Phil-K and nedbat authored Nov 24, 2023
1 parent dca3f2c commit 463b531
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cogapp/cogapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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])

Expand Down

0 comments on commit 463b531

Please sign in to comment.