-
Notifications
You must be signed in to change notification settings - Fork 4
/
ubidetach.go
64 lines (48 loc) · 1.26 KB
/
ubidetach.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright © 2019-2020 Platina Systems, Inc. All rights reserved.
// Use of this source code is governed by the GPL-2 license described in the
// LICENSE file.
package ubi
import (
"fmt"
"strconv"
"github.com/platinasystems/goes/external/parms"
"github.com/platinasystems/goes/lang"
"github.com/platinasystems/ubi"
)
type DetachCommand struct{}
func (DetachCommand) String() string { return "ubidetach" }
func (DetachCommand) Usage() string { return "ubidetach -d [UBI-DEV]" }
func (DetachCommand) Apropos() lang.Alt {
return lang.Alt{
lang.EnUS: "Detach a UBI partition from a MTD device",
}
}
func (DetachCommand) Man() lang.Alt {
return lang.Alt{
lang.EnUS: `
DESCRIPTION
The ubidetach command is used to deassociate a MTD device from
the UBI subsystem.
OPTIONS
-d [UNIT]
Specifies the unit number of the UBI device to detach.
EXAMPLES
ubidetach -d 0
Detach /dev/ubi0.`,
}
}
func (c DetachCommand) Main(args ...string) (err error) {
parm, args := parms.New(args, "-d")
if len(args) > 0 {
return fmt.Errorf("%v: unexpected", args)
}
unit := 0
if us := parm.ByName["-d"]; us != "" {
unit, err = strconv.Atoi(us)
if err != nil {
return fmt.Errorf("Error parsing %s: %s\n", us, err)
}
}
err = ubi.Detach(int32(unit))
return err
}