-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
txtar-c: add -script flag #181
Open
bitfield
wants to merge
1
commit into
rogpeppe:master
Choose a base branch
from
bitfield:txtar-c-script
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
unquote expect | ||
# With the -script flag, it should include the contents of test.txtar as a comment | ||
exec txtar-c -script test.txtar blah | ||
cmp stdout expect | ||
|
||
-- test.txtar -- | ||
exec echo hello | ||
|
||
-- blah/go.mod -- | ||
module example.com/blah | ||
|
||
-- blah/main.go -- | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("Hello, world!") | ||
} | ||
|
||
-- expect -- | ||
>exec echo hello | ||
> | ||
>-- go.mod -- | ||
>module example.com/blah | ||
> | ||
>-- main.go -- | ||
>package main | ||
> | ||
>import "fmt" | ||
> | ||
>func main() { | ||
> fmt.Println("Hello, world!") | ||
>} | ||
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
unquote expect | ||
unquote blah/needsquote.txtar | ||
# With both -script and -quote, it should include test.txtar after any 'unquote's | ||
exec txtar-c -quote -script test.txtar blah | ||
cmp stdout expect | ||
|
||
-- test.txtar -- | ||
exec echo hello | ||
|
||
-- blah/go.mod -- | ||
module example.com/blah | ||
|
||
-- blah/main.go -- | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("Hello, world!") | ||
} | ||
|
||
-- blah/needsquote.txtar -- | ||
>-- file_entry.txt -- | ||
|
||
-- expect -- | ||
>unquote needsquote.txtar | ||
>exec echo hello | ||
> | ||
>-- go.mod -- | ||
>module example.com/blah | ||
> | ||
>-- main.go -- | ||
>package main | ||
> | ||
>import "fmt" | ||
> | ||
>func main() { | ||
> fmt.Println("Hello, world!") | ||
>} | ||
> | ||
>-- needsquote.txtar -- | ||
>>-- file_entry.txt -- | ||
>> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the scenario when the
-script
argument contains unquote lines itself?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I see what you mean. Could you say a little more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
He means that if the script file contains txtar syntax, like
-- foo --
, then it will leak out of the comment section and affect the rest of the txtar.The flag should probably reject those scripts, because I don't think there is any easy quoting or escaping we can reach for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I still don't get it. Could you give an example of a script which would produce the wrong result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I actually misunderstood what Paul said, so ignore me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming I have gotten the quoting right:
Which also points out that in this PR only the comment in the
-script
argument is used. Which seems quite specific. Was that intentional?txtar
files don't naturally compose as far as I can see, hence my question is really directed at questioning whether this could be adequately solved in a purpose built program, rather than trying to adapttxtar-c
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does fail, but only because the script produces an extra unexpected blank line—is that what you meant?
I'm not sure I understand the question. If you mean "only the comment part of the script makes it into the resulting
txtar
, ignoring any file inclusions", that's not the case. The whole of the file referenced by-script FILE
is included, and if it contains file inclusions, they will end up in the finaltxtar
too. At least, that was the intention.If you mean "only the comment part of the resulting
txtar
is modified, by including the script in it", that's correct, but I can't think of an alternative way of doing this that would make sense.Certainly it could.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually misread the code. As you say, the entire file passed to
-script
is included afterunquote
lines that are added bytxtar-c
. What threw me is that the contents of this file are added to the new archive's comments, even though that[]byte
contains files as interpreted bytxtar
.Here's a case where I think things go wrong:
The double
unquote
ofneedsquote.txtar
is incorrect; there should only be oneunquote
.The flag name
-script
is also a bit of a smell for me here.txtar-c
is a command that is only concerned with thetxtar
format. It knows nothing abouttestscript
. If we take the name "script" away, we are effectively passing in anothertxtar
archive as the argument here. In that case, how would you describe the operation we are performing on what are twotxtar
archives? Merge? Append?My sense is that we're struggling to define what this operation between two
txtar
archives is here. And as I said, I think that comes down to the fact that in the general case, operations on archives are not well defined: they don't compose, prepend, append etc. Hence I feel this probably belongs as a purpose-built tool for your situation, rather than something that is generally useful intxtar-c
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's perfectly fair—and I have exactly that tool, which is working perfectly for my use case. (It is, in fact, just vanilla
txtar-c
with this patch applied.)I feel the sense of the meeting is that while a feature like this might be occasionally useful, to provide a really robust solution that works in theory, as well as merely in practice, would take a fair bit more work, if it's even possible at all. Accordingly, please close, with my thanks.