blob: 20c8180b4b6aed920fb2237d8fce5bffec82b6bf [file] [log] [blame]
Yuta HIGUCHI7d7d46e2017-08-29 12:19:10 -07001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.cli;
17
18import java.io.IOException;
19import java.io.InputStreamReader;
20
Ray Milkeyd84f89b2018-08-17 14:54:17 -070021import org.apache.karaf.shell.api.action.Command;
22import org.apache.karaf.shell.api.action.lifecycle.Service;
Yuta HIGUCHI7d7d46e2017-08-29 12:19:10 -070023import org.onlab.util.XmlString;
24
25import com.google.common.io.CharStreams;
26
27/**
28 * Pretty print previous command output XML.
29 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070030@Service
Yuta HIGUCHI7d7d46e2017-08-29 12:19:10 -070031@Command(scope = "onos", name = "ppxml",
32 description = "Pretty print XML output from previous command")
33public class PrettyXml extends AbstractShellCommand {
34
35 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070036 protected void doExecute() {
Yuta HIGUCHI7d7d46e2017-08-29 12:19:10 -070037 try {
38 String xmlS = CharStreams.toString(new InputStreamReader(System.in));
39
40 print("%s", XmlString.prettifyXml(xmlS));
41 } catch (IOException e) {
42 log.error("Failed parsing XML.", e);
43 print("%s", e);
44 }
45 }
46
47}