Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os module: Get current user/group #312

Open
dnbsd opened this issue Jan 24, 2025 · 0 comments
Open

os module: Get current user/group #312

dnbsd opened this issue Jan 24, 2025 · 0 comments

Comments

@dnbsd
Copy link

dnbsd commented Jan 24, 2025

In my scripts I would like to be able to obtain current user's name and group. Go's stdlib has a package os/user which provides the necessary functionality and Risor module could be based on. I am proposing to add the following new functions to the os module:

  • current_user() user
  • lookup_user(name) user
  • lookup_uid(uid) user
  • lookup_group(name) group
  • lookup_gid(gid) group

With this change, I would also like to extend the OS interface so that their implementation can be changed by a custom OS implementation, similarly how it's already done for other functions in Risor's os module:

type User interface {
    func Uid() string
    func Gid() string
    func Username() string
    func Name() string
    func HomeDir() string
}

type Group interface {
    func Gid() string
    func Name() string
}

type OS interface {
    // ...
    func CurrentUser() User
    func LookupUser(name string) User
    func LookupUid(uid string) User
    func LookupGroup(name string) Group
    func LookupGid(gid string) Group
}

If this is agreeable, @myzie, I would like to take a shot at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant