|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2002-2021, the original author or authors. |
| 2 | + * Copyright (c) 2002-2022, the original author or authors. |
3 | 3 | *
|
4 | 4 | * This software is distributable under the BSD license. See the terms of the
|
5 | 5 | * BSD license in the documentation provided with this software.
|
@@ -110,33 +110,51 @@ public static void nano(Terminal terminal, PrintStream out, PrintStream err,
|
110 | 110 |
|
111 | 111 | public static void less(Terminal terminal, InputStream in, PrintStream out, PrintStream err,
|
112 | 112 | Path currentDir,
|
113 |
| - String[] argv) throws Exception { |
| 113 | + Object[] argv) throws Exception { |
114 | 114 | less(terminal, in, out, err, currentDir, argv, null);
|
115 | 115 | }
|
116 | 116 |
|
117 | 117 | public static void less(Terminal terminal, InputStream in, PrintStream out, PrintStream err,
|
118 | 118 | Path currentDir,
|
119 |
| - String[] argv, |
| 119 | + Object[] argv, |
120 | 120 | ConfigurationPath configPath) throws Exception {
|
121 | 121 | Options opt = Options.compile(Less.usage()).parse(argv);
|
122 | 122 | if (opt.isSet("help")) {
|
123 | 123 | throw new HelpException(opt.usage());
|
124 | 124 | }
|
125 | 125 | Less less = new Less(terminal, currentDir, opt, configPath);
|
126 | 126 | List<Source> sources = new ArrayList<>();
|
127 |
| - if (opt.args().isEmpty()) { |
128 |
| - opt.args().add("-"); |
129 |
| - } |
130 |
| - for (String arg : opt.args()) { |
131 |
| - arg = arg.startsWith("~") ? arg.replace("~", System.getProperty("user.home")) : arg; |
132 |
| - if ("-".equals(arg)) { |
133 |
| - sources.add(new StdInSource(in)); |
134 |
| - } else if (arg.contains("*") || arg.contains("?")) { |
135 |
| - for (Path p: findFiles(currentDir, arg)) { |
136 |
| - sources.add(new URLSource(p.toUri().toURL(), p.toString())); |
| 127 | + if (opt.argObjects().isEmpty()) { |
| 128 | + opt.argObjects().add("-"); |
| 129 | + } |
| 130 | + |
| 131 | + for (Object o : opt.argObjects()) { |
| 132 | + if (o instanceof String) { |
| 133 | + String arg = (String)o; |
| 134 | + arg = arg.startsWith("~") ? arg.replace("~", System.getProperty("user.home")) : arg; |
| 135 | + if ("-".equals(arg)) { |
| 136 | + sources.add(new StdInSource(in)); |
| 137 | + } else if (arg.contains("*") || arg.contains("?")) { |
| 138 | + for (Path p : findFiles(currentDir, arg)) { |
| 139 | + sources.add(new URLSource(p.toUri().toURL(), p.toString())); |
| 140 | + } |
| 141 | + } else { |
| 142 | + sources.add(new URLSource(currentDir.resolve(arg).toUri().toURL(), arg)); |
137 | 143 | }
|
| 144 | + } else if (o instanceof Source) { |
| 145 | + sources.add((Source) o); |
138 | 146 | } else {
|
139 |
| - sources.add(new URLSource(currentDir.resolve(arg).toUri().toURL(), arg)); |
| 147 | + ByteArrayInputStream bais = null; |
| 148 | + if (o instanceof String[]) { |
| 149 | + bais = new ByteArrayInputStream(String.join("\n", (String[])o).getBytes()); |
| 150 | + } else if (o instanceof ByteArrayInputStream) { |
| 151 | + bais = (ByteArrayInputStream)o; |
| 152 | + } else if (o instanceof byte[]) { |
| 153 | + bais = new ByteArrayInputStream((byte[])o); |
| 154 | + } |
| 155 | + if (bais != null) { |
| 156 | + sources.add(new Source.InputStreamSource(bais, true, "Less")); |
| 157 | + } |
140 | 158 | }
|
141 | 159 | }
|
142 | 160 | less.run(sources);
|
|
0 commit comments