Skip to content

Commit

Permalink
chore: rename Cmder to Cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
damonto committed Jun 7, 2024
1 parent f81251c commit e6a9588
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion internal/cloud/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func download(ctx context.Context, conn *Conn, data []byte) error {
}
}

return lpac.NewCmder(ctx, conn.APDU).ProfileDownload(lpac.ActivationCode{
return lpac.NewCmd(ctx, conn.APDU).ProfileDownload(lpac.ActivationCode{
SMDP: string(parts[1]),
MatchingId: matchingId,
ConfirmationCode: confirmationCode,
Expand Down
2 changes: 1 addition & 1 deletion internal/cloud/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func handleProcessNotification(ctx context.Context, conn *Conn, _ []byte) error
}

func processNotification(ctx context.Context, conn *Conn) error {
cmder := lpac.NewCmder(ctx, conn.APDU)
cmder := lpac.NewCmd(ctx, conn.APDU)
notifications, err := cmder.NotificationList()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/lpac/chip.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ExtCardResource struct {
FreeVolatileMemory int `json:"freeVolatileMemory"`
}

func (c *Cmder) Info() (Info, error) {
func (c *Cmd) Info() (Info, error) {
var info Info
if err := c.Run([]string{"chip", "info"}, &info, nil); err != nil {
return info, err
Expand Down
18 changes: 9 additions & 9 deletions internal/lpac/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import (
"github.com/damonto/estkme-cloud/internal/driver"
)

type Cmder struct {
type Cmd struct {
ctx context.Context
APDU driver.APDU
}

func NewCmder(ctx context.Context, APDU driver.APDU) *Cmder {
return &Cmder{ctx: ctx, APDU: APDU}
func NewCmd(ctx context.Context, APDU driver.APDU) *Cmd {
return &Cmd{ctx: ctx, APDU: APDU}
}

func (c *Cmder) Run(arguments []string, dst any, progress Progress) error {
func (c *Cmd) Run(arguments []string, dst any, progress Progress) error {
c.APDU.Lock()
defer c.APDU.Unlock()
cmd := exec.CommandContext(c.ctx, filepath.Join(config.C.DataDir, c.bin()), arguments...)
Expand All @@ -45,7 +45,7 @@ func (c *Cmder) Run(arguments []string, dst any, progress Progress) error {
return cmdErr
}

func (c *Cmder) process(output io.ReadCloser, input io.WriteCloser, dst any, progress Progress) error {
func (c *Cmd) process(output io.ReadCloser, input io.WriteCloser, dst any, progress Progress) error {
scanner := bufio.NewScanner(output)
scanner.Split(bufio.ScanLines)
var cmdErr error
Expand All @@ -57,7 +57,7 @@ func (c *Cmder) process(output io.ReadCloser, input io.WriteCloser, dst any, pro
return cmdErr
}

func (c *Cmder) handleOutput(output string, input io.WriteCloser, dst any, progress Progress) error {
func (c *Cmd) handleOutput(output string, input io.WriteCloser, dst any, progress Progress) error {
var commandOutput CommandOutput
if err := json.Unmarshal([]byte(output), &commandOutput); err != nil {
return err
Expand All @@ -76,7 +76,7 @@ func (c *Cmder) handleOutput(output string, input io.WriteCloser, dst any, progr
return nil
}

func (c *Cmder) handleLPAResponse(payload json.RawMessage, dst any) error {
func (c *Cmd) handleLPAResponse(payload json.RawMessage, dst any) error {
var lpaPayload LPAPyaload
if err := json.Unmarshal(payload, &lpaPayload); err != nil {
return err
Expand All @@ -98,7 +98,7 @@ func (c *Cmder) handleLPAResponse(payload json.RawMessage, dst any) error {
return nil
}

func (c *Cmder) handleProgress(payload json.RawMessage, progress Progress) error {
func (c *Cmd) handleProgress(payload json.RawMessage, progress Progress) error {
var progressPayload ProgressPayload
if err := json.Unmarshal(payload, &progressPayload); err != nil {
return err
Expand All @@ -109,7 +109,7 @@ func (c *Cmder) handleProgress(payload json.RawMessage, progress Progress) error
return progress(progressPayload.Message)
}

func (c *Cmder) handleAPDU(payload json.RawMessage, input io.WriteCloser) error {
func (c *Cmd) handleAPDU(payload json.RawMessage, input io.WriteCloser) error {
var command CommandAPDUPayload
if err := json.Unmarshal(payload, &command); err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions internal/lpac/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
NotificationProfileManagementOperationDelete = "delete"
)

func (c *Cmder) NotificationList() ([]Notification, error) {
func (c *Cmd) NotificationList() ([]Notification, error) {
var notifications []Notification
if err := c.Run([]string{"notification", "list"}, &notifications, nil); err != nil {
return notifications, err
Expand All @@ -30,19 +30,19 @@ func (c *Cmder) NotificationList() ([]Notification, error) {
return notifications, nil
}

func (c *Cmder) NotificationProcess(seqNumber int, remove bool, progress Progress) error {
func (c *Cmd) NotificationProcess(seqNumber int, remove bool, progress Progress) error {
arguments := []string{"notification", "process", strconv.Itoa(seqNumber)}
if remove {
arguments = append(arguments, "-r")
}
return c.Run(arguments, nil, progress)
}

func (c *Cmder) NotificationDelete(seqNumber int) error {
func (c *Cmd) NotificationDelete(seqNumber int) error {
return c.Run([]string{"notification", "remove", strconv.Itoa(seqNumber)}, nil, nil)
}

func (c *Cmder) NotificationPurge() error {
func (c *Cmd) NotificationPurge() error {
notifications, err := c.NotificationList()
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions internal/lpac/proc_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"os/exec"
)

func (c *Cmder) forSystem(cmd *exec.Cmd) {
func (c *Cmd) forSystem(cmd *exec.Cmd) {
//
}

func (c *Cmder) bin() string {
func (c *Cmd) bin() string {
return "lpac"
}
4 changes: 2 additions & 2 deletions internal/lpac/proc_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"syscall"
)

func (c *Cmder) forSystem(cmd *exec.Cmd) {
func (c *Cmd) forSystem(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: true,
}
}

func (c *Cmder) bin() string {
func (c *Cmd) bin() string {
return "lpac.exe"
}
14 changes: 7 additions & 7 deletions internal/lpac/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ const (
ErrDeletionNotificationNotFound = "deletion notification not found"
)

func (c *Cmder) ProfileList() ([]Profile, error) {
func (c *Cmd) ProfileList() ([]Profile, error) {
var profiles []Profile
if err := c.Run([]string{"profile", "list"}, &profiles, nil); err != nil {
return profiles, err
}
return profiles, nil
}

func (c *Cmder) ProfileInfo(ICCID string) (Profile, error) {
func (c *Cmd) ProfileInfo(ICCID string) (Profile, error) {
var profiles []Profile
if err := c.Run([]string{"profile", "list"}, &profiles, nil); err != nil {
return Profile{}, err
Expand All @@ -53,7 +53,7 @@ func (c *Cmder) ProfileInfo(ICCID string) (Profile, error) {
return Profile{}, nil
}

func (c *Cmder) ProfileDownload(activationCode ActivationCode, progress Progress) error {
func (c *Cmd) ProfileDownload(activationCode ActivationCode, progress Progress) error {
arguments := []string{"profile", "download"}
if activationCode.SMDP != "" {
arguments = append(arguments, "-s", activationCode.SMDP)
Expand All @@ -73,7 +73,7 @@ func (c *Cmder) ProfileDownload(activationCode ActivationCode, progress Progress
})
}

func (c *Cmder) sendNotificationAfterDownloading(action func() error) error {
func (c *Cmd) sendNotificationAfterDownloading(action func() error) error {
notifications, err := c.NotificationList()
if err != nil {
return err
Expand Down Expand Up @@ -107,7 +107,7 @@ func (c *Cmder) sendNotificationAfterDownloading(action func() error) error {
return nil
}

func (c *Cmder) ProfileDelete(ICCID string) error {
func (c *Cmd) ProfileDelete(ICCID string) error {
if err := c.Run([]string{"profile", "delete", ICCID}, nil, nil); err != nil {
return err
}
Expand All @@ -129,11 +129,11 @@ func (c *Cmder) ProfileDelete(ICCID string) error {
return c.NotificationProcess(deletionNotificationSeqNumber, false, nil)
}

func (c *Cmder) ProfileSetNickname(ICCID string, nickname string) error {
func (c *Cmd) ProfileSetNickname(ICCID string, nickname string) error {
return c.Run([]string{"profile", "nickname", ICCID, nickname}, nil, nil)
}

func (c *Cmder) ProfileDiscovery() ([]DiscoveryResponse, error) {
func (c *Cmd) ProfileDiscovery() ([]DiscoveryResponse, error) {
var response []DiscoveryResponse
if err := c.Run([]string{"profile", "discovery"}, &response, nil); err != nil {
return response, err
Expand Down

0 comments on commit e6a9588

Please sign in to comment.