Merge branch 'graph-output-filename'

This commit is contained in:
Andrey Smirnov
2015-05-18 00:39:41 +03:00
2 changed files with 26 additions and 4 deletions
+20 -2
View File
@@ -4,11 +4,13 @@ import (
"bytes"
"fmt"
"github.com/smira/aptly/deb"
"github.com/smira/aptly/utils"
"github.com/smira/commander"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
)
func aptlyGraph(cmd *commander.Command, args []string) error {
@@ -35,6 +37,11 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
os.Remove(tempfile.Name())
format := context.Flags().Lookup("format").Value.String()
output := context.Flags().Lookup("output").Value.String()
if filepath.Ext(output) != "" {
format = filepath.Ext(output)[1:]
}
tempfilename := tempfile.Name() + "." + format
@@ -66,9 +73,19 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
return err
}
fmt.Printf("Rendered to %s file: %s, trying to open it...\n", format, tempfilename)
if output != "" {
err = utils.CopyFile(tempfilename, output)
if err != nil {
return fmt.Errorf("unable to copy %s -> %s: %s", tempfilename, output, err)
}
_ = os.Remove(tempfilename)
_ = exec.Command("open", tempfilename).Run()
fmt.Printf("Output saved to %s\n", output)
} else {
fmt.Printf("Rendered to %s file: %s, trying to open it...\n", format, tempfilename)
_ = exec.Command("open", tempfilename).Run()
}
return err
}
@@ -90,6 +107,7 @@ Example:
}
cmd.Flag.String("format", "png", "render graph to specified format (png, svg, pdf, etc.)")
cmd.Flag.String("output", "", "specify output filename, default is to open result in viewer")
return cmd
}
+6 -2
View File
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "APTLY" "1" "April 2015" "" ""
.TH "APTLY" "1" "May 2015" "" ""
.
.SH "NAME"
\fBaptly\fR \- Debian repository management tool
@@ -180,7 +180,7 @@ bucket name
.
.TP
\fBdisableMultiDel\fR
for S3\-compatible cloud storages which do not support \fBMultiDel\fR S3 API, enable this setting (file deletion would be slower with this setting enabled)
(optional) for S3\-compatible cloud storages which do not support \fBMultiDel\fR S3 API, enable this setting (file deletion would be slower with this setting enabled)
.
.P
In order to publish to S3, specify endpoint as \fBs3:endpoint\-name:\fR before publishing prefix on the command line, e\.g\.:
@@ -1640,6 +1640,10 @@ Options:
\-\fBformat\fR=png
render graph to specified format (png, svg, pdf, etc\.)
.
.TP
\-\fBoutput\fR=
specify output filename, default is to open result in viewer
.
.SH "SHOW CURRENT APTLY\(cqS CONFIG"
\fBaptly\fR \fBconfig\fR \fBshow\fR
.