Compare commits
No commits in common. "572d868c24942fe4eaa4f4dc18a4e33cee5542a5" and "5c8e2fc607d6023592de0dff7467a9b7ff219ab0" have entirely different histories.
572d868c24
...
5c8e2fc607
5 changed files with 41 additions and 27 deletions
|
|
@ -1,10 +1,5 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## [0.1.0] - 2026-02-28
|
|
||||||
|
|
||||||
- ✨ Move CLI commands to cli/ package for extensibility
|
|
||||||
- Export RootCmd, DropCmd, and ConfigCmd for custom app creation
|
|
||||||
|
|
||||||
## [0.0.11] - 2026-02-13
|
## [0.0.11] - 2026-02-13
|
||||||
|
|
||||||
- ✨ Add support for mixed-level nested keys with dot/blank handling
|
- ✨ Add support for mixed-level nested keys with dot/blank handling
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "codeberg.org/danjones000/my-log/cli"
|
import "codeberg.org/danjones000/my-log/internal/cmd"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cli.Execute()
|
cmd.Execute()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ GNU Affero General Public License for more details.
|
||||||
You should have received a copy of the GNU Affero General Public License
|
You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package cli
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -25,9 +25,11 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ConfigCmd = &cobra.Command{
|
// configCmd represents the config command
|
||||||
Use: "config",
|
var configCmd = &cobra.Command{
|
||||||
Short: "Save default config to file",
|
Use: "config",
|
||||||
|
Short: "Save default config to file",
|
||||||
|
//Long: ``,
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
print, _ := cmd.Flags().GetBool("print")
|
print, _ := cmd.Flags().GetBool("print")
|
||||||
|
|
@ -60,8 +62,8 @@ var ConfigCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RootCmd.AddCommand(ConfigCmd)
|
rootCmd.AddCommand(configCmd)
|
||||||
|
|
||||||
ConfigCmd.Flags().BoolP("force", "f", false, "Force overwrite")
|
configCmd.Flags().BoolP("force", "f", false, "Force overwrite")
|
||||||
ConfigCmd.Flags().BoolP("print", "p", false, "Print path only")
|
configCmd.Flags().BoolP("print", "p", false, "Print path only")
|
||||||
}
|
}
|
||||||
|
|
@ -14,7 +14,7 @@ GNU Affero General Public License for more details.
|
||||||
You should have received a copy of the GNU Affero General Public License
|
You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package cli
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
@ -34,8 +34,8 @@ var fields map[string]string
|
||||||
var j Json
|
var j Json
|
||||||
var outJson bool
|
var outJson bool
|
||||||
|
|
||||||
// DropCmd represents the drop command
|
// dropCmd represents the drop command
|
||||||
var DropCmd = &cobra.Command{
|
var dropCmd = &cobra.Command{
|
||||||
Use: "drop log title",
|
Use: "drop log title",
|
||||||
Short: "Add a new log entry",
|
Short: "Add a new log entry",
|
||||||
// Long: ``,
|
// Long: ``,
|
||||||
|
|
@ -83,13 +83,13 @@ var DropCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RootCmd.AddCommand(DropCmd)
|
rootCmd.AddCommand(dropCmd)
|
||||||
|
|
||||||
(&d).Set("now")
|
(&d).Set("now")
|
||||||
DropCmd.Flags().VarP(&d, "date", "d", "Date for log entry")
|
dropCmd.Flags().VarP(&d, "date", "d", "Date for log entry")
|
||||||
DropCmd.Flags().StringToStringVarP(&fields, "fields", "f", nil, "Fields you add to entry")
|
dropCmd.Flags().StringToStringVarP(&fields, "fields", "f", nil, "Fields you add to entry")
|
||||||
DropCmd.Flags().VarP(&j, "json", "j", "Entire entry as json")
|
dropCmd.Flags().VarP(&j, "json", "j", "Entire entry as json")
|
||||||
DropCmd.Flags().BoolVarP(&outJson, "output_json", "o", false, "Output result as JSON")
|
dropCmd.Flags().BoolVarP(&outJson, "output_json", "o", false, "Output result as JSON")
|
||||||
}
|
}
|
||||||
|
|
||||||
type Json struct {
|
type Json struct {
|
||||||
|
|
@ -14,7 +14,7 @@ GNU Affero General Public License for more details.
|
||||||
You should have received a copy of the GNU Affero General Public License
|
You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package cli
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -23,19 +23,36 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var RootCmd = &cobra.Command{
|
// rootCmd represents the base command when called without any subcommands
|
||||||
|
var rootCmd = &cobra.Command{
|
||||||
Use: "my-log",
|
Use: "my-log",
|
||||||
Short: "A brief description of your application",
|
Short: "A brief description of your application",
|
||||||
|
//Long: ``,
|
||||||
|
// Uncomment the following line if your bare application
|
||||||
|
// has an action associated with it:
|
||||||
|
// Run: func(cmd *cobra.Command, args []string) { },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||||
func Execute() {
|
func Execute() {
|
||||||
err := RootCmd.Execute()
|
err := rootCmd.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RootCmd.PersistentFlags().StringVarP(&config.ConfigPath, "config", "c", config.ConfigPath, "config file")
|
//cobra.OnInitialize(initConfig)
|
||||||
RootCmd.PersistentFlags().StringToStringVarP(&config.Overrides, "config-value", "v", config.Overrides, "Override config values. Use dot syntax to specify key. E.g. -v output.stdout.config.format=json")
|
|
||||||
|
// Here you will define your flags and configuration settings.
|
||||||
|
// Cobra supports persistent flags, which, if defined here,
|
||||||
|
// will be global for your application.
|
||||||
|
|
||||||
|
rootCmd.PersistentFlags().StringVarP(&config.ConfigPath, "config", "c", config.ConfigPath, "config file")
|
||||||
|
rootCmd.PersistentFlags().StringToStringVarP(&config.Overrides, "config-value", "v", config.Overrides, "Override config values. Use dot syntax to specify key. E.g. -v output.stdout.config.format=json")
|
||||||
|
|
||||||
|
// Cobra also supports local flags, which will only run
|
||||||
|
// when this action is called directly.
|
||||||
|
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue