add flags for output format
This commit is contained in:
parent
4ec04b6abf
commit
8855bc9932
26
cmd/root.go
26
cmd/root.go
|
@ -29,6 +29,11 @@ import (
|
|||
|
||||
var file string
|
||||
|
||||
var matlabFmt bool
|
||||
var pythonFmt bool
|
||||
|
||||
var oneline bool
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "dptdist",
|
||||
|
@ -64,9 +69,22 @@ func parse(cmd *cobra.Command, args []string) {
|
|||
panic("not an absorbing Markov chain!")
|
||||
}
|
||||
|
||||
fmtOptions := make([]mat.FormatOption, 0)
|
||||
if matlabFmt {
|
||||
fmtOptions = append(fmtOptions, mat.FormatMATLAB())
|
||||
} else if pythonFmt {
|
||||
fmtOptions = append(fmtOptions, mat.FormatPython())
|
||||
}
|
||||
fmtOptions = append(fmtOptions, mat.Squeeze())
|
||||
|
||||
a := graph.AdjacencyMatrix()
|
||||
out := mat.Formatted(a)
|
||||
out := mat.Formatted(a, fmtOptions...)
|
||||
|
||||
if (matlabFmt || pythonFmt) != oneline {
|
||||
fmt.Printf("%#v\n", out)
|
||||
} else {
|
||||
fmt.Printf("%v\n", out)
|
||||
}
|
||||
}
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
|
@ -91,4 +109,10 @@ func init() {
|
|||
|
||||
rootCmd.Flags().StringVarP(&file, "file", "f", "", "dot file with absorbing Markov chain")
|
||||
rootCmd.MarkFlagRequired("file")
|
||||
|
||||
rootCmd.Flags().BoolVar(&matlabFmt, "matlab", false, "format output as MATLAB array")
|
||||
rootCmd.Flags().BoolVar(&pythonFmt, "python", false, "format output as python array")
|
||||
rootCmd.MarkFlagsMutuallyExclusive("matlab", "python")
|
||||
|
||||
rootCmd.Flags().BoolVar(&oneline, "oneline", false, "output on one line")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue