- fprintf(ofp, "usage: lttng version [OPTIONS]\n");
- fprintf(ofp, "\n");
- fprintf(ofp, "Options:\n");
- fprintf(ofp, " -h, --help Show this help\n");
- fprintf(ofp, " --list-options Simple listing of options\n");
- fprintf(ofp, "\n");
+ int ret = CMD_SUCCESS;
+ struct mi_writer *writer = NULL;
+ struct mi_lttng_version version;
+
+ create_version(&version);
+
+ writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
+ if (!writer) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ /* Open the command element */
+ ret = mi_lttng_writer_command_open(writer,
+ mi_lttng_element_command_version);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto error;
+ }
+
+ /* Beginning of output */
+ ret = mi_lttng_writer_open_element(writer,
+ mi_lttng_element_command_output);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto error;
+ }
+
+ /* Print the machine interface of version */
+ ret = mi_lttng_version(writer, &version,
+ VERSION_DESCRIPTION, lttng_license);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto error;
+ }
+
+ /* Close the output element */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto error;
+ }
+
+ /* Close the command */
+ ret = mi_lttng_writer_command_close(writer);
+ if (ret) {
+ ret = CMD_ERROR;
+ }
+
+error:
+ /* Cleanup */
+ if (writer && mi_lttng_writer_destroy(writer)) {
+ /* Preserve original error code */
+ ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
+ }
+
+end:
+ return ret;