diff --git a/cmd/root.go b/cmd/root.go index 8dc03e3..cd98829 100644 --- a/cmd/root.go +++ b/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) - fmt.Printf("%v\n", out) + 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") }