- not accepted in FileArgument with EXISTING
Project: | JNode Shell |
Component: | Code |
Category: | feature request |
Priority: | critical |
Assigned: | Unassigned |
Status: | closed |
Jump to:
Description
This is enough a universal symbol for stdin that it should be accepted by FileArgument when the EXISTING flag is set. Commands will have to check the name, but you'd have to do that anyway.
- Login to post comments
#1
I don't think that this is implementable as you have described it. The FileArgument delivers a File value not a stream object, and there is no standard way to express "standard input" as a File.
We could do this with a combination of a new FileArgument-specific flag (EXISTING is wrong!) and some new methods on FileArgument to open the ith argument instance as various kinds of stream / reader / writer. There is also the problem of getting hold of "the standard input" from within a FileArgument method ... but I think I can figure that out.
But the big question is whether this is a feature we want to support.
#2
I just created an anonymous inner class to override doaccept if the file name was -, return new File("-"), otherwise let FileArgument accept it. I dont see why it has to be complicated. I just think it is wrong for FileArgument to be denying '-' because it makes EXISTING unusable since just about every command that accepts a list of files accepts '-'
If you added a new flag, add ALLOW_STDIN or something like that to check if the token is '-'. If it is, then allow a new File("-") to be returned, after that, existing/nonexisting can be dealt with.
#3
I think what you are proposing (and have implemented in your sandbox) is the wrong solution.
While some (GNU/Linux) commands support the "'-' means standard input" convention, others do not. For example 'cp', 'mv', 'javac', all would naturally have a (JNode) syntax where the source file(s) are FileArguments with EXISTING. But all of them would break if called with a '-' argument.
If we conclude that this is a use-case that needs to be supported by the syntax mechanisms, it needs to be done without breaking things. Specifically, it should not break the assumption that the following should always work (modulo race conditions with file deletion):
Certainly, this assumption is a reasonable one, given the definition of Argument.EXISTING that I put in the Javadocs. And it was my intention that command classes should be able to make this assumption.
Clearly, the existing definition of EXISTING is not unusable. Rather, it is not usable for the '-' case. And I would argue that the definition of EXISTING should not be changed to cover the '-' case, because that will make it weaker in other cases; see code example above, and programs listed above.
I'm not sure in my mind whether it would be best to create a new Argument type, define a new flag for FileArgument, or wait until we have a generic Argument type that supports a union of other Argument types. IMO, a new Argument type would be the simplest and cleanest approach from the perspective of people designing command classes and syntaxes.
#4
Fixed with issue #2959
#7
Closed manually