Module: environment-commands Synopsis: The commands provided by the environment Author: Andy Armstrong Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND /// Documentation report /// /// This isn't in environment-reports because it is only useful here. define constant $documentation-report = make(, name: #"documentation", title: "Command line documentation", class: , edition: #"basic"); define function command-reports () => (reports :: ) concatenate(vector($documentation-report), available-reports()) end function command-reports; define function write-command-documentation (stream :: , context :: ) let main-group = context.context-command-group; let subgroups = collect-command-info(main-group, , sort?: #t); write-command-group-documentation (stream, context, main-group, show-contents?: #f); for (subgroup :: in subgroups) unless (subgroup == main-group) write-command-group-documentation(stream, context, subgroup) end end end function write-command-documentation; define function write-command-group-documentation (stream :: , context :: , group :: , #key show-contents? :: = #t) => () let separator = make(, size: 60, fill: '-'); format(stream, "%s\n\n", separator); display-help(stream, context, group); if (show-contents?) let properties = collect-command-info(group, , sort?: #t); for (property :: in properties) format(stream, "\n"); display-help(stream, context, property, group: group); end; let command-lines = collect-command-info(group, , sort?: #t); for (command-line :: in command-lines) format(stream, "\n%s\n\n", command-line.command-info-title); display-help(stream, context, command-line, group: group); format(stream, "\n") end end end function write-command-group-documentation; /// Report properties define class () end class ; define command-property reports => (summary: "Available reports", documentation: "The set of available reports.") end command-property reports; define method show-property (context :: , property :: ) => () let stream = context.context-server.server-output-stream; print-table(stream, as(, command-reports()), label-key: method (info :: ) as-uppercase(as(, info.report-info-name)) end, value-key: report-info-title, sort?: #t) end method show-property; /// Export define class () constant slot %report :: , required-init-keyword: report:; constant slot %file :: false-or() = #f, init-keyword: file:; constant slot %format :: false-or() = #f, init-keyword: format:; end class ; define command-line export => (summary: "exports project information", documentation: "Exports information from the specified project.") argument report :: = "the report to generate"; keyword file :: = "the filename for the report"; keyword format :: = "the format for the report"; end command-line export; define sealed method do-execute-command (context :: , command :: ) => () let project = context.context-project; let report = command.%report; let filename = command.%file; let format = command.%format | #"text"; let info = find-report-info(report); case (report == #"documentation") => if (filename) with-open-file (stream = filename, direction: #"output") write-command-documentation(stream, context) end; message(context, "Wrote documentation to %s", filename) else let stream = context.context-server.server-output-stream; write-command-documentation(stream, context) end; info => if (~member?(format, info.report-info-formats)) command-error("The %s report does not support the '%s' format", report, format); end; let report = make(info.report-info-class, project: project, format: format); if (filename) with-open-file (stream = filename, direction: #"output") write-report(stream, report) end; message(context, "Wrote %s to %s", info.report-info-title, filename) else let stream = context.context-server.server-output-stream; write-report(stream, report) end; otherwise => command-error("No such report '%s'", report); end end method do-execute-command; /// Project commands define command-group reports (summary: "report commands", documentation: "Commands for report generation.") property reports; command export; end command-group reports;