From 54545ca337ee803ceb7d7e25a05e929dca2cd856 Mon Sep 17 00:00:00 2001 From: bpc2003 Date: Tue, 27 May 2025 13:16:32 -0400 Subject: Get started on trap command --- cmds/env.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'cmds/env.go') diff --git a/cmds/env.go b/cmds/env.go index 17b220d..63ee7f6 100644 --- a/cmds/env.go +++ b/cmds/env.go @@ -36,23 +36,26 @@ func Set(args []string) { } // unset: unsets an environment variable -func Unset(args []string) error { +func Unset(args []string) (int, error) { if len(args) == 1 || len(args) >= 3 { - return errors.New("usage: unset [name]") + return 1, errors.New("usage: unset [name]") } os.Unsetenv(args[1]) - return nil + return 0, nil } // export: exports a key-value pair to the environment // in the form of `name=value` -func Export(args []string) error { +func Export(args []string) (int, error) { if len(args) == 1 || len(args) >= 3 { - return errors.New("usage: export [name=value]") + return 1, errors.New("usage: export [name=value]") } tmp := strings.Split(args[1], "=") if len(tmp) != 2 { - return errors.New("usage: export [name=value]") + return 1, errors.New("usage: export [name=value]") } - return os.Setenv(tmp[0], tmp[1]) + if err := os.Setenv(tmp[0], tmp[1]); err != nil { + return 2, err + } + return 0, nil } -- cgit v1.2.3