Skip to content

Commit

Permalink
add ptlsp site
Browse files Browse the repository at this point in the history
  • Loading branch information
sagan committed Dec 11, 2023
1 parent eed9bc7 commit ecb415f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
_ "github.com/sagan/ptool/cmd/setsavepath"
_ "github.com/sagan/ptool/cmd/shell"
_ "github.com/sagan/ptool/cmd/show"
_ "github.com/sagan/ptool/cmd/sites"
_ "github.com/sagan/ptool/cmd/sites/all"
_ "github.com/sagan/ptool/cmd/statscmd"
_ "github.com/sagan/ptool/cmd/status"
_ "github.com/sagan/ptool/cmd/tidyup"
Expand Down
6 changes: 6 additions & 0 deletions cmd/sites/all/all.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package all

import (
_ "github.com/sagan/ptool/cmd/sites"
_ "github.com/sagan/ptool/cmd/sites/show"
)
44 changes: 44 additions & 0 deletions cmd/sites/show/show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package show

import (
"fmt"

toml "github.com/pelletier/go-toml/v2"
"github.com/spf13/cobra"

"github.com/sagan/ptool/cmd/sites"
"github.com/sagan/ptool/site/tpl"
"github.com/sagan/ptool/util"
)

var command = &cobra.Command{
Use: "show {site}...",
Short: "Show detailed configuration of internal supported PT site.",
Long: `Show detailed configuration of internal supported PT site.
All configurations of any site can be overrided in ptool.toml.`,
Args: cobra.MatchAll(cobra.MinimumNArgs(1), cobra.OnlyValidArgs),
RunE: show,
}

func init() {
sites.Command.AddCommand(command)
}

func show(cmd *cobra.Command, args []string) error {
sitenames := args

for _, sitename := range sitenames {
tplconfig := tpl.SITES[sitename]
if tplconfig == nil {
fmt.Printf("# %s : is NOT a internal supported site\n", sitename)
continue
}
str, err := toml.Marshal(util.StructToMap(*tplconfig, true, true))
if err != nil {
fmt.Printf("# %s : failed to get detailed configuration: %v\n", sitename, err)
continue
}
fmt.Printf("# %s\n[[sites]]\n%s\n", sitename, str)
}
return nil
}
8 changes: 4 additions & 4 deletions cmd/sites/sites.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package version
package sites

import (
"fmt"
Expand All @@ -11,7 +11,7 @@ import (
"github.com/sagan/ptool/util"
)

var command = &cobra.Command{
var Command = &cobra.Command{
Use: "sites [--filter filter]",
Short: "Show internal supported PT sites list which can be used with this software.",
Long: `Show internal supported PT sites list which can be used with this software.`,
Expand All @@ -24,8 +24,8 @@ var (
)

func init() {
command.Flags().StringVarP(&filter, "filter", "", "", "Filter sites. Only show sites which name / url / comment contain this string")
cmd.RootCmd.AddCommand(command)
Command.Flags().StringVarP(&filter, "filter", "", "", "Filter sites. Only show sites which name / url / comment contain this string")
cmd.RootCmd.AddCommand(Command)
}

func sites(cmd *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/hekmon/transmissionrpc/v2 v2.0.1
github.com/jpillora/go-tld v1.2.1
github.com/mattn/go-runewidth v0.0.14
github.com/pelletier/go-toml/v2 v2.0.8
github.com/refraction-networking/utls v1.3.2
github.com/sirupsen/logrus v1.9.1
github.com/spf13/cobra v1.7.0
Expand Down Expand Up @@ -66,7 +67,6 @@ require (
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-tty v0.0.3 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pkg/term v1.2.0-beta.2 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/spf13/afero v1.9.5 // indirect
Expand Down
5 changes: 5 additions & 0 deletions site/tpl/tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@ var (
Url: "https://pthome.net/",
Comment: "铂金家",
},
"ptlsp": {
Type: "nexusphp",
Url: "https://www.ptlsp.com/",
Comment: "",
},
"pttime": {
Type: "nexusphp",
Aliases: []string{"ptt"},
Expand Down
4 changes: 2 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package version

var (
VersionSuffix = "" // eg. DEV
VersionTag = "v0.1.8"
VersionSuffix = "DEV" // eg. DEV
VersionTag = "v0.1.9"
Version = ""
)

Expand Down

0 comments on commit ecb415f

Please sign in to comment.