Skip to content

Commit 4c8bdf5

Browse files
committed
feat: remove the embed command
1 parent 3745a65 commit 4c8bdf5

6 files changed

Lines changed: 6 additions & 283 deletions

File tree

cmd/embed/embed.go

Lines changed: 0 additions & 170 deletions
This file was deleted.

cmd/quota/quota.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var QuotaCmd = &cobra.Command{
3939
func init() {
4040
QuotaCmd.Flags().BoolVarP(&human, "human", "H", false, "display human readable format")
4141
}
42+
4243
func displayStorage(s string) string {
4344
size, _ := strconv.ParseFloat(s, 64)
4445
cnt := 0

cmd/root.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"os"
55

66
"github.com/52funny/pikpakcli/cmd/download"
7-
"github.com/52funny/pikpakcli/cmd/embed"
87
"github.com/52funny/pikpakcli/cmd/list"
98
"github.com/52funny/pikpakcli/cmd/new"
109
"github.com/52funny/pikpakcli/cmd/quota"
@@ -22,15 +21,15 @@ var rootCmd = &cobra.Command{
2221
Run: func(cmd *cobra.Command, args []string) {
2322
cmd.Help()
2423
},
25-
PersistentPreRun: func(cmd *cobra.Command, args []string) {
24+
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
2625
err := conf.InitConfig(configPath)
2726
if err != nil {
28-
logrus.Errorln(err)
29-
os.Exit(1)
27+
return err
3028
}
3129
if debug {
3230
logrus.SetLevel(logrus.DebugLevel)
3331
}
32+
return nil
3433
},
3534
}
3635

@@ -46,11 +45,11 @@ func init() {
4645
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "debug mode")
4746
// config
4847
rootCmd.PersistentFlags().StringVar(&configPath, "config", "config.yml", "config file path")
48+
4949
rootCmd.AddCommand(upload.UploadCmd)
5050
rootCmd.AddCommand(download.DownloadCmd)
5151
rootCmd.AddCommand(share.ShareCommand)
5252
rootCmd.AddCommand(new.NewCommand)
53-
rootCmd.AddCommand(embed.EmbedCmd)
5453
rootCmd.AddCommand(quota.QuotaCmd)
5554
rootCmd.AddCommand(list.ListCmd)
5655
}

conf/config.go

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package conf
22

33
import (
4-
"bytes"
5-
"encoding/binary"
64
"fmt"
75
"io"
86
"os"
@@ -27,12 +25,7 @@ func (c *ConfigType) UseProxy() bool {
2725

2826
// Initializing configuration information
2927
func InitConfig(path string) error {
30-
// Firstly, read the config info from executable file
31-
if readFromBinary() == nil {
32-
return nil
33-
}
34-
35-
// Secondly, it reads config.yml from the given path.
28+
// Firstly, it reads config.yml from the given path.
3629
// If there is no config.yml in the given path, it reads it from the default config path.
3730
_, err := os.Stat(path)
3831
switch os.IsNotExist(err) {
@@ -54,67 +47,6 @@ func InitConfig(path string) error {
5447
return nil
5548
}
5649

57-
// Read config from binary in the end
58-
// config_bytes: n bytes
59-
// end_magic: 10 bytes
60-
// size: 4 bytes
61-
// -----------------------------------
62-
// | config_bytes | size | end_magic |
63-
// -----------------------------------
64-
func readFromBinary() error {
65-
f, err := os.Open(os.Args[0])
66-
if err != nil {
67-
return err
68-
}
69-
defer f.Close()
70-
stat, err := f.Stat()
71-
if err != nil {
72-
return err
73-
}
74-
75-
var end_magic = make([]byte, 10)
76-
n, err := f.ReadAt(end_magic, stat.Size()-10)
77-
if err != nil {
78-
return err
79-
}
80-
81-
if n != 10 {
82-
return fmt.Errorf("read end_magic err: %d", n)
83-
}
84-
85-
// Not have `config.yml` in the end
86-
if !bytes.Equal(end_magic, []byte("config.yml")) {
87-
return fmt.Errorf("not a pikpakcli binary")
88-
}
89-
90-
var size = make([]byte, 4)
91-
n, err = f.ReadAt(size, stat.Size()-14)
92-
93-
if err != nil {
94-
return err
95-
}
96-
97-
if n != 4 {
98-
return fmt.Errorf("read size err: %d", n)
99-
}
100-
101-
configSize := int64(binary.LittleEndian.Uint32(size))
102-
configBuf := make([]byte, configSize)
103-
104-
n, err = f.ReadAt(configBuf, stat.Size()-14-configSize)
105-
106-
if err != nil || n != int(configSize) {
107-
return err
108-
}
109-
110-
if n != int(configSize) {
111-
return fmt.Errorf("read config size err: %d", n)
112-
}
113-
114-
// Unmarshal config
115-
return yaml.Unmarshal(configBuf, &Config)
116-
}
117-
11850
// Read configuration file from the given path
11951
func readFromPath(path string) error {
12052
f, err := os.Open(path)

internal/utils/embed.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

internal/utils/embed_test.go

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)