Go implementation of pdsadmin cli

chore: add initial cli files

+226
+2
pdsadmin/.cobra.yaml
··· 1 + author: QuietEngineer <qtengineer@proton.me> 2 + license: MIT
+21
pdsadmin/LICENSE
··· 1 + The MIT License (MIT) 2 + 3 + Copyright © 2025 QuietEngineer <qtengineer@proton.me> 4 + 5 + Permission is hereby granted, free of charge, to any person obtaining a copy 6 + of this software and associated documentation files (the "Software"), to deal 7 + in the Software without restriction, including without limitation the rights 8 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 + copies of the Software, and to permit persons to whom the Software is 10 + furnished to do so, subject to the following conditions: 11 + 12 + The above copyright notice and this permission notice shall be included in 13 + all copies or substantial portions of the Software. 14 + 15 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 + THE SOFTWARE.
+92
pdsadmin/cmd/root.go
··· 1 + /* 2 + Copyright © 2025 QuietEngineer <qtengineer@proton.me> 3 + 4 + Permission is hereby granted, free of charge, to any person obtaining a copy 5 + of this software and associated documentation files (the "Software"), to deal 6 + in the Software without restriction, including without limitation the rights 7 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 + copies of the Software, and to permit persons to whom the Software is 9 + furnished to do so, subject to the following conditions: 10 + 11 + The above copyright notice and this permission notice shall be included in 12 + all copies or substantial portions of the Software. 13 + 14 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 + THE SOFTWARE. 21 + */ 22 + package cmd 23 + 24 + import ( 25 + "fmt" 26 + "os" 27 + "path/filepath" 28 + 29 + "github.com/spf13/cobra" 30 + "github.com/spf13/viper" 31 + ) 32 + 33 + var cfgFile string 34 + 35 + // rootCmd represents the base command when called without any subcommands 36 + var rootCmd = &cobra.Command{ 37 + Use: "pdsadmin", 38 + Short: "PDSAdmin is a tool for interacting with a PDS you administer.", 39 + Long: `PDSAdmin is a tool for interacting with a PDS you own. 40 + 41 + This implementation tries to be comparable with [bluesky-social's](https://github.com/bluesky-social/pds). 42 + Due to tool limitations this version uses camelCase instead of kebab-case for subcommands.`, 43 + Version: "0.0.1", 44 + // Uncomment the following line if your bare application 45 + // has an action associated with it: 46 + // Run: func(cmd *cobra.Command, args []string) { }, 47 + } 48 + 49 + // Execute adds all child commands to the root command and sets flags appropriately. 50 + // This is called by main.main(). It only needs to happen once to the rootCmd. 51 + func Execute() { 52 + err := rootCmd.Execute() 53 + if err != nil { 54 + os.Exit(1) 55 + } 56 + } 57 + 58 + func init() { 59 + cobra.OnInitialize(initConfig) 60 + 61 + // Here you will define your flags and configuration settings. 62 + // Cobra supports persistent flags, which, if defined here, 63 + // will be global for your application. 64 + rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config/pdsadmin/config.yaml)") 65 + } 66 + 67 + // initConfig reads in config file and ENV variables if set. 68 + func initConfig() { 69 + if cfgFile != "" { 70 + // Use config file from the flag. 71 + viper.SetConfigFile(cfgFile) 72 + } else { 73 + // Find user's config directory 74 + configdir, err := os.UserConfigDir() 75 + cobra.CheckErr(err) 76 + 77 + // Search for config in config subdirectory "pdsadmin" and name "config" (without extension) 78 + // On Linux, possibly $HOME/.config/pdsadmin/config 79 + configPath := filepath.Join(configdir, "pdsadmin") 80 + viper.AddConfigPath(configPath) 81 + viper.SetConfigType("yaml") 82 + viper.SetConfigName("config") 83 + } 84 + 85 + viper.SetEnvPrefix("PDS") 86 + viper.AutomaticEnv() // read in environment variables that match 87 + 88 + // If a config file is found, read it in. 89 + if err := viper.ReadInConfig(); err == nil { 90 + fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed()) 91 + } 92 + }
+27
pdsadmin/go.mod
··· 1 + module github.com/QuietEngineer/pdsadmin 2 + 3 + go 1.23.6 4 + 5 + require ( 6 + github.com/spf13/cobra v1.9.1 7 + github.com/spf13/viper v1.20.1 8 + ) 9 + 10 + require ( 11 + github.com/fsnotify/fsnotify v1.9.0 // indirect 12 + github.com/go-viper/mapstructure/v2 v2.2.1 // indirect 13 + github.com/inconshreveable/mousetrap v1.1.0 // indirect 14 + github.com/pelletier/go-toml/v2 v2.2.4 // indirect 15 + github.com/rogpeppe/go-internal v1.13.1 // indirect 16 + github.com/sagikazarmark/locafero v0.9.0 // indirect 17 + github.com/sourcegraph/conc v0.3.0 // indirect 18 + github.com/spf13/afero v1.14.0 // indirect 19 + github.com/spf13/cast v1.8.0 // indirect 20 + github.com/spf13/pflag v1.0.6 // indirect 21 + github.com/subosito/gotenv v1.6.0 // indirect 22 + go.uber.org/multierr v1.11.0 // indirect 23 + golang.org/x/sys v0.33.0 // indirect 24 + golang.org/x/text v0.25.0 // indirect 25 + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect 26 + gopkg.in/yaml.v3 v3.0.1 // indirect 27 + )
+56
pdsadmin/go.sum
··· 1 + github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= 2 + github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 3 + github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 4 + github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= 5 + github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= 6 + github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= 7 + github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= 8 + github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= 9 + github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= 10 + github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 11 + github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 12 + github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= 13 + github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= 14 + github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 15 + github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 16 + github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 17 + github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 18 + github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 19 + github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 20 + github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 21 + github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= 22 + github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= 23 + github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 24 + github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 25 + github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= 26 + github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= 27 + github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 28 + github.com/sagikazarmark/locafero v0.9.0 h1:GbgQGNtTrEmddYDSAH9QLRyfAHY12md+8YFTqyMTC9k= 29 + github.com/sagikazarmark/locafero v0.9.0/go.mod h1:UBUyz37V+EdMS3hDF3QWIiVr/2dPrx49OMO0Bn0hJqk= 30 + github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= 31 + github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= 32 + github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA= 33 + github.com/spf13/afero v1.14.0/go.mod h1:acJQ8t0ohCGuMN3O+Pv0V0hgMxNYDlvdk+VTfyZmbYo= 34 + github.com/spf13/cast v1.8.0 h1:gEN9K4b8Xws4EX0+a0reLmhq8moKn7ntRlQYgjPeCDk= 35 + github.com/spf13/cast v1.8.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= 36 + github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= 37 + github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= 38 + github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= 39 + github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 40 + github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4= 41 + github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4= 42 + github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= 43 + github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 44 + github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= 45 + github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= 46 + go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= 47 + go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= 48 + golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= 49 + golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= 50 + golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= 51 + golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= 52 + gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 53 + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 54 + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 55 + gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 56 + gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+28
pdsadmin/main.go
··· 1 + /* 2 + Copyright © 2025 QuietEngineer <qtengineer@proton.me> 3 + 4 + Permission is hereby granted, free of charge, to any person obtaining a copy 5 + of this software and associated documentation files (the "Software"), to deal 6 + in the Software without restriction, including without limitation the rights 7 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 + copies of the Software, and to permit persons to whom the Software is 9 + furnished to do so, subject to the following conditions: 10 + 11 + The above copyright notice and this permission notice shall be included in 12 + all copies or substantial portions of the Software. 13 + 14 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 + THE SOFTWARE. 21 + */ 22 + package main 23 + 24 + import "github.com/QuietEngineer/pdsadmin/cmd" 25 + 26 + func main() { 27 + cmd.Execute() 28 + }
pdsadmin/sample.config.yaml

This is a binary file and will not be displayed.