From 192152b215a2f5c48a11ccac6f77d3bdc02f97d0 Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Mon, 4 Aug 2014 00:12:09 +0000 Subject: [PATCH 01/10] Config command created - config show started --- cmd/cmd.go | 6 ++++-- cmd/config.go | 15 +++++++++++++++ cmd/config_show.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 cmd/config.go create mode 100644 cmd/config_show.go diff --git a/cmd/cmd.go b/cmd/cmd.go index 86df0f33..cbd9ef55 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -3,12 +3,13 @@ package cmd import ( "fmt" + "os" + "time" + "github.com/smira/aptly/aptly" "github.com/smira/aptly/deb" "github.com/smira/commander" "github.com/smira/flag" - "os" - "time" ) // ListPackagesRefList shows list of packages in PackageRefList @@ -65,6 +66,7 @@ fine-grained changes in repository contents to transition your package environment to new version.`, Flag: *flag.NewFlagSet("aptly", flag.ExitOnError), Subcommands: []*commander.Command{ + makeCmdConfig(), makeCmdDb(), makeCmdGraph(), makeCmdMirror(), diff --git a/cmd/config.go b/cmd/config.go new file mode 100644 index 00000000..5eb27307 --- /dev/null +++ b/cmd/config.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "github.com/smira/commander" +) + +func makeCmdConfig() *commander.Command { + return &commander.Command{ + UsageLine: "config", + Short: "manage aptly configuration", + Subcommands: []*commander.Command{ + makeCmdConfigShow(), + }, + } +} diff --git a/cmd/config_show.go b/cmd/config_show.go new file mode 100644 index 00000000..ef7ea040 --- /dev/null +++ b/cmd/config_show.go @@ -0,0 +1,31 @@ +package cmd + +import "fmt" +import "github.com/smira/commander" + +func aptlyConfigShow(cmd *commander.Command, args []string) error { + + config := context.Config() + + fmt.Printf("RootDir: %s") + + return nil + +} + +func makeCmdConfigShow() *commander.Command { + cmd := &commander.Command{ + Run: aptlyConfigShow, + UsageLine: "show", + Short: "show current aptly's config", + Long: ` +Command show displays the current aptly configuration. + +Example: + + $ aptly config show + +`, + } + return cmd +} From c1995beff13a725d27e364c1b51f3154751e12c7 Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Tue, 5 Aug 2014 01:03:06 +0000 Subject: [PATCH 02/10] Config_show prints out strings,structs,ints,bools More development for aptly config show --- cmd/config_show.go | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/cmd/config_show.go b/cmd/config_show.go index ef7ea040..92ca096a 100644 --- a/cmd/config_show.go +++ b/cmd/config_show.go @@ -1,15 +1,50 @@ package cmd -import "fmt" +import ( + "fmt" + "reflect" + "strconv" + "strings" +) import "github.com/smira/commander" func aptlyConfigShow(cmd *commander.Command, args []string) error { config := context.Config() - fmt.Printf("RootDir: %s") + fmt.Println(to_string(reflect.ValueOf(config).Elem())) + return err - return nil +} + +func to_string(v reflect.Value) string { + + switch v.Kind() { + + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return strconv.FormatInt(v.Int(), 10) + case reflect.Bool: + return strconv.FormatBool(v.Bool()) + case reflect.Slice: + var str_slice []string + for i := 0; i < v.Len(); i++ { + str_slice = append(str_slice, to_string(v.Index(i))) + } + return strings.Join(str_slice, ", ") + case reflect.Struct: + var str_slice []string + typ := reflect.TypeOf(v.Interface()) + for i := 0; i < typ.NumField(); i++ { + str_slice = append(str_slice, typ.Field(i).Name+": "+to_string(v.Field(i))) + } + return strings.Join(str_slice, "\n") + //case reflect.Map: + // var str_slice []string + + case reflect.String: + return v.String() + } + return "" } From 8efb7903b2d4c6630d22458c827e8b5a1175a0e0 Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Wed, 6 Aug 2014 00:19:55 +0000 Subject: [PATCH 03/10] Added map to to_string and tabs to config_show --- cmd/config_show.go | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/cmd/config_show.go b/cmd/config_show.go index 92ca096a..370fcd6a 100644 --- a/cmd/config_show.go +++ b/cmd/config_show.go @@ -12,12 +12,13 @@ func aptlyConfigShow(cmd *commander.Command, args []string) error { config := context.Config() - fmt.Println(to_string(reflect.ValueOf(config).Elem())) - return err + fmt.Println(to_string(reflect.ValueOf(config).Elem(), 0)) + + return nil } -func to_string(v reflect.Value) string { +func to_string(v reflect.Value, tabs int) string { switch v.Kind() { @@ -28,19 +29,26 @@ func to_string(v reflect.Value) string { case reflect.Slice: var str_slice []string for i := 0; i < v.Len(); i++ { - str_slice = append(str_slice, to_string(v.Index(i))) + str_slice = append(str_slice, to_string(v.Index(i), tabs)) } return strings.Join(str_slice, ", ") case reflect.Struct: var str_slice []string typ := reflect.TypeOf(v.Interface()) + //str_slice = append(str_slice, make_tabs(tabs)+"{") for i := 0; i < typ.NumField(); i++ { - str_slice = append(str_slice, typ.Field(i).Name+": "+to_string(v.Field(i))) + str_slice = append(str_slice, make_tabs(tabs)+typ.Field(i).Name+": "+to_string(v.Field(i), tabs+1)) } + //str_slice = append(str_slice, make_tabs(tabs)+"}") + return strings.Join(str_slice, "\n") + case reflect.Map: + var str_slice []string + str_slice = append(str_slice, "") + for _, key := range v.MapKeys() { + str_slice = append(str_slice, make_tabs(tabs)+"- "+to_string(key, tabs)+":\n"+to_string(v.MapIndex(key), tabs+1)) + } + //str_slice = append(str_slice, make_tabs(tabs)+"}") return strings.Join(str_slice, "\n") - //case reflect.Map: - // var str_slice []string - case reflect.String: return v.String() } @@ -48,6 +56,14 @@ func to_string(v reflect.Value) string { } +func make_tabs(tabs int) string { + str := "" + for i := 0; i < tabs; i++ { + str += "\t" + } + return str +} + func makeCmdConfigShow() *commander.Command { cmd := &commander.Command{ Run: aptlyConfigShow, From 81e91898539f5bf0c789a6a3549f57eab3630f06 Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Wed, 6 Aug 2014 22:41:31 +0000 Subject: [PATCH 04/10] Config show now outputs a clean data structure --- cmd/config_show.go | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/cmd/config_show.go b/cmd/config_show.go index 370fcd6a..dfafbf4f 100644 --- a/cmd/config_show.go +++ b/cmd/config_show.go @@ -5,20 +5,26 @@ import ( "reflect" "strconv" "strings" + + "github.com/smira/commander" ) -import "github.com/smira/commander" func aptlyConfigShow(cmd *commander.Command, args []string) error { config := context.Config() - fmt.Println(to_string(reflect.ValueOf(config).Elem(), 0)) + config_to_string := toString(reflect.ValueOf(config).Elem()) + + if config_to_string == "" { + return fmt.Errorf("Error processing configuration") + } + + fmt.Println(config_to_string) return nil - } -func to_string(v reflect.Value, tabs int) string { +func toString(v reflect.Value) string { switch v.Kind() { @@ -29,39 +35,30 @@ func to_string(v reflect.Value, tabs int) string { case reflect.Slice: var str_slice []string for i := 0; i < v.Len(); i++ { - str_slice = append(str_slice, to_string(v.Index(i), tabs)) + str_slice = append(str_slice, toString(v.Index(i))) } return strings.Join(str_slice, ", ") case reflect.Struct: var str_slice []string typ := reflect.TypeOf(v.Interface()) - //str_slice = append(str_slice, make_tabs(tabs)+"{") for i := 0; i < typ.NumField(); i++ { - str_slice = append(str_slice, make_tabs(tabs)+typ.Field(i).Name+": "+to_string(v.Field(i), tabs+1)) + str_slice = append(str_slice, typ.Field(i).Name+": "+toString(v.Field(i))) } - //str_slice = append(str_slice, make_tabs(tabs)+"}") return strings.Join(str_slice, "\n") case reflect.Map: var str_slice []string str_slice = append(str_slice, "") for _, key := range v.MapKeys() { - str_slice = append(str_slice, make_tabs(tabs)+"- "+to_string(key, tabs)+":\n"+to_string(v.MapIndex(key), tabs+1)) + str_slice = append(str_slice, "- "+toString(key)+":\n"+toString(v.MapIndex(key))) } - //str_slice = append(str_slice, make_tabs(tabs)+"}") return strings.Join(str_slice, "\n") case reflect.String: return v.String() + default: + return "" } + return "" - -} - -func make_tabs(tabs int) string { - str := "" - for i := 0; i < tabs; i++ { - str += "\t" - } - return str } func makeCmdConfigShow() *commander.Command { From ecbb9ad20c4db39496869ede171f6e8c84193190 Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Sat, 11 Oct 2014 16:59:11 +0000 Subject: [PATCH 05/10] Fixed failing system test Added config command to aptly main output. --- system/t03_help/MainTest_gold | 1 + 1 file changed, 1 insertion(+) diff --git a/system/t03_help/MainTest_gold b/system/t03_help/MainTest_gold index a127f259..e313f9aa 100644 --- a/system/t03_help/MainTest_gold +++ b/system/t03_help/MainTest_gold @@ -3,6 +3,7 @@ aptly - Debian repository management tool Commands: api start API server/issue requests + config manage aptly configuration db manage aptly's internal database and package pool graph render graph of relationships mirror manage mirrors of remote repositories From 24927f9a29f480c6ce212dc07c8c1ba47aefef61 Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Mon, 13 Oct 2014 18:29:45 +0100 Subject: [PATCH 06/10] config_show should output pretty json This commit changes the output of aptly config show to be pretty json rather than YAML. --- cmd/config_show.go | 50 ++++++---------------------------------------- 1 file changed, 6 insertions(+), 44 deletions(-) diff --git a/cmd/config_show.go b/cmd/config_show.go index dfafbf4f..8ddff565 100644 --- a/cmd/config_show.go +++ b/cmd/config_show.go @@ -1,10 +1,8 @@ package cmd import ( + "encoding/json" "fmt" - "reflect" - "strconv" - "strings" "github.com/smira/commander" ) @@ -12,55 +10,19 @@ import ( func aptlyConfigShow(cmd *commander.Command, args []string) error { config := context.Config() + pretty_json, err := json.MarshalIndent(config, "", " ") - config_to_string := toString(reflect.ValueOf(config).Elem()) - - if config_to_string == "" { - return fmt.Errorf("Error processing configuration") + if err != nil { + return fmt.Errorf("unable to parse the config file: %s", err) } + config_to_string := string(pretty_json) + fmt.Println(config_to_string) return nil } -func toString(v reflect.Value) string { - - switch v.Kind() { - - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return strconv.FormatInt(v.Int(), 10) - case reflect.Bool: - return strconv.FormatBool(v.Bool()) - case reflect.Slice: - var str_slice []string - for i := 0; i < v.Len(); i++ { - str_slice = append(str_slice, toString(v.Index(i))) - } - return strings.Join(str_slice, ", ") - case reflect.Struct: - var str_slice []string - typ := reflect.TypeOf(v.Interface()) - for i := 0; i < typ.NumField(); i++ { - str_slice = append(str_slice, typ.Field(i).Name+": "+toString(v.Field(i))) - } - return strings.Join(str_slice, "\n") - case reflect.Map: - var str_slice []string - str_slice = append(str_slice, "") - for _, key := range v.MapKeys() { - str_slice = append(str_slice, "- "+toString(key)+":\n"+toString(v.MapIndex(key))) - } - return strings.Join(str_slice, "\n") - case reflect.String: - return v.String() - default: - return "" - } - - return "" -} - func makeCmdConfigShow() *commander.Command { cmd := &commander.Command{ Run: aptlyConfigShow, From 0afb1f4306cc4563a1ac670b29147c9cd122c091 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Tue, 14 Oct 2014 18:20:09 +0400 Subject: [PATCH 07/10] Style fixes. --- cmd/config_show.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cmd/config_show.go b/cmd/config_show.go index 8ddff565..119fd37f 100644 --- a/cmd/config_show.go +++ b/cmd/config_show.go @@ -10,15 +10,13 @@ import ( func aptlyConfigShow(cmd *commander.Command, args []string) error { config := context.Config() - pretty_json, err := json.MarshalIndent(config, "", " ") + prettyJSON, err := json.MarshalIndent(config, "", " ") if err != nil { - return fmt.Errorf("unable to parse the config file: %s", err) + return fmt.Errorf("unable to dump the config file: %s", err) } - config_to_string := string(pretty_json) - - fmt.Println(config_to_string) + fmt.Println(string(prettyJSON)) return nil } From 37b2d49aea1aa3dad7199c341eb28b31b0d97621 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Tue, 14 Oct 2014 18:22:57 +0400 Subject: [PATCH 08/10] A bit more style fixes. #123 --- cmd/cmd.go | 5 ++--- cmd/config_show.go | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index c73df5b7..4bec1f74 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -3,13 +3,12 @@ package cmd import ( "fmt" - "os" - "time" - "github.com/smira/aptly/aptly" "github.com/smira/aptly/deb" "github.com/smira/commander" "github.com/smira/flag" + "os" + "time" ) // ListPackagesRefList shows list of packages in PackageRefList diff --git a/cmd/config_show.go b/cmd/config_show.go index 119fd37f..04f28648 100644 --- a/cmd/config_show.go +++ b/cmd/config_show.go @@ -3,7 +3,6 @@ package cmd import ( "encoding/json" "fmt" - "github.com/smira/commander" ) From 88351503b0998a5745ab092080a43847c7940bfa Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Tue, 14 Oct 2014 18:26:12 +0400 Subject: [PATCH 09/10] Fix misprint. #96 --- cmd/task_run.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/task_run.go b/cmd/task_run.go index dfe4f02a..2e771761 100644 --- a/cmd/task_run.go +++ b/cmd/task_run.go @@ -133,16 +133,16 @@ func makeCmdTaskRun() *commander.Command { UsageLine: "run -filename= | , , ...", Short: "run aptly tasks", Long: ` -Command helps origanise multiple aptly commands in one single aptly task, running as single thread. +Command helps organise multiple aptly commands in one single aptly task, running as single thread. Example: - $ aptly task run - > repo create local - > repo add local pkg1 - > publish repo local - > serve - > + $ aptly task run + > repo create local + > repo add local pkg1 + > publish repo local + > serve + > `, } From 017dca57ede406ba5f605b15480e8465db12649e Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Tue, 14 Oct 2014 18:26:27 +0400 Subject: [PATCH 10/10] Re-generate man page. #123 #96 --- man/aptly.1 | 43 +++++++++++++++++++++++++++++++++++++++++++ man/aptly.1.ronn.tmpl | 4 ++++ 2 files changed, 47 insertions(+) diff --git a/man/aptly.1 b/man/aptly.1 index f78fd8bd..15284323 100644 --- a/man/aptly.1 +++ b/man/aptly.1 @@ -1464,6 +1464,49 @@ Example: .P $ aptly graph . +.SH "SHOW CURRENT APTLY\(cqS CONFIG" +\fBaptly\fR \fBconfig\fR \fBshow\fR +. +.P +Command show displays the current aptly configuration\. +. +.P +Example: +. +.P +$ aptly config show +. +.SH "RUN APTLY TASKS" +\fBaptly\fR \fBtask\fR \fBrun\fR \-filename=\fIfilename\fR \fB|\fR \fIcommand1\fR, \fIcommand2\fR, \fB\|\.\|\.\|\.\fR +. +.P +Command helps organise multiple aptly commands in one single aptly task, running as single thread\. +. +.P +Example: +. +.IP "" 4 +. +.nf + + $ aptly task run + > repo create local + > repo add local pkg1 + > publish repo local + > serve + > +. +.fi +. +.IP "" 0 +. +.P +Options: +. +.TP +\-\fBfilename\fR= +specifies the filename that contains the commands to run +. .SH "ENVIRONMENT" If environment variable \fBHTTP_PROXY\fR is set \fBaptly\fR would use its value to proxy all HTTP requests\. . diff --git a/man/aptly.1.ronn.tmpl b/man/aptly.1.ronn.tmpl index b2674547..1c49a15b 100644 --- a/man/aptly.1.ronn.tmpl +++ b/man/aptly.1.ronn.tmpl @@ -245,6 +245,10 @@ When specified on command line, query may have to be quoted according to shell r {{template "command" findCommand . "graph"}} +{{template "command" findCommand . "config"}} + +{{template "command" findCommand . "task"}} + ## ENVIRONMENT If environment variable `HTTP_PROXY` is set `aptly` would use its value